Skip to content

Commit

Permalink
Added publish flag to posts, not preventing it from being in the dest…
Browse files Browse the repository at this point in the history
…ination directory yet.
  • Loading branch information
qrush committed Feb 10, 2009
1 parent 1211f23 commit ad617da
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/jekyll/post.rb
Expand Up @@ -18,7 +18,7 @@ def self.valid?(name)
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.
Expand All @@ -38,6 +38,12 @@ def initialize(source, dir, name)

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')
Expand Down
@@ -0,0 +1,7 @@
---
layout: default
title: Not published!
published: false
---

This should *not* be published!
7 changes: 7 additions & 0 deletions test/source/publish_test/_posts/2008-02-02-publish.textile
@@ -0,0 +1,7 @@
---
layout: default
title: Publish
---

This should be published.

10 changes: 10 additions & 0 deletions test/test_post.rb
Expand Up @@ -71,6 +71,16 @@ def test_transform
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')
Expand Down
2 changes: 1 addition & 1 deletion test/test_site.rb
Expand Up @@ -27,7 +27,7 @@ def test_site_payload
@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
Expand Down

0 comments on commit ad617da

Please sign in to comment.