Skip to content

Commit

Permalink
Strip beginning of template strings now that front matter regexp isn't
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredcwhite committed May 4, 2024
1 parent 9b89961 commit a829c1b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
2 changes: 1 addition & 1 deletion bridgetown-routes/lib/bridgetown-routes/code_blocks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions bridgetown-routes/test/test_routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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<h1>Dynamic Index</h1>", last_response.body
assert_equal "<h1>Dynamic Index</h1>", last_response.body
FileUtils.remove_file(index_file.sub("test_index.erb", "index.erb"))
end

Expand All @@ -38,32 +38,32 @@ def site

should "return HTML for the howdy route" do
get "/howdy?yo=joe&happy=pleased"
assert_equal "\n<h1>joe 42</h1>\n\n<p>I am pleasedpleased.</p>\n", last_response.body
assert_equal "<h1>joe 42</h1>\n\n<p>I am pleasedpleased.</p>\n", last_response.body
end

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

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

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

should "return HTML for nested index RESTful route" do
get "/nested"
assert_equal "\n<h1>Nested Index</h1>\n", last_response.body
assert_equal "<h1>Nested Index</h1>\n", last_response.body
end

should "return HTML for nested item RESTful route" do
get "/nested/123-abc"
assert_equal "\n<h1>Nested Page with Slug: 123-abc</h1>\n", last_response.body
assert_equal "<h1>Nested Page with Slug: 123-abc</h1>\n", last_response.body
end

should "return JSON for a base route (no template)" do
Expand Down

0 comments on commit a829c1b

Please sign in to comment.