Permalink
Browse files

Adding support for setting post categories through YAML if not specif…

…ied by directory structure
  • Loading branch information...
1 parent 4bcfaea commit 1211f23b53af69f5ce31bd1e7eec747294f12e78 @qrush qrush committed Jan 28, 2009
Showing with 42 additions and 12 deletions.
  1. +2 −0 .gitignore
  2. +8 −0 lib/jekyll/post.rb
  3. +2 −1 test/helper.rb
  4. +7 −3 test/test_generated_site.rb
  5. +13 −1 test/test_post.rb
  6. +10 −7 test/test_site.rb
View
@@ -1,3 +1,5 @@
test/dest/
*.gem
pkg/
+*.swp
+*~
View
@@ -38,6 +38,14 @@ def initialize(source, dir, name)
self.process(name)
self.read_yaml(@base, name)
+
+ if self.categories.empty?
+ if self.data.has_key?('category')
+ self.categories << self.data['category']
+ elsif self.data.has_key?('categories')
+ self.categories = self.data['categories'].split
+ end
+ end
end
# Spaceship is based on Post#date
View
@@ -1,6 +1,7 @@
require File.join(File.dirname(__FILE__), *%w[.. lib jekyll])
require 'test/unit'
+require 'redgreen'
include Jekyll
@@ -10,4 +11,4 @@ def dest_dir
def clear_dest
FileUtils.rm_rf(dest_dir)
-end
+end
@@ -3,8 +3,8 @@
class TestGeneratedSite < Test::Unit::TestCase
def setup
clear_dest
- source = File.join(File.dirname(__FILE__), *%w[source])
- @s = Site.new(source, dest_dir)
+ @source = File.join(File.dirname(__FILE__), *%w[source])
+ @s = Site.new(@source, dest_dir)
@s.process
@index = File.read(File.join(dest_dir, 'index.html'))
end
@@ -16,6 +16,10 @@ def test_site_posts_in_index
def test_post_content_in_index
# confirm that the {{ post.content }} is rendered OK
- assert @index.include?('<p>This <em>is</em> cool</p>')
+ latest_post = Dir[File.join(@source, '_posts/*')].last
+ post = Post.new(@source, '', File.basename(latest_post))
+ Jekyll.content_type = post.determine_content_type
+ post.transform
+ assert @index.include?(post.content)
end
end
View
@@ -70,6 +70,18 @@ def test_transform
assert_equal "<h1>{{ page.title }}</h1>\n<p>Best <strong>post</strong> ever</p>", p.content
end
+
+ def test_yaml_category
+ p = Post.new(File.join(File.dirname(__FILE__), *%w[source]), '', "2009-01-27-category.textile")
+ assert p.categories.include?('foo')
+ end
+
+ def test_yaml_categories
+ p = Post.new(File.join(File.dirname(__FILE__), *%w[source]), '', "2009-01-27-categories.textile")
+ assert p.categories.include?('foo')
+ assert p.categories.include?('bar')
+ assert p.categories.include?('baz')
+ end
def test_render
p = Post.new(File.join(File.dirname(__FILE__), *%w[source]), '', "2008-10-18-foo-bar.textile")
@@ -110,4 +122,4 @@ def test_include
assert_equal "<<< <hr />\n<p>Tom Preston-Werner github.com/mojombo</p>\n\n<p>This <em>is</em> cool</p> >>>", p.output
end
-end
+end
View
@@ -2,8 +2,8 @@
class TestSite < Test::Unit::TestCase
def setup
- source = File.join(File.dirname(__FILE__), *%w[source])
- @s = Site.new(source, dest_dir)
+ @source = File.join(File.dirname(__FILE__), *%w[source])
+ @s = Site.new(@source, dest_dir)
end
def test_site_init
@@ -18,16 +18,19 @@ def test_read_layouts
def test_read_posts
@s.read_posts('')
-
- assert_equal 4, @s.posts.size
+ posts = Dir[File.join(@source, '_posts/*')]
+ assert_equal posts.size, @s.posts.size
end
def test_site_payload
clear_dest
@s.process
- assert_equal 7, @s.posts.length
- assert_equal ["category", "foo", "z_category"].sort, @s.categories.keys.sort
- assert_equal 1, @s.categories['foo'].length
+ posts = Dir[File.join(@source, "**", "_posts/*")]
+ categories = %w(bar baz category foo z_category).sort
+
+ assert_equal posts.size, @s.posts.size
+ assert_equal categories, @s.categories.keys.sort
+ assert_equal 3, @s.categories['foo'].size
end
end

0 comments on commit 1211f23

Please sign in to comment.