From a829c1b46458821e2f1af3965605dc0906beef53 Mon Sep 17 00:00:00 2001 From: Jared White Date: Sat, 4 May 2024 07:58:48 -0700 Subject: [PATCH] Strip beginning of template strings now that front matter regexp isn't --- .../bridgetown-core/front_matter/loaders/ruby.rb | 2 +- .../bridgetown-core/front_matter/loaders/yaml.rb | 2 +- .../lib/bridgetown-routes/code_blocks.rb | 2 +- bridgetown-routes/test/test_routes.rb | 14 +++++++------- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/bridgetown-core/lib/bridgetown-core/front_matter/loaders/ruby.rb b/bridgetown-core/lib/bridgetown-core/front_matter/loaders/ruby.rb index 3ab6993be..7b1da87c5 100644 --- a/bridgetown-core/lib/bridgetown-core/front_matter/loaders/ruby.rb +++ b/bridgetown-core/lib/bridgetown-core/front_matter/loaders/ruby.rb @@ -77,7 +77,7 @@ def self.header?(file) def read(file_contents, file_path:) if (ruby_content = file_contents.match(BLOCK)) && should_execute_inline_ruby? Result.new( - content: ruby_content.post_match, + content: ruby_content.post_match.lstrip, front_matter: process_ruby_data(ruby_content[1], file_path, 2), line_count: ruby_content[1].lines.size - 1 ) diff --git a/bridgetown-core/lib/bridgetown-core/front_matter/loaders/yaml.rb b/bridgetown-core/lib/bridgetown-core/front_matter/loaders/yaml.rb index 26dc6bcf3..c915c0798 100644 --- a/bridgetown-core/lib/bridgetown-core/front_matter/loaders/yaml.rb +++ b/bridgetown-core/lib/bridgetown-core/front_matter/loaders/yaml.rb @@ -31,7 +31,7 @@ def read(file_contents, **) yaml_content = file_contents.match(BLOCK) or return Result.new( - content: yaml_content.post_match, + content: yaml_content.post_match.lstrip, front_matter: YAMLParser.load(yaml_content[1]), line_count: yaml_content[1].lines.size - 1 ) diff --git a/bridgetown-routes/lib/bridgetown-routes/code_blocks.rb b/bridgetown-routes/lib/bridgetown-routes/code_blocks.rb index 2e4e4a70b..b12172462 100644 --- a/bridgetown-routes/lib/bridgetown-routes/code_blocks.rb +++ b/bridgetown-routes/lib/bridgetown-routes/code_blocks.rb @@ -37,7 +37,7 @@ def eval_route_file(file, file_slug, app) # rubocop:disable Lint/UnusedMethodArg front_matter_line_count = nil if ruby_content code = ruby_content[1] - code_postmatch = ruby_content.post_match + code_postmatch = ruby_content.post_match.lstrip front_matter_line_count = code.lines.count - 1 code.concat("\nrender_with {}") unless code.match?(%r!^\s*render_with\s|\(!) end diff --git a/bridgetown-routes/test/test_routes.rb b/bridgetown-routes/test/test_routes.rb index 58ee7f207..cfaee70c3 100644 --- a/bridgetown-routes/test/test_routes.rb +++ b/bridgetown-routes/test/test_routes.rb @@ -26,7 +26,7 @@ def site FileUtils.cp(index_file, index_file.sub("test_index.erb", "index.erb")) get "/" assert last_response.ok? - assert_equal "\n

Dynamic Index

", last_response.body + assert_equal "

Dynamic Index

", last_response.body FileUtils.remove_file(index_file.sub("test_index.erb", "index.erb")) end @@ -38,32 +38,32 @@ def site should "return HTML for the howdy route" do get "/howdy?yo=joe&happy=pleased" - assert_equal "\n

joe 42

\n\n

I am pleasedpleased.

\n", last_response.body + assert_equal "

joe 42

\n\n

I am pleasedpleased.

\n", last_response.body end should "return HTML for a route in an arbitrary folder" do get "/yello/my-friend" - assert_equal "\n

So arbitrary!

\n", last_response.body + assert_equal "

So arbitrary!

\n", last_response.body end should "return HTML for a route localized in english" do get "/localized" - assert_equal "\n

Localized for en - en

\n", last_response.body + assert_equal "

Localized for en - en

\n", last_response.body end should "return HTML for a route localized in italian" do get "/it/localized" - assert_equal "\n

Localized for it - it

\n", last_response.body + assert_equal "

Localized for it - it

\n", last_response.body end should "return HTML for nested index RESTful route" do get "/nested" - assert_equal "\n

Nested Index

\n", last_response.body + assert_equal "

Nested Index

\n", last_response.body end should "return HTML for nested item RESTful route" do get "/nested/123-abc" - assert_equal "\n

Nested Page with Slug: 123-abc

\n", last_response.body + assert_equal "

Nested Page with Slug: 123-abc

\n", last_response.body end should "return JSON for a base route (no template)" do