pol-hyde 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. data/.gitignore +6 -0
  2. data/History.txt +151 -0
  3. data/README.textile +56 -0
  4. data/Rakefile +91 -0
  5. data/VERSION.yml +4 -0
  6. data/bin/hyde +150 -0
  7. data/features/create_sites.feature +46 -0
  8. data/features/embed_filters.feature +60 -0
  9. data/features/pagination.feature +40 -0
  10. data/features/permalinks.feature +65 -0
  11. data/features/post_data.feature +153 -0
  12. data/features/site_configuration.feature +63 -0
  13. data/features/site_data.feature +82 -0
  14. data/features/step_definitions/jekyll_steps.rb +136 -0
  15. data/features/support/env.rb +16 -0
  16. data/hyde.gemspec +138 -0
  17. data/lib/jekyll.rb +86 -0
  18. data/lib/jekyll/albino.rb +122 -0
  19. data/lib/jekyll/converters/csv.rb +26 -0
  20. data/lib/jekyll/converters/mephisto.rb +79 -0
  21. data/lib/jekyll/converters/mt.rb +59 -0
  22. data/lib/jekyll/converters/textpattern.rb +50 -0
  23. data/lib/jekyll/converters/typo.rb +49 -0
  24. data/lib/jekyll/converters/wordpress.rb +54 -0
  25. data/lib/jekyll/convertible.rb +78 -0
  26. data/lib/jekyll/core_ext.rb +30 -0
  27. data/lib/jekyll/engines.rb +69 -0
  28. data/lib/jekyll/filters.rb +47 -0
  29. data/lib/jekyll/layout.rb +36 -0
  30. data/lib/jekyll/page.rb +112 -0
  31. data/lib/jekyll/pager.rb +45 -0
  32. data/lib/jekyll/post.rb +270 -0
  33. data/lib/jekyll/site.rb +211 -0
  34. data/lib/jekyll/tags/highlight.rb +56 -0
  35. data/lib/jekyll/tags/include.rb +31 -0
  36. data/test/helper.rb +27 -0
  37. data/test/source/_includes/sig.markdown +3 -0
  38. data/test/source/_layouts/default.html +27 -0
  39. data/test/source/_layouts/simple.html +1 -0
  40. data/test/source/_posts/2008-02-02-not-published.textile +8 -0
  41. data/test/source/_posts/2008-02-02-published.textile +7 -0
  42. data/test/source/_posts/2008-10-18-foo-bar.textile +8 -0
  43. data/test/source/_posts/2008-11-21-complex.textile +8 -0
  44. data/test/source/_posts/2008-12-03-permalinked-post.textile +9 -0
  45. data/test/source/_posts/2008-12-13-include.markdown +8 -0
  46. data/test/source/_posts/2009-01-27-array-categories.textile +10 -0
  47. data/test/source/_posts/2009-01-27-categories.textile +7 -0
  48. data/test/source/_posts/2009-01-27-category.textile +7 -0
  49. data/test/source/_posts/2009-03-12-hash-#1.markdown +6 -0
  50. data/test/source/_posts/2009-05-18-tag.textile +6 -0
  51. data/test/source/_posts/2009-05-18-tags.textile +9 -0
  52. data/test/source/_posts/2009-06-03-haml-rocks.haml +11 -0
  53. data/test/source/_posts/2009-06-22-empty-yaml.textile +3 -0
  54. data/test/source/_posts/2009-06-22-no-yaml.textile +1 -0
  55. data/test/source/_posts/foo-bar.textile +9 -0
  56. data/test/source/about.html +6 -0
  57. data/test/source/category/_posts/2008-9-23-categories.textile +6 -0
  58. data/test/source/contacts.html +5 -0
  59. data/test/source/css/screen.css +76 -0
  60. data/test/source/foo/_posts/bar/2008-12-12-topical-post.textile +8 -0
  61. data/test/source/index.html +22 -0
  62. data/test/source/sitemap.xml +23 -0
  63. data/test/source/win/_posts/2009-05-24-yaml-linebreak.markdown +7 -0
  64. data/test/source/z_category/_posts/2008-9-23-categories.textile +6 -0
  65. data/test/suite.rb +9 -0
  66. data/test/test_configuration.rb +29 -0
  67. data/test/test_filters.rb +49 -0
  68. data/test/test_generated_site.rb +40 -0
  69. data/test/test_page.rb +98 -0
  70. data/test/test_pager.rb +47 -0
  71. data/test/test_post.rb +308 -0
  72. data/test/test_site.rb +85 -0
  73. data/test/test_tags.rb +117 -0
  74. metadata +193 -0
