jekyll 0.4.1 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of jekyll might be problematic. Click here for more details.

Files changed (51) hide show
  1. data/History.txt +31 -1
  2. data/README.textile +23 -457
  3. data/Rakefile +91 -0
  4. data/VERSION.yml +2 -2
  5. data/bin/jekyll +61 -57
  6. data/lib/jekyll.rb +48 -32
  7. data/lib/jekyll/albino.rb +13 -7
  8. data/lib/jekyll/converters/mephisto.rb +8 -8
  9. data/lib/jekyll/converters/mt.rb +8 -8
  10. data/lib/jekyll/converters/textpattern.rb +4 -4
  11. data/lib/jekyll/converters/typo.rb +8 -8
  12. data/lib/jekyll/converters/wordpress.rb +1 -2
  13. data/lib/jekyll/convertible.rb +33 -22
  14. data/lib/jekyll/core_ext.rb +5 -5
  15. data/lib/jekyll/filters.rb +15 -7
  16. data/lib/jekyll/layout.rb +9 -6
  17. data/lib/jekyll/page.rb +13 -10
  18. data/lib/jekyll/post.rb +108 -39
  19. data/lib/jekyll/site.rb +121 -51
  20. data/lib/jekyll/tags/highlight.rb +12 -9
  21. data/lib/jekyll/tags/include.rb +5 -5
  22. data/test/helper.rb +20 -6
  23. data/test/source/_posts/2008-02-02-not-published.textile +8 -0
  24. data/test/source/_posts/2008-02-02-published.textile +8 -0
  25. data/test/source/_posts/2009-01-27-array-categories.textile +10 -0
  26. data/test/source/_posts/2009-01-27-categories.textile +7 -0
  27. data/test/source/_posts/2009-01-27-category.textile +7 -0
  28. data/test/source/_posts/2009-03-12-hash-#1.markdown +6 -0
  29. data/test/test_filters.rb +39 -27
  30. data/test/test_generated_site.rb +32 -16
  31. data/test/test_post.rb +258 -102
  32. data/test/test_site.rb +60 -28
  33. data/test/test_tags.rb +103 -18
  34. metadata +25 -70
  35. data/test/dest/2008/10/18/foo-bar.html +0 -28
  36. data/test/dest/2008/11/21/complex.html +0 -29
  37. data/test/dest/2008/12/13/include.html +0 -30
  38. data/test/dest/_posts/2008-10-18-foo-bar.html +0 -28
  39. data/test/dest/_posts/2008-11-21-complex.html +0 -29
  40. data/test/dest/_posts/2008-12-03-permalinked-post.html +0 -2
  41. data/test/dest/_posts/2008-12-13-include.html +0 -30
  42. data/test/dest/category/2008/09/23/categories.html +0 -27
  43. data/test/dest/category/_posts/2008-9-23-categories.html +0 -27
  44. data/test/dest/css/screen.css +0 -76
  45. data/test/dest/foo/2008/12/12/topical-post.html +0 -28
  46. data/test/dest/foo/_posts/bar/2008-12-12-topical-post.html +0 -28
  47. data/test/dest/index.html +0 -60
  48. data/test/dest/my_category/permalinked-post +0 -2
  49. data/test/dest/z_category/2008/09/23/categories.html +0 -27
  50. data/test/dest/z_category/_posts/2008-9-23-categories.html +0 -27
  51. data/test/test_jekyll.rb +0 -0
@@ -1,22 +1,38 @@
1
1
  require File.dirname(__FILE__) + '/helper'
2
2
 
3
3
  class TestGeneratedSite < Test::Unit::TestCase
