diff --git a/features/rendering.feature b/features/rendering.feature new file mode 100644 index 00000000..5f71e2cd --- /dev/null +++ b/features/rendering.feature @@ -0,0 +1,34 @@ +Feature: Rendering + As a hacker who likes to blog + I want to be able to make a static site + In order to share my awesome ideas with the interwebs + But I want to make it as simply as possible + So render with Liquid and place in Layouts + + Scenario: Render Liquid and place in layout + Given I have a "index.html" page with layout "simple" that contains "Hi there, Jekyll {{ jekyll.environment }}!" + And I have a simple layout that contains "{{ content }}Ahoy, indeed!" + When I run jekyll build + Then the _site directory should exist + And I should see "Hi there, Jekyll development!\nAhoy, indeed" in "_site/index.html" + + Scenario: Don't place asset files in layout + Given I have an "index.scss" page with layout "simple" that contains ".foo-bar { color:black; }" + And I have an "index.coffee" page with layout "simple" that contains "whatever()" + And I have a simple layout that contains "{{ content }}Ahoy, indeed!" + When I run jekyll build + Then the _site directory should exist + And I should not see "Ahoy, indeed!" in "_site/index.css" + And I should not see "Ahoy, indeed!" in "_site/index.js" + + Scenario: Don't render liquid in Sass + Given I have an "index.scss" page that contains ".foo-bar { color:{{site.color}}; }" + When I run jekyll build + Then the _site directory should not exist + And I should see "Invalid CSS after" in the build output + + Scenario: Don't render liquid in CoffeeScript + Given I have an "index.coffee" page that contains "hey='for {{site.animal}}'" + When I run jekyll build + Then the _site directory should exist + And I should see "hey = 'for {{site.animal}}';" in "_site/index.js" diff --git a/features/step_definitions/jekyll_steps.rb b/features/step_definitions/jekyll_steps.rb index 4fe7edd2..1a4ec029 100644 --- a/features/step_definitions/jekyll_steps.rb +++ b/features/step_definitions/jekyll_steps.rb @@ -141,7 +141,7 @@ end When /^I run jekyll(.*)$/ do |args| status = run_jekyll(args) - if !status || args.include?("--verbose") + if args.include?("--verbose") puts jekyll_run_output end end @@ -195,3 +195,7 @@ end Then /^I should see today's date in "(.*)"$/ do |file| assert_match Regexp.new(Date.today.to_s), file_contents(file) end + +Then /^I should see "(.*)" in the build output$/ do |text| + assert_match Regexp.new(text), jekyll_run_output +end diff --git a/lib/jekyll/convertible.rb b/lib/jekyll/convertible.rb index 9d00d703..b423ac43 100644 --- a/lib/jekyll/convertible.rb +++ b/lib/jekyll/convertible.rb @@ -114,6 +114,10 @@ module Jekyll Utils.deep_merge_hashes defaults, Utils.deep_merge_hashes(data, further_data) end + # The type of a document, + # i.e., its classname downcase'd and to_sym'd. + # + # Returns the type of self. def type if is_a?(Post) :post @@ -124,6 +128,31 @@ module Jekyll end end + # Determine whether the document is an asset file. + # Asset files include CoffeeScript files and Sass/SCSS files. + # + # Returns true if the extname belongs to the set of extensions + # that asset files use. + def asset_file? + %w[.sass .scss .coffee].include?(ext) + end + + # Determine whether the file should be rendered with Liquid. + # + # Returns false if the document is either an asset file or a yaml file, + # true otherwise. + def render_with_liquid? + !asset_file? + end + + # Determine whether the file should be placed into layouts. + # + # Returns false if the document is either an asset file or a yaml file, + # true otherwise. + def place_in_layout? + !asset_file? + end + # Recursively render layouts # # layouts - a list of the layouts @@ -167,13 +196,13 @@ module Jekyll payload["highlighter_prefix"] = converter.highlighter_prefix payload["highlighter_suffix"] = converter.highlighter_suffix - self.content = render_liquid(content, payload, info) + self.content = render_liquid(content, payload, info) if render_with_liquid? transform # output keeps track of what will finally be written self.output = content - render_all_layouts(layouts, payload, info) + render_all_layouts(layouts, payload, info) if place_in_layout? end # Write the generated page file to the destination directory. diff --git a/lib/jekyll/document.rb b/lib/jekyll/document.rb index 50aeaa14..0fb6719f 100644 --- a/lib/jekyll/document.rb +++ b/lib/jekyll/document.rb @@ -88,6 +88,14 @@ module Jekyll !(asset_file? || yaml_file?) end + # Determine whether the file should be placed into layouts. + # + # Returns false if the document is either an asset file or a yaml file, + # true otherwise. + def place_in_layout? + !(asset_file? || yaml_file?) + end + # The URL template where the document would be accessible. # # Returns the URL template for the document. diff --git a/lib/jekyll/renderer.rb b/lib/jekyll/renderer.rb index e3d233df..f918cc0d 100644 --- a/lib/jekyll/renderer.rb +++ b/lib/jekyll/renderer.rb @@ -47,11 +47,15 @@ module Jekyll output = render_liquid(output, payload, info) end - place_in_layouts( - convert(output), - payload, - info - ) + if document.place_in_layout? + place_in_layouts( + convert(output), + payload, + info + ) + else + convert(output) + end end # Convert the given content using the converters which match this renderer's document.