@@ -0,0 +1,47 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class TestPager < Test::Unit::TestCase
4
+ context "pagination enabled" do
5
+ setup do
6
+ stub(Jekyll).configuration do
7
+ Jekyll::DEFAULTS.merge({
8
+ 'source' => source_dir,
9
+ 'destination' => dest_dir,
10
+ 'paginate' => 2
11
+ })
12
+ end
13
+
14
+ @config = Jekyll.configuration
15
+ @site = Site.new(@config)
16
+ @posts = @site.read_posts('')
17
+ end
18
+
19
+ should "calculate number of pages" do
20
+ assert_equal(2, Pager.calculate_pages(@posts, @config['paginate']))
21
+ end
22
+
23
+ should "create first pager" do
24
+ pager = Pager.new(@config, 1, @posts)
25
+ assert_equal(@config['paginate'].to_i, pager.posts.size)
26
+ assert_equal(2, pager.total_pages)
27
+ assert_nil(pager.previous_page)
28
+ assert_equal(2, pager.next_page)
29
+ end
30
+
31
+ should "create second pager" do
32
+ pager = Pager.new(@config, 2, @posts)
33
+ assert_equal(@posts.size - @config['paginate'].to_i, pager.posts.size)
34
+ assert_equal(2, pager.total_pages)
35
+ assert_equal(1, pager.previous_page)
36
+ assert_nil(pager.next_page)
37
+ end
38
+
39
+ should "not create third pager" do
40
+ assert_raise(RuntimeError) { Pager.new(@config, 3, @posts) }
41
+ end
42
+
43
+ should "report that pagination is enabled" do
44
+ assert Pager.pagination_enabled?(@config, 'index.html')
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,308 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class TestPost < Test::Unit::TestCase
4
+ def setup_post(file)
5
+ Post.new(@site, source_dir, '', file)
6
+ end
7
+
8
+ def do_render(post)
9
+ layouts = { "default" => Layout.new(@site, source_dir('_layouts'), "simple.html")}
10
+ post.render(layouts, {"site" => {"posts" => []}})
11
+ end
12
+
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
19
+
20
+ context "processing posts" do
21
+ setup do
22
+ @post = Post.allocate
23
+ @post.site = @site
24
+
25
+ @real_file = "2008-10-18-foo-bar.textile"
26
+ @fake_file = "2008-10-19-foo-bar.textile"
27
+ @source = source_dir('_posts')
28
+ end
29
+
30
+ should "keep date, title, and markup type" do
31
+ @post.process(@fake_file)
32
+
33
+ assert_equal Time.parse("2008-10-19"), @post.date
34
+ assert_equal "foo-bar", @post.slug
35
+ assert_equal ".textile", @post.ext
36
+ assert_equal "/2008/10/19", @post.dir
37
+ assert_equal "/2008/10/19/foo-bar", @post.id
38
+ end
39
+
40
+ should "create url based on date and title" do
41
+ @post.categories = []
42
+ @post.process(@fake_file)
43
+ assert_equal "/2008/10/19/foo-bar.html", @post.url
44
+ end
45
+
46
+ should "CGI escape urls" do
47
+ @post.categories = []
48
+ @post.process("2009-03-12-hash-#1.markdown")
49
+ assert_equal "/2009/03/12/hash-%231.html", @post.url
50
+ assert_equal "/2009/03/12/hash-#1", @post.id
51
+ end
52
+
53
+ should "respect permalink in yaml front matter" do
54
+ file = "2008-12-03-permalinked-post.textile"
55
+ @post.process(file)
56
+ @post.read_yaml(@source, file)
57
+
58
+ assert_equal "my_category/permalinked-post", @post.permalink
59
+ assert_equal "my_category", @post.dir
60
+ assert_equal "my_category/permalinked-post", @post.url
61
+ end
62
+
63
+ context "with CRLF linebreaks" do
64
+ setup do
65
+ @real_file = "2009-05-24-yaml-linebreak.markdown"
66
+ @source = source_dir('win/_posts')
67
+ end
68
+ should "read yaml front-matter" do
69
+ @post.read_yaml(@source, @real_file)
70
+
71
+ assert_equal({"title" => "Test title", "layout" => "post", "tag" => "Ruby"}, @post.data)
72
+ assert_equal "\r\nThis is the content", @post.content
73
+ end
74
+ end
75
+
76
+ context "with site wide permalink" do
77
+ setup do
78
+ @post.categories = []
79
+ end
80
+
81
+ context "with unspecified (date) style" do
82
+ setup do
83
+ @post.process(@fake_file)
84
+ end
85
+
86
+ should "process the url correctly" do
87
+ assert_equal "/:categories/:year/:month/:day/:title.html", @post.template
88
+ assert_equal "/2008/10/19/foo-bar.html", @post.url
89
+ end
90
+ end
91
+
92
+ context "with unspecified (date) style and a category" do
93
+ setup do
94
+ @post.categories << "beer"
95
+ @post.process(@fake_file)
96
+ end
97
+
98
+ should "process the url correctly" do
99
+ assert_equal "/:categories/:year/:month/:day/:title.html", @post.template
100
+ assert_equal "/beer/2008/10/19/foo-bar.html", @post.url
101
+ end
102
+ end
103
+
104
+ context "with unspecified (date) style and categories" do
105
+ setup do
106
+ @post.categories << "food"
107
+ @post.categories << "beer"
108
+ @post.process(@fake_file)
109
+ end
110
+
111
+ should "process the url correctly" do
112
+ assert_equal "/:categories/:year/:month/:day/:title.html", @post.template
113
+ assert_equal "/beer/food/2008/10/19/foo-bar.html", @post.url
114
+ end
115
+ end
116
+
117
+ context "with none style" do
118
+ setup do
119
+ @post.site.permalink_style = :none
120
+ @post.process(@fake_file)
121
+ end
122
+
123
+ should "process the url correctly" do
124
+ assert_equal "/:categories/:title.html", @post.template
125
+ assert_equal "/foo-bar.html", @post.url
126
+ end
127
+ end
128
+
129
+ context "with pretty style" do
130
+ setup do
131
+ @post.site.permalink_style = :pretty
132
+ @post.process(@fake_file)
133
+ end
134
+
135
+ should "process the url correctly" do
136
+ assert_equal "/:categories/:year/:month/:day/:title/", @post.template
137
+ assert_equal "/2008/10/19/foo-bar/", @post.url
138
+ end
139
+ end
140
+
141
+ context "with prefix style and no extension" do
142
+ setup do
143
+ @post.site.permalink_style = "/prefix/:title"
144
+ @post.process(@fake_file)
145
+ end
146
+
147
+ should "process the url correctly" do
148
+ assert_equal "/prefix/:title", @post.template
149
+ assert_equal "/prefix/foo-bar", @post.url
150
+ end
151
+ end
152
+ end
153
+
154
+ should "read yaml front-matter" do
155
+ @post.read_yaml(@source, @real_file)
156
+
157
+ assert_equal({"title" => "Foo Bar", "layout" => "default"}, @post.data)
158
+ assert_equal "\nh1. {{ page.title }}\n\nBest *post* ever", @post.content
159
+ end
160
+
161
+ should "transform textile" do
162
+ @post.process(@real_file)
163
+ @post.read_yaml(@source, @real_file)
164
+ @post.transform
165
+
166
+ assert_equal "<h1>{{ page.title }}</h1>\n<p>Best <strong>post</strong> ever</p>", @post.content
167
+ end
168
+ end
169
+
170
+ context "when in a site" do
171
+ setup do
172
+ clear_dest
173
+ stub(Jekyll).configuration { Jekyll::DEFAULTS }
174
+ @site = Site.new(Jekyll.configuration)
175
+ @site.posts = [setup_post('2008-02-02-published.textile'),
176
+ setup_post('2009-01-27-categories.textile')]
177
+ end
178
+
179
+ should "have next post" do
180
+ assert_equal(@site.posts.last, @site.posts.first.next)
181
+ end
182
+
183
+ should "have previous post" do
184
+ assert_equal(@site.posts.first, @site.posts.last.previous)
185
+ end
186
+
187
+ should "not have previous post if first" do
188
+ assert_equal(nil, @site.posts.first.previous)
189
+ end
190
+
191
+ should "not have next post if last" do
192
+ assert_equal(nil, @site.posts.last.next)
193
+ end
194
+ end
195
+
196
+ context "initializing posts" do
197
+ should "publish when published yaml is no specified" do
198
+ post = setup_post("2008-02-02-published.textile")
199
+ assert_equal true, post.published
200
+ end
201
+
202
+ should "not published when published yaml is false" do
203
+ post = setup_post("2008-02-02-not-published.textile")
204
+ assert_equal false, post.published
205
+ end
206
+
207
+ should "recognize category in yaml" do
208
+ post = setup_post("2009-01-27-category.textile")
209
+ assert post.categories.include?('foo')
210
+ end
211
+
212
+ should "recognize several categories in yaml" do
213
+ post = setup_post("2009-01-27-categories.textile")
214
+ assert post.categories.include?('foo')
215
+ assert post.categories.include?('bar')
216
+ assert post.categories.include?('baz')
217
+ end
218
+
219
+ should "recognize tag in yaml" do
220
+ post = setup_post("2009-05-18-tag.textile")
221
+ assert post.tags.include?('code')
222
+ end
223
+
224
+ should "recognize tags in yaml" do
225
+ post = setup_post("2009-05-18-tags.textile")
226
+ assert post.tags.include?('food')
227
+ assert post.tags.include?('cooking')
228
+ assert post.tags.include?('pizza')
229
+ end
230
+
231
+ should "allow no yaml" do
232
+ post = setup_post("2009-06-22-no-yaml.textile")
233
+ assert_equal "No YAML.", post.content
234
+ end
235
+
236
+ should "allow empty yaml" do
237
+ post = setup_post("2009-06-22-empty-yaml.textile")
238
+ assert_equal "Empty YAML.", post.content
239
+ end
240
+
241
+ context "rendering" do
242
+ setup do
243
+ clear_dest
244
+ end
245
+
246
+ should "render properly" do
247
+ post = setup_post("2008-10-18-foo-bar.textile")
248
+ do_render(post)
249
+ assert_equal "<<< <h1>Foo Bar</h1>\n<p>Best <strong>post</strong> ever</p> >>>", post.output
250
+ end
251
+
252
+ should "render haml properly" do
253
+ post = setup_post("2009-06-03-haml-rocks.haml")
254
+ do_render(post)
255
+ assert_equal "<<< <h1>Haml is cool</h1>\n<p>\n The title of this page is " +
256
+ "\"Haml is indeed cool\"\n</p>\n<p></p>\n >>>", post.output
257
+ end
258
+
259
+ should "write properly" do
260
+ post = setup_post("2008-10-18-foo-bar.textile")
261
+ do_render(post)
262
+ post.write(dest_dir)
263
+
264
+ assert File.directory?(dest_dir)
265
+ assert File.exists?(File.join(dest_dir, '2008', '10', '18', 'foo-bar.html'))
266
+ end
267
+
268
+ should "write properly without html extension" do
269
+ post = setup_post("2008-10-18-foo-bar.textile")
270
+ post.site.permalink_style = ":title"
271
+ do_render(post)
272
+ post.write(dest_dir)
273
+
274
+ assert File.directory?(dest_dir)
275
+ assert File.exists?(File.join(dest_dir, 'foo-bar', 'index.html'))
276
+ end
277
+
278
+ should "read post that lacks a date in the filename" do
279
+ post = setup_post("foo-bar.textile")
280
+ assert post.date.class == Time
281
+ assert post.data["title"] == "Foo Bar Baz"
282
+ assert post.url == "/2009/05/31/foo-bar-baz.html"
283
+ end
284
+
285
+ should "insert data" do
286
+ post = setup_post("2008-11-21-complex.textile")
287
+ do_render(post)
288
+
289
+ 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
290
+ end
291
+
292
+ should "include templates" do
293
+ post = setup_post("2008-12-13-include.markdown")
294
+ post.site.source = File.join(File.dirname(__FILE__), 'source')
295
+ do_render(post)
296
+
297
+ assert_equal "<<< <hr />\n<p>Tom Preston-Werner github.com/mojombo</p>\n\n<p>This <em>is</em> cool</p> >>>", post.output
298
+ end
299
+ end
300
+ end
301
+
302
+ should "generate categories and topics" do
303
+ post = Post.new(@site, File.join(File.dirname(__FILE__), *%w[source]), 'foo', 'bar/2008-12-12-topical-post.textile')
304
+ assert_equal ['foo'], post.categories
305
+ end
306
+
307
+ end
308
+ end
@@ -0,0 +1,85 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class TestSite < Test::Unit::TestCase
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 "have an empty tag hash by default" do
13
+ assert_equal Hash.new, @site.tags
14
+ end
15
+
16
+ should "reset data before processing" do
17
+ clear_dest
18
+ @site.process
19
+ before_posts = @site.posts.length
20
+ before_layouts = @site.layouts.length
21
+ before_categories = @site.categories.length
22
+
23
+ @site.process
24
+ assert_equal before_posts, @site.posts.length
25
+ assert_equal before_layouts, @site.layouts.length
26
+ assert_equal before_categories, @site.categories.length
27
+ end
28
+
29
+ should "read layouts" do
30
+ @site.read_layouts
31
+ assert_equal ["default", "simple"].sort, @site.layouts.keys.sort
32
+ end
33
+
34
+ should "read posts" do
35
+ @site.read_posts('')
36
+ posts = Dir[source_dir('_posts', '*')]
37
+ assert_equal posts.size - 1, @site.posts.size
38
+ end
39
+
40
+ should "deploy payload" do
41
+ clear_dest
42
+ @site.process
43
+
44
+ posts = Dir[source_dir("**", "_posts", "*")]
45
+ categories = %w(bar baz category foo z_category publish_test win).sort
46
+
47
+ assert_equal posts.size - 1, @site.posts.size
48
+ assert_equal categories, @site.categories.keys.sort
49
+ assert_equal 4, @site.categories['foo'].size
50
+ end
51
+
52
+ should "filter entries" do
53
+ ent1 = %w[foo.markdown bar.markdown baz.markdown #baz.markdown#
54
+ .baz.markdow foo.markdown~]
55
+ ent2 = %w[.htaccess _posts bla.bla]
56
+
57
+ assert_equal %w[foo.markdown bar.markdown baz.markdown], @site.filter_entries(ent1)
58
+ assert_equal ent2, @site.filter_entries(ent2)
59
+ end
60
+
61
+ should "filter entries with exclude" do
62
+ excludes = %w[README TODO]
63
+ includes = %w[index.html site.css]
64
+
65
+ @site.exclude = excludes
66
+ assert_equal includes, @site.filter_entries(excludes + includes)
67
+ end
68
+
69
+ context 'with an invalid markdown processor in the configuration' do
70
+
71
+ should 'give a meaningful error message' do
72
+ bad_processor = 'not a processor name'
73
+ begin
74
+ Site.new(Jekyll.configuration.merge({ 'markdown' => bad_processor }))
75
+ flunk 'Invalid markdown processors should cause a failure on site creation'
76
+ rescue RuntimeError => e
77
+ assert e.to_s =~ /invalid|bad/i
78
+ assert e.to_s =~ %r{#{bad_processor}}
79
+ end
80
+ end
81
+
82
+ end
83
+
84
+ end
85
+ end
@@ -0,0 +1,117 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/helper'
4
+
5
+ class TestTags < Test::Unit::TestCase
6
+
7
+ def create_post(content, override = {}, markdown = true)
8
+ stub(Jekyll).configuration do
9
+ Jekyll::DEFAULTS.merge({'pygments' => true}).merge(override)
10
+ end
11
+ site = Site.new(Jekyll.configuration)
12
+ info = { :filters => [Jekyll::Filters], :registers => { :site => site } }
13
+
14
+ if markdown
15
+ payload = {"content_type" => "markdown"}
16
+ else
17
+ payload = {"content_type" => "textile"}
18
+ end
19
+ @result = Liquid::Template.parse(content).render(payload, info)
20
+
21
+ if markdown
22
+ @result = Engines.markdown(@result)
23
+ else
24
+ @result = Engines.textile(@result)
25
+ end
26
+ end
27
+
28
+ def fill_post(code, override = {})
29
+ content = <<CONTENT
30
+ ---
31
+ title: This is a test
32
+ ---
33
+
34
+ This document results in a markdown error with maruku
35
+
36
+ {% highlight text %}
37
+ #{code}
38
+ {% endhighlight %}
39
+ CONTENT
40
+ create_post(content, override)
41
+ end
42
+
43
+ context "post content has highlight tag" do
44
+ setup do
45
+ fill_post("test")
46
+ end
47
+
48
+ should "not cause a markdown error" do
49
+ assert_no_match /markdown\-html\-error/, @result
50
+ end
51
+
52
+ should "render markdown with pygments line handling" do
53
+ assert_match %{<pre>test\n</pre>}, @result
54
+ end
55
+ end
56
+
57
+ context "post content has highlight tag with UTF character" do
58
+ setup do
59
+ fill_post("Æ")
60
+ end
61
+
62
+ should "render markdown with pygments line handling" do
63
+ assert_match %{<pre>Æ\n</pre>}, @result
64
+ end
65
+ end
66
+
67
+ context "simple post with markdown and pre tags" do
68
+ setup do
69
+ @content = <<CONTENT
70
+ ---
71
+ title: Maruku vs. RDiscount
72
+ ---
73
+
74
+ _FIGHT!_
75
+
76
+ {% highlight ruby %}
77
+ puts "3..2..1.."
78
+ {% endhighlight %}
79
+
80
+ *FINISH HIM*
81
+ CONTENT
82
+ end
83
+
84
+ context "using Textile" do
85
+ setup do
86
+ create_post(@content, {}, false)
87
+ end
88
+
89
+ # Broken in RedCloth 4.1.9
90
+ should "not textilize highlight block" do
91
+ assert_no_match %r{3\.\.2\.\.1\.\.&quot;</span><br />}, @result
92
+ end
93
+ end
94
+
95
+ context "using Maruku" do
96
+ setup do
97
+ create_post(@content)
98
+ end
99
+
100
+ should "parse correctly" do
101
+ assert_match %r{<em>FIGHT!</em>}, @result
102
+ assert_match %r{<em>FINISH HIM</em>}, @result
103
+ end
104
+ end
105
+
106
+ context "using RDiscount" do
107
+ setup do
108
+ create_post(@content, 'markdown' => 'rdiscount')
109
+ end
110
+
111
+ should "parse correctly" do
112
+ assert_match %r{<em>FIGHT!</em>}, @result
113
+ assert_match %r{<em>FINISH HIM</em>}, @result
114
+ end
115
+ end
116
+ end
117
+ end