4
- def setup
5
- clear_dest
6
- source = File.join(File.dirname(__FILE__), *%w[source])
7
- @s = Site.new(source, dest_dir)
8
- @s.process
9
- @index = File.read(File.join(dest_dir, 'index.html'))
10
- end
11
-
12
- def test_site_posts_in_index
13
- # confirm that {{ site.posts }} is working
14
- puts @s.posts.size
15
- assert @index.include?("#{@s.posts.size} Posts")
16
- end
4
+ context "generated sites" do
5
+ setup do
6
+ clear_dest
7
+ stub(Jekyll).configuration do
8
+ Jekyll::DEFAULTS.merge({'source' => source_dir, 'destination' => dest_dir})
9
+ end
10
+
11
+ @site = Site.new(Jekyll.configuration)
12
+ @site.process
13
+ @index = File.read(dest_dir('index.html'))
14
+ end
15
+
16
+ should "insert site.posts into the index" do
17
+ assert @index.include?("#{@site.posts.size} Posts")
18
+ end
19
+
20
+ should "render post.content" do
21
+ latest_post = Dir[source_dir('_posts', '*')].sort.last
22
+ post = Post.new(@site, source_dir, '', File.basename(latest_post))
23
+ post.transform
24
+ assert @index.include?(post.content)
25
+ end
26
+
27
+ should "hide unpublished posts" do
28
+ published = Dir[dest_dir('publish_test/2008/02/02/*.html')].map {|f| File.basename(f)}
29
+
30
+ assert_equal 1, published.size
31
+ assert_equal "published.html", published.first
32
+ end
17
33
 
18
- def test_post_content_in_index
19
- # confirm that the {{ post.content }} is rendered OK
20
- assert @index.include?('<p>This <em>is</em> cool</p>')
34
+ should "not copy _posts directory" do
35
+ assert !File.exist?(dest_dir('_posts'))
36
+ end
21
37
  end
22
38
  end
@@ -1,113 +1,269 @@
1
1
  require File.dirname(__FILE__) + '/helper'
2
2
 
3
3
  class TestPost < Test::Unit::TestCase
4
- def setup
5
-
4
+ def setup_post(file)
5
+ Post.new(@site, source_dir, '', file)
6
6
  end
7
-
8
- def test_valid
9
- assert Post.valid?("2008-10-19-foo-bar.textile")
10
- assert Post.valid?("foo/bar/2008-10-19-foo-bar.textile")
11
-
12
- assert !Post.valid?("lol2008-10-19-foo-bar.textile")
13
- assert !Post.valid?("blah")
14
- end
15
-
16
- def test_process
17
- p = Post.allocate
18
- p.process("2008-10-19-foo-bar.textile")
19
-
20
- assert_equal Time.parse("2008-10-19"), p.date
21
- assert_equal "foo-bar", p.slug
22
- assert_equal ".textile", p.ext
23
- end
24
-
25
- def test_url
26
- p = Post.allocate
27
- p.categories = []
28
- p.process("2008-10-19-foo-bar.textile")
29
-
30
- assert_equal "/2008/10/19/foo-bar.html", p.url
31
- end
32
-
33
- def test_permalink
34
- p = Post.allocate
35
- p.process("2008-12-03-permalinked-post.textile")
36
- p.read_yaml(File.join(File.dirname(__FILE__), *%w[source _posts]), "2008-12-03-permalinked-post.textile")
37
7
 
38
- assert_equal "my_category/permalinked-post", p.permalink
8
+ def do_render(post)
9
+ layouts = { "default" => Layout.new(@site, source_dir('_layouts'), "simple.html")}
10
+ post.render(layouts, {"site" => {"posts" => []}})
39
11
  end
40
12
 
41
- def test_dir_respects_permalink
42
- p = Post.allocate
43
- p.process("2008-12-03-permalinked-post.textile")
44
- p.read_yaml(File.join(File.dirname(__FILE__), *%w[source _posts]), "2008-12-03-permalinked-post.textile")
13
+ context "A Post" do
14
+ setup do
15
+ clear_dest
16
+ stub(Jekyll).configuration { Jekyll::DEFAULTS }
17
+ @site = Site.new(Jekyll.configuration)
18
+ end
45
19
 
