jroes-jekyll 0.5.1

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 (48) hide show
  1. data/History.txt +127 -0
  2. data/README.textile +41 -0
  3. data/Rakefile +91 -0
  4. data/VERSION.yml +4 -0
  5. data/bin/jekyll +150 -0
  6. data/lib/jekyll/albino.rb +122 -0
  7. data/lib/jekyll/converters/csv.rb +26 -0
  8. data/lib/jekyll/converters/mephisto.rb +79 -0
  9. data/lib/jekyll/converters/mt.rb +59 -0
  10. data/lib/jekyll/converters/textpattern.rb +50 -0
  11. data/lib/jekyll/converters/typo.rb +49 -0
  12. data/lib/jekyll/converters/wordpress.rb +54 -0
  13. data/lib/jekyll/convertible.rb +82 -0
  14. data/lib/jekyll/core_ext.rb +22 -0
  15. data/lib/jekyll/filters.rb +47 -0
  16. data/lib/jekyll/layout.rb +36 -0
  17. data/lib/jekyll/page.rb +70 -0
  18. data/lib/jekyll/pager.rb +45 -0
  19. data/lib/jekyll/post.rb +247 -0
  20. data/lib/jekyll/site.rb +266 -0
  21. data/lib/jekyll/tags/highlight.rb +56 -0
  22. data/lib/jekyll/tags/include.rb +31 -0
  23. data/lib/jekyll.rb +84 -0
  24. data/test/helper.rb +27 -0
  25. data/test/source/_includes/sig.markdown +3 -0
  26. data/test/source/_layouts/default.html +27 -0
  27. data/test/source/_layouts/simple.html +1 -0
  28. data/test/source/_posts/2008-02-02-not-published.textile +8 -0
  29. data/test/source/_posts/2008-02-02-published.textile +8 -0
  30. data/test/source/_posts/2008-10-18-foo-bar.textile +8 -0
  31. data/test/source/_posts/2008-11-21-complex.textile +8 -0
  32. data/test/source/_posts/2008-12-03-permalinked-post.textile +9 -0
  33. data/test/source/_posts/2008-12-13-include.markdown +8 -0
  34. data/test/source/_posts/2009-01-27-array-categories.textile +10 -0
  35. data/test/source/_posts/2009-01-27-categories.textile +7 -0
  36. data/test/source/_posts/2009-01-27-category.textile +7 -0
  37. data/test/source/_posts/2009-03-12-hash-#1.markdown +6 -0
  38. data/test/source/category/_posts/2008-9-23-categories.textile +6 -0
  39. data/test/source/css/screen.css +76 -0
  40. data/test/source/foo/_posts/bar/2008-12-12-topical-post.textile +8 -0
  41. data/test/source/index.html +22 -0
  42. data/test/source/z_category/_posts/2008-9-23-categories.textile +6 -0
  43. data/test/suite.rb +9 -0
  44. data/test/test_filters.rb +49 -0
  45. data/test/test_post.rb +279 -0
  46. data/test/test_site.rb +69 -0
  47. data/test/test_tags.rb +116 -0
  48. metadata +163 -0
