Skip to content

Commit

Permalink
Filter feature passing, definitely room for refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
qrush committed Apr 1, 2009
1 parent 0d78cb7 commit aff6c9c
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 55 deletions.
55 changes: 30 additions & 25 deletions features/embed_filters.feature
Expand Up @@ -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 | '<tt>Mario & Luigi</tt>' | 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 "&lt;tt&gt;Mario &amp; Luigi&lt;tt&gt;" in "_site/2009/03/27/escape-text-for-xml.html"
And I should see "Star &amp; 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 "<b>Mr. Spock</b>" in "_site/2009/03/27/textilize.html"
And I should see "By <p><em>Obi-wan</em></p>" in "_site/2009/03/27/star-wars.html"

36 changes: 12 additions & 24 deletions features/post_data.feature
Expand Up @@ -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 |
Expand All @@ -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 |
Expand All @@ -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 |
Expand All @@ -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 |
Expand All @@ -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 |
Expand All @@ -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":
Expand All @@ -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
Expand All @@ -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 |
Expand All @@ -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 |
Expand All @@ -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:
Expand All @@ -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. |
Expand All @@ -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. |
Expand Down
24 changes: 18 additions & 6 deletions features/step_definitions/jekyll_steps.rb
Expand Up @@ -42,18 +42,26 @@
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 <<EOF
---
#{matter}
---
#{post['content']}
#{content}
EOF
f.close
end
Expand All @@ -65,7 +73,7 @@
end

When /^I run jekyll$/ do
`#{File.join(ENV['PWD'], 'bin', 'jekyll')}`
system File.join(ENV['PWD'], 'bin', 'jekyll') + " >> /dev/null"
end

When /^I change "(.*)" to contain "(.*)"$/ do |file, text|
Expand All @@ -88,3 +96,7 @@
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

0 comments on commit aff6c9c

Please sign in to comment.