46
- assert_equal "my_category/", p.dir
47
- end
48
-
49
- def test_url_respects_permalink
50
- p = Post.allocate
51
- p.process("2008-12-03-permalinked-post.textile")
52
- p.read_yaml(File.join(File.dirname(__FILE__), *%w[source _posts]), "2008-12-03-permalinked-post.textile")
20
+ should "ensure valid posts are valid" do
21
+ assert Post.valid?("2008-10-19-foo-bar.textile")
22
+ assert Post.valid?("foo/bar/2008-10-19-foo-bar.textile")
53
23
 
54
- assert_equal "my_category/permalinked-post", p.url
55
- end
24
+ assert !Post.valid?("lol2008-10-19-foo-bar.textile")
25
+ assert !Post.valid?("blah")
26
+ end
27
+
28
+
29
+ context "processing posts" do
30
+ setup do
31
+ @post = Post.allocate
32
+ @post.site = @site
33
+
34
+ @real_file = "2008-10-18-foo-bar.textile"
35
+ @fake_file = "2008-10-19-foo-bar.textile"
36
+ @source = source_dir('_posts')
37
+ end
38
+
39
+ should "keep date, title, and markup type" do
40
+ @post.process(@fake_file)
41
+
42
+ assert_equal Time.parse("2008-10-19"), @post.date
43
+ assert_equal "foo-bar", @post.slug
44
+ assert_equal ".textile", @post.ext
45
+ assert_equal "/2008/10/19", @post.dir
46
+ assert_equal "/2008/10/19/foo-bar", @post.id
47
+ end
48
+
49
+ should "create url based on date and title" do
50
+ @post.categories = []
51
+ @post.process(@fake_file)
52
+ assert_equal "/2008/10/19/foo-bar.html", @post.url
53
+ end
54
+
55
+ should "CGI escape urls" do
56
+ @post.categories = []
57
+ @post.process("2009-03-12-hash-#1.markdown")
58
+ assert_equal "/2009/03/12/hash-%231.html", @post.url
59
+ assert_equal "/2009/03/12/hash-#1", @post.id
60
+ end
61
+
62
+ should "respect permalink in yaml front matter" do
63
+ file = "2008-12-03-permalinked-post.textile"
64
+ @post.process(file)
65
+ @post.read_yaml(@source, file)
66
+
67
+ assert_equal "my_category/permalinked-post", @post.permalink
68
+ assert_equal "my_category", @post.dir
69
+ assert_equal "my_category/permalinked-post", @post.url
70
+ end
71
+
72
+ context "with site wide permalink" do
73
+ setup do
74
+ @post.categories = []
75
+ end
76
+
77
+ context "with unspecified (date) style" do
78
+ setup do
79
+ @post.process(@fake_file)
80
+ end
81
+
82
+ should "process the url correctly" do
83
+ assert_equal "/:categories/:year/:month/:day/:title.html", @post.template
84
+ assert_equal "/2008/10/19/foo-bar.html", @post.url
85
+ end
86
+ end
87
+
88
+ context "with unspecified (date) style and a category" do
89
+ setup do
90
+ @post.categories << "beer"
91
+ @post.process(@fake_file)
92
+ end
93
+
94
+ should "process the url correctly" do
95
+ assert_equal "/:categories/:year/:month/:day/:title.html", @post.template
96
+ assert_equal "/beer/2008/10/19/foo-bar.html", @post.url
97
+ end
98
+ end
99
+
100
+ context "with unspecified (date) style and categories" do
101
+ setup do
102
+ @post.categories << "food"
103
+ @post.categories << "beer"
104
+ @post.process(@fake_file)
105
+ end
106
+
107
+ should "process the url correctly" do
108
+ assert_equal "/:categories/:year/:month/:day/:title.html", @post.template
109
+ assert_equal "/beer/food/2008/10/19/foo-bar.html", @post.url
110
+ end
111
+ end
112
+
113
+ context "with none style" do
114
+ setup do
115
+ @post.site.permalink_style = :none
116
+ @post.process(@fake_file)
117
+ end
118
+
119
+ should "process the url correctly" do
120
+ assert_equal "/:categories/:title.html", @post.template
121
+ assert_equal "/foo-bar.html", @post.url
122
+ end
123
+ end
124
+
125
+ context "with pretty style" do
126
+ setup do
127
+ @post.site.permalink_style = :pretty
128
+ @post.process(@fake_file)
129
+ end
130
+
131
+ should "process the url correctly" do
132
+ assert_equal "/:categories/:year/:month/:day/:title", @post.template
133
+ assert_equal "/2008/10/19/foo-bar", @post.url
134
+ end
135
+ end
136
+
137
+ context "with prefix style and no extension" do
138
+ setup do
139
+ @post.site.permalink_style = "/prefix/:title"
140
+ @post.process(@fake_file)
141
+ end
142
+
143
+ should "process the url correctly" do
144
+ assert_equal "/prefix/:title", @post.template
145
+ assert_equal "/prefix/foo-bar", @post.url
146
+ end
147
+ end
148
+ end
149
+
150
+ should "read yaml front-matter" do
151
+ @post.read_yaml(@source, @real_file)
152
+
153
+ assert_equal({"title" => "Foo Bar", "layout" => "default"}, @post.data)
154
+ assert_equal "\nh1. {{ page.title }}\n\nBest *post* ever", @post.content
155
+ end
156
+
157
+ should "transform textile" do
158
+ @post.process(@real_file)
159
+ @post.read_yaml(@source, @real_file)
160
+ @post.transform
161
+
162
+ assert_equal "<h1>{{ page.title }}</h1>\n<p>Best <strong>post</strong> ever</p>", @post.content
163
+ end
164
+ end
165
+
166
+ context "when in a site" do
167
+ setup do
168
+ clear_dest
169
+ stub(Jekyll).configuration { Jekyll::DEFAULTS }
170
+ @site = Site.new(Jekyll.configuration)
171
+ @site.posts = [setup_post('2008-02-02-published.textile'),
172
+ setup_post('2009-01-27-categories.textile')]
173
+ end
174
+
175
+ should "have next post" do
176
+ assert_equal(@site.posts.last, @site.posts.first.next)
177
+ end
178
+
179
+ should "have previous post" do
180
+ assert_equal(@site.posts.first, @site.posts.last.previous)
181
+ end
182
+
183
+ should "not have previous post if first" do
184
+ assert_equal(nil, @site.posts.first.previous)
185
+ end
186
+
187
+ should "not have next post if last" do
188
+ assert_equal(nil, @site.posts.last.next)
189
+ end
190
+ end
191
+
192
+ context "initializing posts" do
193
+ should "publish when published yaml is no specified" do
194
+ post = setup_post("2008-02-02-published.textile")
195
+ assert_equal true, post.published
196
+ end
197
+
198
+ should "not published when published yaml is false" do
199
+ post = setup_post("2008-02-02-not-published.textile")
200
+ assert_equal false, post.published
201
+ end
202
+
203
+ should "recognize category in yaml" do
204
+ post = setup_post("2009-01-27-category.textile")
205
+ assert post.categories.include?('foo')
206
+ end
207
+
208
+ should "recognize several categories in yaml" do
209
+ post = setup_post("2009-01-27-categories.textile")
210
+ assert post.categories.include?('foo')
211
+ assert post.categories.include?('bar')
212
+ assert post.categories.include?('baz')
213
+ end
214
+
215
+ context "rendering" do
216
+ setup do
217
+ clear_dest
218
+ end
219
+
220
+ should "render properly" do
221
+ post = setup_post("2008-10-18-foo-bar.textile")
222
+ do_render(post)
223
+ assert_equal "<<< <h1>Foo Bar</h1>\n<p>Best <strong>post</strong> ever</p> >>>", post.output
224
+ end
225
+
226
+ should "write properly" do
227
+ post = setup_post("2008-10-18-foo-bar.textile")
228
+ do_render(post)
229
+ post.write(dest_dir)
230
+
231
+ assert File.directory?(dest_dir)
232
+ assert File.exists?(File.join(dest_dir, '2008', '10', '18', 'foo-bar.html'))
233
+ end
234
+
235
+ should "write properly without html extension" do
236
+ post = setup_post("2008-10-18-foo-bar.textile")
237
+ post.site.permalink_style = ":title"
238
+ do_render(post)
239
+ post.write(dest_dir)
240
+
241
+ assert File.directory?(dest_dir)
242
+ assert File.exists?(File.join(dest_dir, 'foo-bar', 'index.html'))
243
+ end
244
+
245
+ should "insert data" do
246
+ post = setup_post("2008-11-21-complex.textile")
247
+ do_render(post)
248
+
249
+ assert_equal "<<< <p>url: /2008/11/21/complex.html<br />\ndate: #{Time.parse("2008-11-21")}<br />\nid: /2008/11/21/complex</p> >>>", post.output
250
+ end
251
+
252
+ should "include templates" do
253
+ post = setup_post("2008-12-13-include.markdown")
254
+ post.site.source = File.join(File.dirname(__FILE__), 'source')
255
+ do_render(post)
256
+
257
+ assert_equal "<<< <hr />\n<p>Tom Preston-Werner github.com/mojombo</p>\n\n<p>This <em>is</em> cool</p> >>>", post.output
258
+ end
259
+ end
260
+ end
261
+
262
+ should "generate categories and topics" do
263
+ post = Post.new(@site, File.join(File.dirname(__FILE__), *%w[source]), 'foo', 'bar/2008-12-12-topical-post.textile')
264
+ assert_equal ['foo'], post.categories
265
+ assert_equal ['bar'], post.topics
266
+ end
56
267
 
