Merge commit '60709da7067fbe1d106fbdfadb3a84b35d07d721' into qrush
This commit is contained in:
		
						commit
						0168581a82
					
				|  | @ -1,3 +1,5 @@ | |||
| test/dest/ | ||||
| *.gem | ||||
| pkg/ | ||||
| *.swp | ||||
| *~ | ||||
|  |  | |||
|  | @ -255,6 +255,15 @@ h3. Predefined Post Variables | |||
|     /year/month/day/title.html then you can set this variable and it will | ||||
|     be used as the final URL. | ||||
| 
 | ||||
|   published | ||||
|     Set to false if you don't want a post to show up when the site is  | ||||
|     generated. | ||||
| 
 | ||||
|   category/categories | ||||
|     Instead of placing posts inside of folders, you can specify one or more | ||||
|     categories that the post belongs to. When the site is generated the post | ||||
|     will act as though it had been set with these categories normally. | ||||
| 
 | ||||
| h3. Custom Variables | ||||
| 
 | ||||
| Any variables in the front matter that are not predefined are mixed into the | ||||
|  | @ -372,7 +381,7 @@ within a Liquid template as follows: | |||
| 
 | ||||
| <pre> | ||||
| {% for post in site.categories.foo %} | ||||
| 	<li><span>{{ post.date | date_to_string }}</span> - {{ post.title }}</li> | ||||
|   <li><span>{{ post.date | date_to_string }}</span> - {{ post.title }}</li> | ||||
| {% endfor %} | ||||
| </pre> | ||||
| 
 | ||||
|  |  | |||
|  | @ -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. | ||||
|  | @ -38,6 +38,20 @@ 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'] | ||||
|         elsif self.data.has_key?('categories') | ||||
|           self.categories = self.data['categories'].split | ||||
|         end | ||||
|       end | ||||
|     end | ||||
|      | ||||
|     # Spaceship is based on Post#date | ||||
|  |  | |||
|  | @ -63,8 +63,11 @@ module Jekyll | |||
|       entries.each do |f| | ||||
|         if Post.valid?(f) | ||||
|           post = Post.new(self.source, dir, f) | ||||
|           self.posts << post | ||||
|           post.categories.each { |c| self.categories[c] << post } | ||||
| 
 | ||||
|           if post.published | ||||
|             self.posts << post | ||||
|             post.categories.each { |c| self.categories[c] << post } | ||||
|           end | ||||
|         end | ||||
|       end | ||||
|        | ||||
|  |  | |||
|  | @ -1,6 +1,7 @@ | |||
| require File.join(File.dirname(__FILE__), *%w[.. lib jekyll]) | ||||
| 
 | ||||
| require 'test/unit' | ||||
| require 'redgreen' | ||||
| 
 | ||||
| include Jekyll | ||||
| 
 | ||||
|  | @ -10,4 +11,4 @@ end | |||
| 
 | ||||
| def clear_dest | ||||
|   FileUtils.rm_rf(dest_dir) | ||||
| end | ||||
| end | ||||
|  |  | |||
|  | @ -0,0 +1,8 @@ | |||
| --- | ||||
| layout: default | ||||
| title: Not published! | ||||
| published: false | ||||
| category: publish_test | ||||
| --- | ||||
| 
 | ||||
| This should *not* be published! | ||||
|  | @ -0,0 +1,8 @@ | |||
| --- | ||||
| layout: default | ||||
| title: Publish | ||||
| category: publish_test | ||||
| --- | ||||
| 
 | ||||
| This should be published. | ||||
| 
 | ||||
|  | @ -0,0 +1,7 @@ | |||
| --- | ||||
| layout: default | ||||
| title: Categories in YAML | ||||
| categories: foo bar baz | ||||
| --- | ||||
| 
 | ||||
| Best *post* ever | ||||
|  | @ -0,0 +1,7 @@ | |||
| --- | ||||
| layout: default | ||||
| title: Category in YAML | ||||
| category: foo | ||||
| --- | ||||
| 
 | ||||
| Best *post* ever | ||||
|  | @ -3,20 +3,30 @@ require File.dirname(__FILE__) + '/helper' | |||
| 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 | ||||
|    | ||||
|   def test_site_posts_in_index | ||||
|     # confirm that {{ site.posts }} is working | ||||
|     puts @s.posts.size | ||||
|     assert @index.include?("#{@s.posts.size} Posts") | ||||
|   end | ||||
| 
 | ||||
|   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 | ||||
| 
 | ||||
|   def test_unpublished_posts_are_hidden | ||||
|     published = Dir[File.join(dest_dir, 'publish_test/2008/02/02/*.html')].map {|f| File.basename(f)} | ||||
|      | ||||
|     assert_equal 1, published.size | ||||
|     assert_equal "published.html", published.first | ||||
|   end | ||||
| end | ||||
|  |  | |||
|  | @ -70,6 +70,28 @@ 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]), '',  "2008-02-02-published.textile") | ||||
| 		assert_equal true, p.published | ||||
|   end | ||||
| 
 | ||||
|   def test_not_published | ||||
|     p = Post.new(File.join(File.dirname(__FILE__), *%w[source]), '',  "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') | ||||
|   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 +132,4 @@ class TestPost < Test::Unit::TestCase | |||
|      | ||||
|     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 | ||||
|  |  | |||
|  | @ -2,8 +2,8 @@ require File.dirname(__FILE__) + '/helper' | |||
| 
 | ||||
| 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 @@ class TestSite < Test::Unit::TestCase | |||
|   | ||||
|   def test_read_posts | ||||
|     @s.read_posts('') | ||||
|      | ||||
|     assert_equal 4, @s.posts.size | ||||
|     posts = Dir[File.join(@source, '_posts/*')] | ||||
|     assert_equal posts.size - 1, @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 publish_test).sort | ||||
| 
 | ||||
|     assert_equal posts.size - 1, @s.posts.size | ||||
|     assert_equal categories, @s.categories.keys.sort | ||||
|     assert_equal 3, @s.categories['foo'].size | ||||
|   end | ||||
| end | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue