diff --git a/features/embed_filters.feature b/features/embed_filters.feature index b5eca2df..61bd8da0 100644 --- a/features/embed_filters.feature +++ b/features/embed_filters.feature @@ -4,52 +4,57 @@ Feature: Embed filters In order to perform cool stuff in my posts Scenario: Convert date to XML schema - Given I have a blank site - And I have a _posts directory + Given I have a _posts directory + And I have a _layouts directory And I have the following post: - | title | date | input | filter | - | Date to XML schema | 3/27/2009 | post.date | date_to_xmlschema | + | title | date | layout | content | + | Star Wars | 3/27/2009 | default | These aren't the droids you're looking for. | + And I have a default layout that contains "{{ site.time | date_to_xmlschema }}" When I run jekyll Then the _site directory should exist - And I should see "2009-03-27T00:00:00-08:00" in "_site/2009/03/27/date-to-xml-schema.html" + And I should see today's date in "_site/2009/03/27/star-wars.html" Scenario: Escape text for XML - Given I have a blank site - And I have a _posts directory + Given I have a _posts directory + And I have a _layouts directory And I have the following post: - | title | date | input | filter | - | Escape text for XML | 3/27/2009 | 'Mario & Luigi' | xml_escape | + | title | date | layout | content | + | Star & Wars | 3/27/2009 | default | These aren't the droids you're looking for. | + And I have a default layout that contains "{{ page.title | xml_escape }}" When I run jekyll Then the _site directory should exist - And I should see "<tt>Mario & Luigi<tt>" in "_site/2009/03/27/escape-text-for-xml.html" + And I should see "Star & Wars" in "_site/2009/03/27/star-wars.html" Scenario: Calculate number of words - Given I have a blank site - And I have a _posts directory + Given I have a _posts directory + And I have a _layouts directory And I have the following post: - | title | date | input | filter | - | Calculate number of words | 3/27/2009 | post.title | number_of_words | + | title | date | layout | content | + | Star Wars | 3/27/2009 | default | These aren't the droids you're looking for. | + And I have a default layout that contains "{{ content | xml_escape }}" When I run jekyll Then the _site directory should exist - And I should see "4" in "_site/2009/03/27/calculate-number-of-words.html" + And I should see "7" in "_site/2009/03/27/star-wars.html" Scenario: Convert an array into a sentence - Given I have a blank site - And I have a _posts directory + Given I have a _posts directory + And I have a _layouts directory And I have the following post: - | title | date | tags | input | filter | - | Convert array to sentence | 3/27/2009 | life hacks code | post.tags | array_to_sentence_string | + | title | date | layout | tags | content | + | Star Wars | 3/27/2009 | default | [scifi, movies, force] | These aren't the droids you're looking for. | + And I have a default layout that contains "{{ page.tags | array_to_sentence_string }}" When I run jekyll Then the _site directory should exist - And I should see "life, hacks, and code" in "_site/2009/03/27/convert-array-to-sentence.html" + And I should see "scifi, movies, and force" in "_site/2009/03/27/star-wars.html" Scenario: Textilize a given string - Given I have a blank site - And I have a _posts directory + Given I have a _posts directory + And I have a _layouts directory And I have the following post: - | title | date | tags | input | filter | - | Logical Awesome | 3/27/2009 | *Mr. Spock* | post.author | textilize | + | title | date | layout | content | + | Star Wars | 3/27/2009 | default | These aren't the droids you're looking for. | + And I have a default layout that contains "By {{ '_Obi-wan_' | textilize }}" When I run jekyll Then the _site directory should exist - And I should see "Mr. Spock" in "_site/2009/03/27/textilize.html" + And I should see "By

Obi-wan

" in "_site/2009/03/27/star-wars.html" diff --git a/features/post_data.feature b/features/post_data.feature index f7938f36..f50b53b7 100644 --- a/features/post_data.feature +++ b/features/post_data.feature @@ -4,8 +4,7 @@ Feature: Post data In order to make the posts slightly dynamic Scenario: Use post.title variable - Given I have a blank site - And I have a _posts directory + Given I have a _posts directory And I have a _layouts directory And I have the following post: | title | date | layout | content | @@ -16,8 +15,7 @@ Feature: Post data And I should see "Post title: Star Wars" in "_site/2009/03/27/star-wars.html" Scenario: Use post.url variable - Given I have a blank site - And I have a _posts directory + Given I have a _posts directory And I have a _layouts directory And I have the following post: | title | date | layout | content | @@ -28,8 +26,7 @@ Feature: Post data And I should see "Post url: /2009/03/27/star-wars.html" in "_site/2009/03/27/star-wars.html" Scenario: Use post.date variable - Given I have a blank site - And I have a _posts directory + Given I have a _posts directory And I have a _layouts directory And I have the following post: | title | date | layout | content | @@ -40,8 +37,7 @@ Feature: Post data And I should see "Post url: 2009-03-27" in "_site/2009/03/27/star-wars.html" Scenario: Use post.id variable - Given I have a blank site - And I have a _posts directory + Given I have a _posts directory And I have a _layouts directory And I have the following post: | title | date | layout | content | @@ -52,8 +48,7 @@ Feature: Post data And I should see "Post id: /2009/03/27/star-wars" in "_site/2009/03/27/star-wars.html" Scenario: Use post.content variable - Given I have a blank site - And I have a _posts directory + Given I have a _posts directory And I have a _layouts directory And I have the following post: | title | date | layout | content | @@ -64,8 +59,7 @@ Feature: Post data And I should see "Post content: Luke, I am your father." in "_site/2009/03/27/star-wars.html" Scenario: Use post.categories variable when category is in a folder - Given I have a blank site - And I have a movies directory + Given I have a movies directory And I have a movies/_posts directory And I have a _layouts directory And I have the following post in "movies": @@ -77,8 +71,7 @@ Feature: Post data And I should see "Post category: movies" in "_site/movies/2009/03/27/star-wars.html" Scenario: Use post.categories variable when categories are in folders - Given I have a blank site - And I have a movies directory + Given I have a movies directory And I have a movies/scifi directory And I have a movies/scifi/_posts directory And I have a _layouts directory @@ -91,8 +84,7 @@ Feature: Post data And I should see "Post categories: movies scifi" in "_site/movies/scifi/2009/03/27/star-wars.html" Scenario: Use post.categories variable when category is in YAML - Given I have a blank site - And I have a _posts directory + Given I have a _posts directory And I have a _layouts directory And I have the following post: | title | date | layout | category | content | @@ -103,8 +95,7 @@ Feature: Post data And I should see "Post categories: movies" in "_site/movies/2009/03/27/star-wars.html" Scenario: Use post.categories variable when categories are in YAML - Given I have a blank site - And I have a _posts directory + Given I have a _posts directory And I have a _layouts directory And I have the following post: | title | date | layout | categories | content | @@ -115,8 +106,7 @@ Feature: Post data And I should see "Post categories: movies scifi" in "_site/movies/scifi/2009/03/27/star-wars.html" Scenario: Use post.topics variable - Given I have a blank site - And I have a _posts directory + Given I have a _posts directory And I have a _posts/movies directory And I have a _posts/movies/scifi directory And I have the following post: @@ -128,8 +118,7 @@ Feature: Post data And I should see "Post topics: movies scifi" in "_site/2009/03/27/star-wars.html" Scenario: Disable a post from being published - Given I have a blank site - And I have a _posts directory + Given I have a _posts directory And I have the following post: | title | date | layout | published | content | | Star Wars | 3/27/2009 | simple | false | Luke, I am your father. | @@ -138,8 +127,7 @@ Feature: Post data And the "_site/2009/03/27/star-wars.html" file should not exist Scenario: Use a custom variable - Given I have a blank site - And I have a _posts directory + Given I have a _posts directory And I have the following post: | title | date | layout | author | content | | Star Wars | 3/27/2009 | simple | Darth Vader | Luke, I am your father. | diff --git a/features/step_definitions/jekyll_steps.rb b/features/step_definitions/jekyll_steps.rb index f2ece816..f30426fc 100644 --- a/features/step_definitions/jekyll_steps.rb +++ b/features/step_definitions/jekyll_steps.rb @@ -42,18 +42,26 @@ end Given /^I have the following posts?(?: in "(.*)")?:$/ do |dir, table| table.hashes.each do |post| date = Date.parse(post['date']).strftime('%Y-%m-%d') - path = File.join("_posts", "#{date}-#{post['title'].downcase}.textile") + title = post['title'].downcase.gsub(/[^\w]/, " ").strip.gsub(/\s+/, '-') + path = File.join("_posts", "#{date}-#{title}.#{post['type'] || 'textile'}") - matter_hash = {'title' => post['title']} - matter_hash['layout'] = post['layout'] if post['layout'] - matter = matter_hash.map { |k, v| "#{k}: #{v}\n" } + matter_hash = {} + %w(title layout tags).each do |key| + matter_hash[key] = post[key] if post[key] + end + matter = matter_hash.map { |k, v| "#{k}: #{v}\n" }.join.chomp + + content = post['content'] + if post['input'] && post['filter'] + content = "{{ #{post['input']} | #{post['filter']} }}" + end File.open(path, 'w') do |f| f.write <> /dev/null" end When /^I change "(.*)" to contain "(.*)"$/ do |file, text| @@ -88,3 +96,7 @@ Then /^the "(.*)" file should not exist$/ do |file| pending end +Then /^I should see today's date in "(.*)"$/ do |file| + assert_match Regexp.new(Date.today.to_s), File.open(file).readlines.join +end +