57
- def test_read_yaml
58
- p = Post.allocate
59
- p.read_yaml(File.join(File.dirname(__FILE__), *%w[source _posts]), "2008-10-18-foo-bar.textile")
60
-
61
- assert_equal({"title" => "Foo Bar", "layout" => "default"}, p.data)
62
- assert_equal "\nh1. {{ page.title }}\n\nBest *post* ever", p.content
63
- end
64
-
65
- def test_transform
66
- p = Post.allocate
67
- p.process("2008-10-18-foo-bar.textile")
68
- p.read_yaml(File.join(File.dirname(__FILE__), *%w[source _posts]), "2008-10-18-foo-bar.textile")
69
- p.transform
70
-
71
- assert_equal "<h1>{{ page.title }}</h1>\n<p>Best <strong>post</strong> ever</p>", p.content
72
- end
73
-
74
- def test_render
75
- p = Post.new(File.join(File.dirname(__FILE__), *%w[source]), '', "2008-10-18-foo-bar.textile")
76
- layouts = {"default" => Layout.new(File.join(File.dirname(__FILE__), *%w[source _layouts]), "simple.html")}
77
- p.render(layouts, {"site" => {"posts" => []}})
78
-
79
- assert_equal "<<< <h1>Foo Bar</h1>\n<p>Best <strong>post</strong> ever</p> >>>", p.output
80
- end
81
-
82
- def test_write
83
- clear_dest
84
-
85
- p = Post.new(File.join(File.dirname(__FILE__), *%w[source]), '', "2008-10-18-foo-bar.textile")
86
- layouts = {"default" => Layout.new(File.join(File.dirname(__FILE__), *%w[source _layouts]), "simple.html")}
87
- p.render(layouts, {"site" => {"posts" => []}})
88
- p.write(dest_dir)
89
- end
90
-
91
- def test_data
92
- p = Post.new(File.join(File.dirname(__FILE__), *%w[source]), '', "2008-11-21-complex.textile")
93
- layouts = {"default" => Layout.new(File.join(File.dirname(__FILE__), *%w[source _layouts]), "simple.html")}
94
- p.render(layouts, {"site" => {"posts" => []}})
95
-
96
- assert_equal "<<< <p>url: /2008/11/21/complex.html<br />\ndate: #{Time.parse("2008-11-21")}<br />\nid: /2008/11/21/complex</p> >>>", p.output
97
- end
98
-
99
- def test_categories_and_topics
100
- p = Post.new(File.join(File.dirname(__FILE__), *%w[source]), 'foo', 'bar/2008-12-12-topical-post.textile')
101
- assert_equal ['foo'], p.categories
102
- assert_equal ['bar'], p.topics
103
- end
104
-
105
- def test_include
106
- Jekyll.source = File.join(File.dirname(__FILE__), *%w[source])
107
- p = Post.new(File.join(File.dirname(__FILE__), *%w[source]), '', "2008-12-13-include.markdown")
108
- layouts = {"default" => Layout.new(File.join(File.dirname(__FILE__), *%w[source _layouts]), "simple.html")}
109
- p.render(layouts, {"site" => {"posts" => []}})
110
-
111
- assert_equal "<<< <hr />\n<p>Tom Preston-Werner github.com/mojombo</p>\n\n<p>This <em>is</em> cool</p> >>>", p.output
112
268
  end
