Made it possible to enter categories from YAML as an array.

This commit is contained in:
Bjørn Arild Mæland 2009-02-22 19:09:16 +01:00
parent 2569e9fb5e
commit 0ec9a1330a
3 changed files with 27 additions and 5 deletions

View File

@ -49,7 +49,13 @@ module Jekyll
if self.data.has_key?('category') if self.data.has_key?('category')
self.categories << self.data['category'] self.categories << self.data['category']
elsif self.data.has_key?('categories') elsif self.data.has_key?('categories')
# Look for categories in the YAML-header, either specified as
# an array or a string.
if self.data['categories'].kind_of? String
self.categories = self.data['categories'].split self.categories = self.data['categories'].split
else
self.categories = self.data['categories']
end
end end
end end
end end

View File

@ -0,0 +1,10 @@
---
layout: default
title: Array categories in YAML
categories:
- foo
- bar
- baz
---
Best *post* ever

View File

@ -87,11 +87,17 @@ class TestPost < Test::Unit::TestCase
end end
def test_yaml_categories def test_yaml_categories
p = Post.new(File.join(File.dirname(__FILE__), *%w[source]), '', "2009-01-27-categories.textile") p1 = Post.new(File.join(File.dirname(__FILE__), *%w[source]), '',
"2009-01-27-categories.textile")
p2 = Post.new(File.join(File.dirname(__FILE__), *%w[source]), '',
"2009-01-27-array-categories.textile")
[p1, p2].each do |p|
assert p.categories.include?('foo') assert p.categories.include?('foo')
assert p.categories.include?('bar') assert p.categories.include?('bar')
assert p.categories.include?('baz') assert p.categories.include?('baz')
end end
end
def test_render def test_render
p = Post.new(File.join(File.dirname(__FILE__), *%w[source]), '', "2008-10-18-foo-bar.textile") p = Post.new(File.join(File.dirname(__FILE__), *%w[source]), '', "2008-10-18-foo-bar.textile")