Added publish flag to posts, not preventing it from being in the destination directory yet.

This commit is contained in:
Nick Quaranto 2009-02-02 22:24:51 -05:00
parent 1211f23b53
commit ad617da4e0
5 changed files with 32 additions and 2 deletions

View File

@ -18,7 +18,7 @@ module Jekyll
name =~ MATCHER
end
attr_accessor :date, :slug, :ext, :categories, :topics
attr_accessor :date, :slug, :ext, :categories, :topics, :published
attr_accessor :data, :content, :output
# Initialize this Post instance.
@ -39,6 +39,12 @@ module Jekyll
self.process(name)
self.read_yaml(@base, name)
if self.data.has_key?('published') && self.data['published'] == false
self.published = false
else
self.published = true
end
if self.categories.empty?
if self.data.has_key?('category')
self.categories << self.data['category']

View File

@ -0,0 +1,7 @@
---
layout: default
title: Not published!
published: false
---
This should *not* be published!

View File

@ -0,0 +1,7 @@
---
layout: default
title: Publish
---
This should be published.

View File

@ -71,6 +71,16 @@ class TestPost < Test::Unit::TestCase
assert_equal "<h1>{{ page.title }}</h1>\n<p>Best <strong>post</strong> ever</p>", p.content
end
def test_published
p = Post.new(File.join(File.dirname(__FILE__), *%w[source publish_test]), '', "2008-02-02-publish.textile")
assert_equal true, p.published
end
def test_not_published
p = Post.new(File.join(File.dirname(__FILE__), *%w[source publish_test]), '', "2008-02-02-not-published.textile")
assert_equal false, p.published
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')

View File

@ -27,7 +27,7 @@ class TestSite < Test::Unit::TestCase
@s.process
posts = Dir[File.join(@source, "**", "_posts/*")]
categories = %w(bar baz category foo z_category).sort
categories = %w(bar baz category foo z_category publish_test).sort
assert_equal posts.size, @s.posts.size
assert_equal categories, @s.categories.keys.sort