113
- end
269
+ end
@@ -1,33 +1,65 @@
1
1
  require File.dirname(__FILE__) + '/helper'
2
2
 
3
3
  class TestSite < Test::Unit::TestCase
4
- def setup
5
- source = File.join(File.dirname(__FILE__), *%w[source])
6
- @s = Site.new(source, dest_dir)
7
- end
8
-
9
- def test_site_init
10
-
11
- end
12
-
13
- def test_read_layouts
14
- @s.read_layouts
15
-
16
- assert_equal ["default", "simple"].sort, @s.layouts.keys.sort
17
- end
18
-
19
- def test_read_posts
20
- @s.read_posts('')
21
-
22
- assert_equal 4, @s.posts.size
23
- end
24
-
25
- def test_site_payload
26
- clear_dest
27
- @s.process
28
-
29
- assert_equal 7, @s.posts.length
30
- assert_equal ["category", "foo", "z_category"].sort, @s.categories.keys.sort
31
- assert_equal 1, @s.categories['foo'].length
4
+ context "creating sites" do
5
+ setup do
6
+ stub(Jekyll).configuration do
7
+ Jekyll::DEFAULTS.merge({'source' => source_dir, 'destination' => dest_dir})
8
+ end
9
+ @site = Site.new(Jekyll.configuration)
10
+ end
11
+
12
+ should "reset data before processing" do
13
+ clear_dest
14
+ @site.process
15
+ before_posts = @site.posts.length
16
+ before_layouts = @site.layouts.length
17
+ before_categories = @site.categories.length
18
+
19
+ @site.process
20
+ assert_equal before_posts, @site.posts.length
21
+ assert_equal before_layouts, @site.layouts.length
22
+ assert_equal before_categories, @site.categories.length
23
+ end
24
+
25
+ should "read layouts" do
26
+ @site.read_layouts
27
+ assert_equal ["default", "simple"].sort, @site.layouts.keys.sort
28
+ end
29
+
30
+ should "read posts" do
31
+ @site.read_posts('')
32
+ posts = Dir[source_dir('_posts', '*')]
33
+ assert_equal posts.size - 1, @site.posts.size
34
+ end
35
+
36
+ should "deploy payload" do
37
+ clear_dest
38
+ @site.process
39
+
40
+ posts = Dir[source_dir("**", "_posts", "*")]
41
+ categories = %w(bar baz category foo z_category publish_test).sort
42
+
43
+ assert_equal posts.size - 1, @site.posts.size
44
+ assert_equal categories, @site.categories.keys.sort
45
+ assert_equal 4, @site.categories['foo'].size
46
+ end
47
+
48
+ should "filter entries" do
49
+ ent1 = %w[foo.markdown bar.markdown baz.markdown #baz.markdown#
50
+ .baz.markdow foo.markdown~]
51
+ ent2 = %w[.htaccess _posts bla.bla]
52
+
53
+ assert_equal %w[foo.markdown bar.markdown baz.markdown], @site.filter_entries(ent1)
54
+ assert_equal ent2, @site.filter_entries(ent2)
55
+ end
56
+
57
+ should "filter entries with exclude" do
58
+ excludes = %w[README TODO]
59
+ includes = %w[index.html site.css]
60
+
61
+ @site.exclude = excludes
62
+ assert_equal includes, @site.filter_entries(excludes + includes)
63
+ end
32
64
  end
33
65
  end