From 829530be36b04a4870f42c6634f3c319460eadb6 Mon Sep 17 00:00:00 2001 From: Nick Quaranto Date: Wed, 1 Apr 2009 07:36:56 -0400 Subject: [PATCH] Adding the categories back into the post payload --- features/embed_filters.feature | 6 +++--- features/post_data.feature | 26 +++++++++++------------ features/step_definitions/jekyll_steps.rb | 18 ++++++++-------- lib/jekyll/post.rb | 1 + 4 files changed, 26 insertions(+), 25 deletions(-) diff --git a/features/embed_filters.feature b/features/embed_filters.feature index 61bd8da0..f71dfb8f 100644 --- a/features/embed_filters.feature +++ b/features/embed_filters.feature @@ -20,7 +20,7 @@ Feature: Embed filters And I have the following post: | 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 }}" + And I have a default layout that contains "{{ site.posts.first.title | xml_escape }}" When I run jekyll Then the _site directory should exist And I should see "Star & Wars" in "_site/2009/03/27/star-wars.html" @@ -31,7 +31,7 @@ Feature: Embed filters And I have the following post: | 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 }}" + And I have a default layout that contains "{{ site.posts.first.content | xml_escape }}" When I run jekyll Then the _site directory should exist And I should see "7" in "_site/2009/03/27/star-wars.html" @@ -42,7 +42,7 @@ Feature: Embed filters And I have the following post: | 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 }}" + And I have a default layout that contains "{{ site.posts.first.tags | array_to_sentence_string }}" When I run jekyll Then the _site directory should exist And I should see "scifi, movies, and force" in "_site/2009/03/27/star-wars.html" diff --git a/features/post_data.feature b/features/post_data.feature index f50b53b7..45c29560 100644 --- a/features/post_data.feature +++ b/features/post_data.feature @@ -9,7 +9,7 @@ Feature: Post data And I have the following post: | title | date | layout | content | | Star Wars | 3/27/2009 | simple | Luke, I am your father. | - And I have a simple layout that contains "Post title: {{ post.title }}" + And I have a simple layout that contains "Post title: {{ site.posts.first.title }}" When I run jekyll Then the _site directory should exist And I should see "Post title: Star Wars" in "_site/2009/03/27/star-wars.html" @@ -20,7 +20,7 @@ Feature: Post data And I have the following post: | title | date | layout | content | | Star Wars | 3/27/2009 | simple | Luke, I am your father. | - And I have a simple layout that contains "Post url: {{ post.url }}" + And I have a simple layout that contains "Post url: {{ site.posts.first.url }}" When I run jekyll Then the _site directory should exist And I should see "Post url: /2009/03/27/star-wars.html" in "_site/2009/03/27/star-wars.html" @@ -31,10 +31,10 @@ Feature: Post data And I have the following post: | title | date | layout | content | | Star Wars | 3/27/2009 | simple | Luke, I am your father. | - And I have a simple layout that contains "Post date: {{ post.date }}" + And I have a simple layout that contains "Post date: {{ site.posts.first.date }}" When I run jekyll Then the _site directory should exist - And I should see "Post url: 2009-03-27" in "_site/2009/03/27/star-wars.html" + And I should see "Post date: Fri Mar 27" in "_site/2009/03/27/star-wars.html" Scenario: Use post.id variable Given I have a _posts directory @@ -42,7 +42,7 @@ Feature: Post data And I have the following post: | title | date | layout | content | | Star Wars | 3/27/2009 | simple | Luke, I am your father. | - And I have a simple layout that contains "Post id: {{ post.id }}" + And I have a simple layout that contains "Post id: {{ site.posts.first.id }}" When I run jekyll Then the _site directory should exist And I should see "Post id: /2009/03/27/star-wars" in "_site/2009/03/27/star-wars.html" @@ -53,10 +53,10 @@ Feature: Post data And I have the following post: | title | date | layout | content | | Star Wars | 3/27/2009 | simple | Luke, I am your father. | - And I have a simple layout that contains "Post content: {{ post.content }}" + And I have a simple layout that contains "Post content: {{ site.posts.first.content }}" When I run jekyll Then the _site directory should exist - And I should see "Post content: Luke, I am your father." in "_site/2009/03/27/star-wars.html" + 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 movies directory @@ -65,7 +65,7 @@ Feature: Post data And I have the following post in "movies": | title | date | layout | content | | Star Wars | 3/27/2009 | simple | Luke, I am your father. | - And I have a simple layout that contains "Post category: {{ post.categories }}" + 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 category: movies" in "_site/movies/2009/03/27/star-wars.html" @@ -78,7 +78,7 @@ 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: {{ post.categories }}" + And I have a simple layout that contains "Post categories: {{ site.posts.first.categories }}" 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" @@ -89,7 +89,7 @@ Feature: Post data And I have the following post: | title | date | layout | category | content | | Star Wars | 3/27/2009 | simple | movies | Luke, I am your father. | - And I have a simple layout that contains "Post category: {{ post.categories }}" + 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" @@ -100,7 +100,7 @@ Feature: Post data 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: {{ post.categories }}" + And I have a simple layout that contains "Post categories: {{ site.posts.first.categories }}" 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" @@ -112,7 +112,7 @@ Feature: Post data And I have the following post: | 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: {{ post.topics }}" + And I have a simple layout that contains "Post topics: {{ site.posts.first.topics }}" 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" @@ -131,7 +131,7 @@ Feature: Post data And I have the following post: | title | date | layout | author | content | | Star Wars | 3/27/2009 | simple | Darth Vader | Luke, I am your father. | - And I have a simple layout that contains "Post author: {{ post.author }}" + And I have a simple layout that contains "Post author: {{ site.posts.first.author }}" When I run jekyll Then the _site directory should exist And I should see "Post author: Darth Vader" in "_site/2009/03/27/star-wars.html" diff --git a/features/step_definitions/jekyll_steps.rb b/features/step_definitions/jekyll_steps.rb index f30426fc..61d09e91 100644 --- a/features/step_definitions/jekyll_steps.rb +++ b/features/step_definitions/jekyll_steps.rb @@ -42,19 +42,19 @@ 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') - title = post['title'].downcase.gsub(/[^\w]/, " ").strip.gsub(/\s+/, '-') - path = File.join("_posts", "#{date}-#{title}.#{post['type'] || 'textile'}") + title = post['title'].downcase.gsub(/[^\w]/, " ").strip.gsub(/\s+/, '-') + path = File.join(dir || '', '_posts', "#{date}-#{title}.#{post['type'] || 'textile'}") matter_hash = {} - %w(title layout tags).each do |key| - matter_hash[key] = post[key] if post[key] - end + %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 + content = post['content'] + if post['input'] && post['filter'] + content = "{{ #{post['input']} | #{post['filter']} }}" + end File.open(path, 'w') do |f| f.write < self.date, "id" => self.id, "topics" => self.topics, + "categories" => self.categories, "content" => self.content }.deep_merge(self.data) end