separated up the attrs required by convertible and made tags and categories always non-nil as empty front matter entries could cause them to be nil
This commit is contained in:
parent
5c17d6266d
commit
7806a0d6bb
|
@ -3,6 +3,10 @@
|
|||
#
|
||||
# Requires
|
||||
# self.site -> Jekyll::Site
|
||||
# self.content=
|
||||
# self.data=
|
||||
# self.ext=
|
||||
# self.output=
|
||||
module Jekyll
|
||||
module Convertible
|
||||
# Return the contents as a string
|
||||
|
|
|
@ -18,12 +18,9 @@ module Jekyll
|
|||
name =~ MATCHER
|
||||
end
|
||||
|
||||
attr_accessor :site, :date, :slug, :ext, :published, :data, :content, :output, :tags
|
||||
attr_writer :categories
|
||||
|
||||
def categories
|
||||
@categories ||= []
|
||||
end
|
||||
attr_accessor :site
|
||||
attr_accessor :data, :content, :output, :ext
|
||||
attr_accessor :date, :slug, :published, :tags, :categories
|
||||
|
||||
# Initialize this Post instance.
|
||||
# +site+ is the Site
|
||||
|
@ -51,9 +48,8 @@ module Jekyll
|
|||
self.tags = [self.data["tag"]]
|
||||
elsif self.data.has_key?("tags")
|
||||
self.tags = self.data['tags']
|
||||
else
|
||||
self.tags = []
|
||||
end
|
||||
self.tags ||= []
|
||||
|
||||
if self.categories.empty?
|
||||
if self.data.has_key?('category')
|
||||
|
@ -68,6 +64,7 @@ module Jekyll
|
|||
end
|
||||
end
|
||||
end
|
||||
self.categories ||= []
|
||||
end
|
||||
|
||||
# Spaceship is based on Post#date, slug
|
||||
|
|
|
@ -36,6 +36,7 @@ class TestPost < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
should "keep date, title, and markup type" do
|
||||
@post.categories = []
|
||||
@post.process(@fake_file)
|
||||
|
||||
assert_equal Time.parse("2008-10-19"), @post.date
|
||||
|
@ -202,6 +203,13 @@ class TestPost < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
context "initializing posts" do
|
||||
|
||||
should "ensure suitable defaults for attributes" do
|
||||
post = setup_post("2009-06-22-no-yaml.textile")
|
||||
assert_equal [], post.tags
|
||||
assert_equal [], post.categories
|
||||
end
|
||||
|
||||
should "publish when published yaml is no specified" do
|
||||
post = setup_post("2008-02-02-published.textile")
|
||||
assert_equal true, post.published
|
||||
|
|
Loading…
Reference in New Issue