data/test/helper.rb ADDED
@@ -0,0 +1,27 @@
1
+ require 'rubygems'
2
+ gem 'RedCloth', '= 4.1.0'
3
+
4
+ require File.join(File.dirname(__FILE__), *%w[.. lib jekyll])
5
+
6
+ require 'test/unit'
7
+ require 'redgreen'
8
+ require 'shoulda'
9
+ require 'rr'
10
+
11
+ include Jekyll
12
+
13
+ class Test::Unit::TestCase
14
+ include RR::Adapters::TestUnit
15
+
16
+ def dest_dir(*subdirs)
17
+ File.join(File.dirname(__FILE__), 'dest', *subdirs)
18
+ end
19
+
20
+ def source_dir(*subdirs)
21
+ File.join(File.dirname(__FILE__), 'source', *subdirs)
22
+ end
23
+
24
+ def clear_dest
25
+ FileUtils.rm_rf(dest_dir)
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ --
2
+ Tom Preston-Werner
3
+ github.com/mojombo
@@ -0,0 +1,27 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en-us">
5
+ <head>
6
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
7
+ <title>{{ page.title }}</title>
8
+ <meta name="author" content="<%= @page.author %>" />
9
+
10
+ <!-- CodeRay syntax highlighting CSS -->
11
+ <link rel="stylesheet" href="/css/coderay.css" type="text/css" />
12
+
13
+ <!-- Homepage CSS -->
14
+ <link rel="stylesheet" href="/css/screen.css" type="text/css" media="screen, projection" />
15
+ </head>
16
+ <body>
17
+
18
+ <div class="site">
19
+ <div class="title">
20
+ Tom Preston-Werner
21
+ </div>
22
+
23
+ {{ content }}
24
+ </div>
25
+
26
+ </body>
27
+ </html>
@@ -0,0 +1 @@
1
+ <<< {{ content }} >>>
@@ -0,0 +1,8 @@
1
+ ---
2
+ layout: default
3
+ title: Not published!
4
+ published: false
5
+ category: publish_test
6
+ ---
7
+
8
+ This should *not* be published!
@@ -0,0 +1,8 @@
1
+ ---
2
+ layout: default
3
+ title: Publish
4
+ category: publish_test
5
+ ---
6
+
7
+ This should be published.
8
+
@@ -0,0 +1,8 @@
1
+ ---
2
+ layout: default
3
+ title: Foo Bar
4
+ ---
5
+
6
+ h1. {{ page.title }}
7
+
8
+ Best *post* ever
@@ -0,0 +1,8 @@
1
+ ---
2
+ layout: default
3
+ title: Complex
4
+ ---
5
+
6
+ url: {{ page.url }}
7
+ date: {{ page.date }}
8
+ id: {{ page.id }}
@@ -0,0 +1,9 @@
1
+ ---
2
+ title: Post with Permalink
3
+ permalink: my_category/permalinked-post
4
+ ---
5
+
6
+ h1. {{ page.title }}
7
+
8
+
9
+ <p>Best <strong>post</strong> ever</p>
@@ -0,0 +1,8 @@
1
+ ---
2
+ layout: default
3
+ title: Include
4
+ ---
5
+
6
+ {% include sig.markdown %}
7
+
8
+ This _is_ cool
@@ -0,0 +1,10 @@
1
+ ---
2
+ layout: default
3
+ title: Array categories in YAML
4
+ categories:
5
+ - foo
6
+ - bar
7
+ - baz
8
+ ---
9
+
10
+ Best *post* ever
@@ -0,0 +1,7 @@
1
+ ---
2
+ layout: default
3
+ title: Categories in YAML
4
+ categories: foo bar baz
5
+ ---
6
+
7
+ Best *post* ever
@@ -0,0 +1,7 @@
1
+ ---
2
+ layout: default
3
+ title: Category in YAML
4
+ category: foo
5
+ ---
6
+
7
+ Best *post* ever
@@ -0,0 +1,6 @@
1
+ ---
2
+ layout: default
3
+ title: Hash #1
4
+ ---
5
+
6
+ Hashes are nice
@@ -0,0 +1,6 @@
1
+ ---
2
+ layout: default
3
+ title: Categories
4
+ ---
5
+
6
+ Categories _should_ work
@@ -0,0 +1,76 @@
1
+ /*****************************************************************************/
2
+ /*
3
+ /* Common
4
+ /*
5
+ /*****************************************************************************/
6
+
7
+ /* Global Reset */
8
+
9
+ * {
10
+ margin: 0;
11
+ padding: 0;
12
+ }
13
+
14
+ html, body {
15
+ height: 100%;
16
+ }
17
+
18
+ body {
19
+ background-color: white;
20
+ font: 13.34px helvetica, arial, clean, sans-serif;
21
+ *font-size: small;
22
+ text-align: center;
23
+ }
24
+
25
+ h1, h2, h3, h4, h5, h6 {
26
+ font-size: 100%;
27
+ }
28
+
29
+ h1 {
30
+ margin-bottom: 1em;
31
+ }
32
+
33
+ p {
34
+ margin: 1em 0;
35
+ }
36
+
37
+ a {
38
+ color: #00a;
39
+ }
40
+
41
+ a:hover {
42
+ color: black;
43
+ }
44
+
45
+ a:visited {
46
+ color: #a0a;
47
+ }
48
+
49
+ table {
50
+ font-size: inherit;
51
+ font: 100%;
52
+ }
53
+
54
+ /*****************************************************************************/
55
+ /*
56
+ /* Site
57
+ /*
58
+ /*****************************************************************************/
59
+
60
+ .site {
61
+ font-size: 110%;
62
+ text-align: justify;
63
+ width: 40em;
64
+ margin: 3em auto 2em auto;
65
+ line-height: 1.5em;
66
+ }
67
+
68
+ .title {
69
+ color: #a00;
70
+ font-weight: bold;
71
+ margin-bottom: 2em;
72
+ }
73
+
74
+ .site .meta {
75
+ color: #aaa;
76
+ }
@@ -0,0 +1,8 @@
1
+ ---
2
+ layout: default
3
+ title: Topical Post
4
+ ---
5
+
6
+ h1. {{ page.title }}
7
+
8
+ This post has a topic.
@@ -0,0 +1,22 @@
1
+ ---
2
+ layout: default
3
+ title: Tom Preston-Werner
4
+ ---
5
+
6
+ h1. Welcome to my site
7
+
8
+ h2. Please read our {{ site.posts | size }} Posts
9
+
10
+ <ul>
11
+ {% for post in site.posts %}
12
+ <li>{{ post.date }} <a href="{{ post.url }}">{{ post.title }}</a></li>
13
+ {% endfor %}
14
+ </ul>
15
+
16
+ {% assign first_post = site.posts.first %}
17
+ <div id="first_post">
18
+ <h1>{{ first_post.title }}</h1>
19
+ <div>
20
+ {{ first_post.content }}
21
+ </div>
22
+ </div>
@@ -0,0 +1,6 @@
1
+ ---
2
+ layout: default
3
+ title: Categories
4
+ ---
5
+
6
+ Categories _should_ work. Even if ordered after index.
data/test/suite.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'test/unit'
2
+
3
+ # for some reason these tests fail when run via TextMate
4
+ # but succeed when run on the command line.
5
+
6
+ tests = Dir["#{File.dirname(__FILE__)}/test_*.rb"]
7
+ tests.each do |file|
8
+ require file
9
+ end
@@ -0,0 +1,49 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class TestFilters < Test::Unit::TestCase
4
+ class JekyllFilter
5
+ include Jekyll::Filters
6
+ end
7
+
8
+ context "filters" do
9
+ setup do
10
+ @filter = JekyllFilter.new
11
+ end
12
+
13
+ should "textilize with simple string" do
14
+ assert_equal "<p>something <strong>really</strong> simple</p>", @filter.textilize("something *really* simple")
15
+ end
16
+
17
+ should "convert array to sentence string with no args" do
18
+ assert_equal "", @filter.array_to_sentence_string([])
19
+ end
20
+
21
+ should "convert array to sentence string with one arg" do
22
+ assert_equal "1", @filter.array_to_sentence_string([1])
23
+ assert_equal "chunky", @filter.array_to_sentence_string(["chunky"])
24
+ end
25
+
26
+ should "convert array to sentence string with two args" do
27
+ assert_equal "1 and 2", @filter.array_to_sentence_string([1, 2])
28
+ assert_equal "chunky and bacon", @filter.array_to_sentence_string(["chunky", "bacon"])
29
+ end
30
+
31
+ should "convert array to sentence string with multiple args" do
32
+ assert_equal "1, 2, 3, and 4", @filter.array_to_sentence_string([1, 2, 3, 4])
33
+ assert_equal "chunky, bacon, bits, and pieces", @filter.array_to_sentence_string(["chunky", "bacon", "bits", "pieces"])
34
+ end
35
+
36
+ should "escape xml with ampersands" do
37
+ assert_equal "AT&amp;T", @filter.xml_escape("AT&T")
38
+ assert_equal "&lt;code&gt;command &amp;lt;filename&amp;gt;&lt;/code&gt;", @filter.xml_escape("<code>command &lt;filename&gt;</code>")
39
+ end
40
+
41
+ should "escape space as plus" do
42
+ assert_equal "my+things", @filter.cgi_escape("my things")
43
+ end
44
+
45
+ should "escape special characters" do
46
+ assert_equal "hey%21", @filter.cgi_escape("hey!")
47
+ end
48
+ end
49
+ end
data/test/test_post.rb ADDED
@@ -0,0 +1,279 @@
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
+ 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")
23
+
24
+ assert !Post.valid?("lol2008-10-19-foo-bar.textile")
25
+ assert !Post.valid?("blah")
26
+ end
27
+
28
+ context "processing posts" do
29
+ setup do
30
+ @post = Post.allocate
31
+ @post.site = @site
32
+
33
+ @real_file = "2008-10-18-foo-bar.textile"
34
+ @fake_file = "2008-10-19-foo-bar.textile"
35
+ @source = source_dir('_posts')
36
+ end
37
+
38
+ should "keep date, title, and markup type" do
39
+ @post.process(@fake_file)
40
+
41
+ assert_equal Time.parse("2008-10-19"), @post.date
42
+ assert_equal "foo-bar", @post.slug
43
+ assert_equal ".textile", @post.ext
44
+ assert_equal "/2008/10/19", @post.dir
45
+ assert_equal "/2008/10/19/foo-bar", @post.id
46
+ end
47
+
48
+ should "create url based on date and title" do
49
+ @post.categories = []
50
+ @post.process(@fake_file)
51
+ assert_equal "/2008/10/19/foo-bar.html", @post.url
52
+ end
53
+
54
+ should "CGI escape urls" do
55
+ @post.categories = []
56
+ @post.process("2009-03-12-hash-#1.markdown")
57
+ assert_equal "/2009/03/12/hash-%231.html", @post.url
58
+ assert_equal "/2009/03/12/hash-#1", @post.id
59
+ end
60
+
61
+ should "respect permalink in yaml front matter" do
62
+ file = "2008-12-03-permalinked-post.textile"
63
+ @post.process(file)
64
+ @post.read_yaml(@source, file)
65
+
66
+ assert_equal "my_category/permalinked-post", @post.permalink
67
+ assert_equal "my_category", @post.dir
68
+ assert_equal "my_category/permalinked-post", @post.url
69
+ end
70
+
71
+ context "with site wide permalink" do
72
+ setup do
73
+ @post.categories = []
74
+ end
75
+
76
+ context "with unspecified (date) style" do
77
+ setup do
78
+ @post.process(@fake_file)
79
+ end
80
+
81
+ should "process the url correctly" do
82
+ assert_equal "/:categories/:year/:month/:day/:title.html", @post.template
83
+ assert_equal "/2008/10/19/foo-bar.html", @post.url
84
+ end
85
+ end
86
+
87
+ context "with unspecified (date) style and a category" do
88
+ setup do
89
+ @post.categories << "beer"
90
+ @post.process(@fake_file)
91
+ end
92
+
93
+ should "process the url correctly" do
94
+ assert_equal "/:categories/:year/:month/:day/:title.html", @post.template
95
+ assert_equal "/beer/2008/10/19/foo-bar.html", @post.url
96
+ end
97
+ end
98
+
99
+ context "with unspecified (date) style and categories" do
100
+ setup do
101
+ @post.categories << "food"
102
+ @post.categories << "beer"
103
+ @post.process(@fake_file)
104
+ end
105
+
106
+ should "process the url correctly" do
107
+ assert_equal "/:categories/:year/:month/:day/:title.html", @post.template
108
+ assert_equal "/beer/food/2008/10/19/foo-bar.html", @post.url
109
+ end
110
+ end
111
+
112
+ context "with none style" do
113
+ setup do
114
+ @post.site.permalink_style = :none
115
+ @post.process(@fake_file)
116
+ end
117
+
118
+ should "process the url correctly" do
119
+ assert_equal "/:categories/:title.html", @post.template
120
+ assert_equal "/foo-bar.html", @post.url
121
+ end
122
+ end
123
+
124
+ context "with pretty style" do
125
+ setup do
126
+ @post.site.permalink_style = :pretty
127
+ @post.process(@fake_file)
128
+ end
129
+
130
+ should "process the url correctly" do
131
+ assert_equal "/:categories/:year/:month/:day/:title", @post.template
132
+ assert_equal "/2008/10/19/foo-bar", @post.url
133
+ end
134
+ end
135
+
136
+ context "with prefix style and no extension" do
137
+ setup do
138
+ @post.site.permalink_style = "/prefix/:title"
139
+ @post.process(@fake_file)
140
+ end
141
+
142
+ should "process the url correctly" do
143
+ assert_equal "/prefix/:title", @post.template
144
+ assert_equal "/prefix/foo-bar", @post.url
145
+ end
146
+ end
147
+ end
148
+
149
+ should "read yaml front-matter" do
150
+ @post.read_yaml(@source, @real_file)
151
+
152
+ assert_equal({"title" => "Foo Bar", "layout" => "default"}, @post.data)
153
+ assert_equal "\nh1. {{ page.title }}\n\nBest *post* ever", @post.content
154
+ end
155
+
156
+ should "transform textile" do
157
+ @post.process(@real_file)
158
+ @post.read_yaml(@source, @real_file)
159
+ @post.transform
160
+
161
+ assert_equal "<h1>{{ page.title }}</h1>\n<p>Best <strong>post</strong> ever</p>", @post.content
162
+ end
163
+ end
164
+
165
+ context "when in a site" do
166
+ setup do
167
+ clear_dest
168
+ stub(Jekyll).configuration { Jekyll::DEFAULTS }
169
+ @site = Site.new(Jekyll.configuration)
170
+ @site.posts = [setup_post('2008-02-02-published.textile'),
171
+ setup_post('2009-01-27-categories.textile')]
172
+ end
173
+
174
+ should "have next post" do
175
+ assert_equal(@site.posts.last, @site.posts.first.next)
176
+ end
177
+
178
+ should "have previous post" do
179
+ assert_equal(@site.posts.first, @site.posts.last.previous)
180
+ end
181
+
182
+ should "not have previous post if first" do
183
+ assert_equal(nil, @site.posts.first.previous)
184
+ end
185
+
186
+ should "not have next post if last" do
187
+ assert_equal(nil, @site.posts.last.next)
188
+ end
189
+ end
190
+
191
+ context "initializing posts" do
192
+ should "publish when published yaml is no specified" do
193
+ post = setup_post("2008-02-02-published.textile")
194
+ assert_equal true, post.published
195
+ end
196
+
197
+ should "not published when published yaml is false" do
198
+ post = setup_post("2008-02-02-not-published.textile")
199
+ assert_equal false, post.published
200
+ end
201
+
202
+ should "recognize category in yaml" do
203
+ post = setup_post("2009-01-27-category.textile")
204
+ assert post.categories.include?('foo')
205
+ end
206
+
207
+ should "recognize several categories in yaml" do
208
+ post = setup_post("2009-01-27-categories.textile")
209
+ assert post.categories.include?('foo')
210
+ assert post.categories.include?('bar')
211
+ assert post.categories.include?('baz')
212
+ end
213
+
214
+ should "recognize tag in yaml" do
215
+ post = setup_post("2009-05-18-tag.textile")
216
+ assert post.tags.include?('code')
217
+ end
218
+
219
+ should "recognize tags in yaml" do
220
+ post = setup_post("2009-05-18-tags.textile")
221
+ assert post.tags.include?('food')
222
+ assert post.tags.include?('cooking')
223
+ assert post.tags.include?('pizza')
224
+ end
225
+
226
+ context "rendering" do
227
+ setup do
228
+ clear_dest
229
+ end
230
+
231
+ should "render properly" do
232
+ post = setup_post("2008-10-18-foo-bar.textile")
233
+ do_render(post)
234
+ assert_equal "<<< <h1>Foo Bar</h1>\n<p>Best <strong>post</strong> ever</p> >>>", post.output
235
+ end
236
+
237
+ should "write properly" do
238
+ post = setup_post("2008-10-18-foo-bar.textile")
239
+ do_render(post)
240
+ post.write(dest_dir)
241
+
242
+ assert File.directory?(dest_dir)
243
+ assert File.exists?(File.join(dest_dir, '2008', '10', '18', 'foo-bar.html'))
244
+ end
245
+
246
+ should "write properly without html extension" do
247
+ post = setup_post("2008-10-18-foo-bar.textile")
248
+ post.site.permalink_style = ":title"
249
+ do_render(post)
250
+ post.write(dest_dir)
251
+
252
+ assert File.directory?(dest_dir)
253
+ assert File.exists?(File.join(dest_dir, 'foo-bar', 'index.html'))
254
+ end
255
+
256
+ should "insert data" do
257
+ post = setup_post("2008-11-21-complex.textile")
258
+ do_render(post)
259
+
260
+ 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
261
+ end
262
+
263
+ should "include templates" do
264
+ post = setup_post("2008-12-13-include.markdown")
265
+ post.site.source = File.join(File.dirname(__FILE__), 'source')
266
+ do_render(post)
267
+
268
+ assert_equal "<<< <hr />\n<p>Tom Preston-Werner github.com/mojombo</p>\n\n<p>This <em>is</em> cool</p> >>>", post.output
269
+ end
270
+ end
271
+ end
272
+
273
+ should "generate categories and topics" do
274
+ post = Post.new(@site, File.join(File.dirname(__FILE__), *%w[source]), 'foo', 'bar/2008-12-12-topical-post.textile')
275
+ assert_equal ['foo'], post.categories
276
+ end
277
+
278
+ end
279
+ end