Skip to content

Commit

Permalink
Following post step is getting confusing, but it works
Browse files Browse the repository at this point in the history
  • Loading branch information
qrush committed Apr 1, 2009
1 parent 829530b commit 03f511b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
21 changes: 11 additions & 10 deletions features/post_data.feature
Expand Up @@ -78,10 +78,10 @@ Feature: Post data
And I have the following post in "movies/scifi":
| title | date | layout | content |
| Star Wars | 3/27/2009 | simple | Luke, I am your father. |
And I have a simple layout that contains "Post categories: {{ site.posts.first.categories }}"
And I have a simple layout that contains "Post categories: {{ site.posts.first.categories | array_to_sentence_string }}"
When I run jekyll
Then the _site directory should exist
And I should see "Post categories: movies scifi" in "_site/movies/scifi/2009/03/27/star-wars.html"
And I should see "Post categories: movies and 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 _posts directory
Expand All @@ -92,30 +92,31 @@ Feature: Post data
And I have a simple layout that contains "Post category: {{ site.posts.first.categories }}"
When I run jekyll
Then the _site directory should exist
And I should see "Post categories: movies" in "_site/movies/2009/03/27/star-wars.html"
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 YAML
Given I have a _posts directory
And I have a _layouts directory
And I have the following post:
| title | date | layout | categories | content |
| Star Wars | 3/27/2009 | simple | movies, scifi | Luke, I am your father. |
And I have a simple layout that contains "Post categories: {{ site.posts.first.categories }}"
| title | date | layout | categories | content |
| Star Wars | 3/27/2009 | simple | ['movies', 'scifi'] | Luke, I am your father. |
And I have a simple layout that contains "Post categories: {{ site.posts.first.categories | array_to_sentence_string }}"
When I run jekyll
Then the _site directory should exist
And I should see "Post categories: movies scifi" in "_site/movies/scifi/2009/03/27/star-wars.html"
And I should see "Post categories: movies and scifi" in "_site/movies/scifi/2009/03/27/star-wars.html"

Scenario: Use post.topics variable
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:
And I have a _layouts directory
And I have the following post under "movies/scifi":
| title | date | layout | content |
| Star Wars | 3/27/2009 | simple | Luke, I am your father. |
And I have a simple layout that contains "Post topics: {{ site.posts.first.topics }}"
And I have a simple layout that contains "Post topics: {{ site.posts.first.topics | array_to_sentence_string }}"
When I run jekyll
Then the _site directory should exist
And I should see "Post topics: movies scifi" in "_site/2009/03/27/star-wars.html"
And I should see "Post topics: movies and scifi" in "_site/2009/03/27/star-wars.html"

Scenario: Disable a post from being published
Given I have a _posts directory
Expand Down
13 changes: 10 additions & 3 deletions features/step_definitions/jekyll_steps.rb
Expand Up @@ -39,14 +39,21 @@
FileUtils.mkdir(dir)
end

Given /^I have the following posts?(?: in "(.*)")?:$/ do |dir, table|
Given /^I have the following posts?(?: (.*) "(.*)")?:$/ do |direction, folder, table|
table.hashes.each do |post|
date = Date.parse(post['date']).strftime('%Y-%m-%d')
title = post['title'].downcase.gsub(/[^\w]/, " ").strip.gsub(/\s+/, '-')
path = File.join(dir || '', '_posts', "#{date}-#{title}.#{post['type'] || 'textile'}")

if direction && direction == "in"
before = folder || '.'
elsif direction && direction == "under"
after = folder || '.'
end

path = File.join(before || '.', '_posts', after || '.', "#{date}-#{title}.#{post['type'] || 'textile'}")

matter_hash = {}
%w(title layout tags).each do |key|
%w(title layout tags category categories).each do |key|
matter_hash[key] = post[key] if post[key]
end
matter = matter_hash.map { |k, v| "#{k}: #{v}\n" }.join.chomp
Expand Down

0 comments on commit 03f511b

Please sign in to comment.