spinto-jekyll 0.11.2.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 (108) hide show
  1. data/Gemfile +2 -0
  2. data/History.txt +321 -0
  3. data/LICENSE +21 -0
  4. data/README.textile +41 -0
  5. data/Rakefile +166 -0
  6. data/bin/jekyll +289 -0
  7. data/cucumber.yml +1 -0
  8. data/features/create_sites.feature +112 -0
  9. data/features/embed_filters.feature +60 -0
  10. data/features/markdown.feature +30 -0
  11. data/features/pagination.feature +27 -0
  12. data/features/permalinks.feature +65 -0
  13. data/features/post_data.feature +153 -0
  14. data/features/site_configuration.feature +145 -0
  15. data/features/site_data.feature +82 -0
  16. data/features/step_definitions/jekyll_steps.rb +145 -0
  17. data/features/support/env.rb +19 -0
  18. data/lib/jekyll.rb +136 -0
  19. data/lib/jekyll/converter.rb +50 -0
  20. data/lib/jekyll/converters/identity.rb +22 -0
  21. data/lib/jekyll/converters/markdown.rb +125 -0
  22. data/lib/jekyll/converters/textile.rb +50 -0
  23. data/lib/jekyll/convertible.rb +112 -0
  24. data/lib/jekyll/core_ext.rb +52 -0
  25. data/lib/jekyll/errors.rb +6 -0
  26. data/lib/jekyll/filters.rb +118 -0
  27. data/lib/jekyll/generator.rb +7 -0
  28. data/lib/jekyll/generators/pagination.rb +113 -0
  29. data/lib/jekyll/layout.rb +44 -0
  30. data/lib/jekyll/migrators/csv.rb +26 -0
  31. data/lib/jekyll/migrators/drupal.rb +103 -0
  32. data/lib/jekyll/migrators/enki.rb +49 -0
  33. data/lib/jekyll/migrators/joomla.rb +53 -0
  34. data/lib/jekyll/migrators/marley.rb +52 -0
  35. data/lib/jekyll/migrators/mephisto.rb +84 -0
  36. data/lib/jekyll/migrators/mt.rb +86 -0
  37. data/lib/jekyll/migrators/posterous.rb +67 -0
  38. data/lib/jekyll/migrators/rss.rb +47 -0
  39. data/lib/jekyll/migrators/textpattern.rb +58 -0
  40. data/lib/jekyll/migrators/tumblr.rb +195 -0
  41. data/lib/jekyll/migrators/typo.rb +51 -0
  42. data/lib/jekyll/migrators/wordpress.rb +294 -0
  43. data/lib/jekyll/migrators/wordpressdotcom.rb +70 -0
  44. data/lib/jekyll/page.rb +155 -0
  45. data/lib/jekyll/plugin.rb +77 -0
  46. data/lib/jekyll/post.rb +257 -0
  47. data/lib/jekyll/site.rb +337 -0
  48. data/lib/jekyll/static_file.rb +72 -0
  49. data/lib/jekyll/tags/highlight.rb +76 -0
  50. data/lib/jekyll/tags/include.rb +37 -0
  51. data/lib/jekyll/tags/post_url.rb +38 -0
  52. data/lib/spinto-jekyll.rb +3 -0
  53. data/spinto-jekyll.gemspec +155 -0
  54. data/test/helper.rb +34 -0
  55. data/test/source/.htaccess +8 -0
  56. data/test/source/_includes/sig.markdown +3 -0
  57. data/test/source/_layouts/default.html +27 -0
  58. data/test/source/_layouts/simple.html +1 -0
  59. data/test/source/_posts/2008-02-02-not-published.textile +8 -0
  60. data/test/source/_posts/2008-02-02-published.textile +8 -0
  61. data/test/source/_posts/2008-10-18-foo-bar.textile +8 -0
  62. data/test/source/_posts/2008-11-21-complex.textile +8 -0
  63. data/test/source/_posts/2008-12-03-permalinked-post.textile +9 -0
  64. data/test/source/_posts/2008-12-13-include.markdown +8 -0
  65. data/test/source/_posts/2009-01-27-array-categories.textile +10 -0
  66. data/test/source/_posts/2009-01-27-categories.textile +7 -0
  67. data/test/source/_posts/2009-01-27-category.textile +7 -0
  68. data/test/source/_posts/2009-01-27-empty-categories.textile +7 -0
  69. data/test/source/_posts/2009-01-27-empty-category.textile +7 -0
  70. data/test/source/_posts/2009-03-12-hash-#1.markdown +6 -0
  71. data/test/source/_posts/2009-05-18-empty-tag.textile +6 -0
  72. data/test/source/_posts/2009-05-18-empty-tags.textile +6 -0
  73. data/test/source/_posts/2009-05-18-tag.textile +6 -0
  74. data/test/source/_posts/2009-05-18-tags.textile +9 -0
  75. data/test/source/_posts/2009-06-22-empty-yaml.textile +3 -0
  76. data/test/source/_posts/2009-06-22-no-yaml.textile +1 -0
  77. data/test/source/_posts/2010-01-08-triple-dash.markdown +5 -0
  78. data/test/source/_posts/2010-01-09-date-override.textile +7 -0
  79. data/test/source/_posts/2010-01-09-time-override.textile +7 -0
  80. data/test/source/_posts/2010-01-09-timezone-override.textile +7 -0
  81. data/test/source/_posts/2010-01-16-override-data.textile +4 -0
  82. data/test/source/_posts/2011-04-12-md-extension.md +7 -0
  83. data/test/source/_posts/2011-04-12-text-extension.text +0 -0
  84. data/test/source/about.html +6 -0
  85. data/test/source/category/_posts/2008-9-23-categories.textile +6 -0
  86. data/test/source/contacts.html +5 -0
  87. data/test/source/css/screen.css +76 -0
  88. data/test/source/deal.with.dots.html +7 -0
  89. data/test/source/foo/_posts/bar/2008-12-12-topical-post.textile +8 -0
  90. data/test/source/index.html +22 -0
  91. data/test/source/sitemap.xml +32 -0
  92. data/test/source/win/_posts/2009-05-24-yaml-linebreak.markdown +7 -0
  93. data/test/source/z_category/_posts/2008-9-23-categories.textile +6 -0
  94. data/test/suite.rb +11 -0
  95. data/test/test_configuration.rb +29 -0
  96. data/test/test_core_ext.rb +66 -0
  97. data/test/test_filters.rb +62 -0
  98. data/test/test_generated_site.rb +72 -0
  99. data/test/test_kramdown.rb +23 -0
  100. data/test/test_page.rb +117 -0
  101. data/test/test_pager.rb +113 -0
  102. data/test/test_post.rb +456 -0
  103. data/test/test_rdiscount.rb +18 -0
  104. data/test/test_redcarpet.rb +21 -0
  105. data/test/test_redcloth.rb +86 -0
  106. data/test/test_site.rb +220 -0
  107. data/test/test_tags.rb +201 -0
  108. metadata +336 -0
@@ -0,0 +1,72 @@
1
+ require 'helper'
2
+
3
+ class TestGeneratedSite < Test::Unit::TestCase
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 "ensure post count is as expected" do
17
+ assert_equal 28, @site.posts.size
18
+ end
19
+
20
+ should "insert site.posts into the index" do
21
+ assert @index.include?("#{@site.posts.size} Posts")
22
+ end
23
+
24
+ should "render latest post's content" do
25
+ assert @index.include?(@site.posts.last.content)
26
+ end
27
+
28
+ should "hide unpublished posts" do
29
+ published = Dir[dest_dir('publish_test/2008/02/02/*.html')].map {|f| File.basename(f)}
30
+
31
+ assert_equal 1, published.size
32
+ assert_equal "published.html", published.first
33
+ end
34
+
35
+ should "not copy _posts directory" do
36
+ assert !File.exist?(dest_dir('_posts'))
37
+ end
38
+
39
+ should "process other static files and generate correct permalinks" do
40
+ assert File.exists?(dest_dir('/about/index.html'))
41
+ assert File.exists?(dest_dir('/contacts.html'))
42
+ end
43
+ end
44
+
45
+ context "generating limited posts" do
46
+ setup do
47
+ clear_dest
48
+ stub(Jekyll).configuration do
49
+ Jekyll::DEFAULTS.merge({'source' => source_dir, 'destination' => dest_dir, 'limit_posts' => 5})
50
+ end
51
+
52
+ @site = Site.new(Jekyll.configuration)
53
+ @site.process
54
+ @index = File.read(dest_dir('index.html'))
55
+ end
56
+
57
+ should "generate only the specified number of posts" do
58
+ assert_equal 5, @site.posts.size
59
+ end
60
+
61
+ should "ensure limit posts is 1 or more" do
62
+ assert_raise ArgumentError do
63
+ clear_dest
64
+ stub(Jekyll).configuration do
65
+ Jekyll::DEFAULTS.merge({'source' => source_dir, 'destination' => dest_dir, 'limit_posts' => 0})
66
+ end
67
+
68
+ @site = Site.new(Jekyll.configuration)
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,23 @@
1
+ require 'helper'
2
+
3
+ class TestKramdown < Test::Unit::TestCase
4
+ context "kramdown" do
5
+ setup do
6
+ config = {
7
+ 'markdown' => 'kramdown',
8
+ 'kramdown' => {
9
+ 'auto_ids' => false,
10
+ 'footnote_nr' => 1,
11
+ 'entity_output' => 'as_char',
12
+ 'toc_levels' => '1..6'
13
+ }
14
+ }
15
+ @markdown = MarkdownConverter.new config
16
+ end
17
+
18
+ # http://kramdown.rubyforge.org/converter/html.html#options
19
+ should "pass kramdown options" do
20
+ assert_equal "<h1>Some Header</h1>", @markdown.convert('# Some Header #').strip
21
+ end
22
+ end
23
+ end
data/test/test_page.rb ADDED
@@ -0,0 +1,117 @@
1
+ require 'helper'
2
+
3
+ class TestPage < Test::Unit::TestCase
4
+ def setup_page(file)
5
+ @page = Page.new(@site, source_dir, '', file)
6
+ end
7
+
8
+ def do_render(page)
9
+ layouts = { "default" => Layout.new(@site, source_dir('_layouts'), "simple.html")}
10
+ page.render(layouts, {"site" => {"posts" => []}})
11
+ end
12
+
13
+ context "A Page" 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 pages" do
21
+ should "create url based on filename" do
22
+ @page = setup_page('contacts.html')
23
+ assert_equal "/contacts.html", @page.url
24
+ end
25
+
26
+ should "deal properly with extensions" do
27
+ @page = setup_page('deal.with.dots.html')
28
+ assert_equal ".html", @page.ext
29
+ end
30
+
31
+ should "deal properly with dots" do
32
+ @page = setup_page('deal.with.dots.html')
33
+ assert_equal "deal.with.dots", @page.basename
34
+ end
35
+
36
+ context "with pretty url style" do
37
+ setup do
38
+ @site.permalink_style = :pretty
39
+ end
40
+
41
+ should "return dir correctly" do
42
+ @page = setup_page('contacts.html')
43
+ assert_equal '/contacts/', @page.dir
44
+ end
45
+
46
+ should "return dir correctly for index page" do
47
+ @page = setup_page('index.html')
48
+ assert_equal '/', @page.dir
49
+ end
50
+ end
51
+
52
+ context "with any other url style" do
53
+ should "return dir correctly" do
54
+ @site.permalink_style = nil
55
+ @page = setup_page('contacts.html')
56
+ assert_equal '/', @page.dir
57
+ end
58
+ end
59
+
60
+ should "respect permalink in yaml front matter" do
61
+ file = "about.html"
62
+ @page = setup_page(file)
63
+
64
+ assert_equal "/about/", @page.permalink
65
+ assert_equal @page.permalink, @page.url
66
+ assert_equal "/about/", @page.dir
67
+ end
68
+ end
69
+
70
+ context "rendering" do
71
+ setup do
72
+ clear_dest
73
+ end
74
+
75
+ should "write properly" do
76
+ page = setup_page('contacts.html')
77
+ do_render(page)
78
+ page.write(dest_dir)
79
+
80
+ assert File.directory?(dest_dir)
81
+ assert File.exists?(File.join(dest_dir, 'contacts.html'))
82
+ end
83
+
84
+ should "write properly without html extension" do
85
+ page = setup_page('contacts.html')
86
+ page.site.permalink_style = :pretty
87
+ do_render(page)
88
+ page.write(dest_dir)
89
+
90
+ assert File.directory?(dest_dir)
91
+ assert File.exists?(File.join(dest_dir, 'contacts', 'index.html'))
92
+ end
93
+
94
+ should "write properly with extension different from html" do
95
+ page = setup_page("sitemap.xml")
96
+ page.site.permalink_style = :pretty
97
+ do_render(page)
98
+ page.write(dest_dir)
99
+
100
+ assert_equal("/sitemap.xml", page.url)
101
+ assert_nil(page.url[/\.html$/])
102
+ assert File.directory?(dest_dir)
103
+ assert File.exists?(File.join(dest_dir,'sitemap.xml'))
104
+ end
105
+
106
+ should "write dotfiles properly" do
107
+ page = setup_page('.htaccess')
108
+ do_render(page)
109
+ page.write(dest_dir)
110
+
111
+ assert File.directory?(dest_dir)
112
+ assert File.exists?(File.join(dest_dir, '.htaccess'))
113
+ end
114
+ end
115
+
116
+ end
117
+ end
@@ -0,0 +1,113 @@
1
+ require 'helper'
2
+
3
+ class TestPager < Test::Unit::TestCase
4
+
5
+ should "calculate number of pages" do
6
+ assert_equal(0, Pager.calculate_pages([], '2'))
7
+ assert_equal(1, Pager.calculate_pages([1], '2'))
8
+ assert_equal(1, Pager.calculate_pages([1,2], '2'))
9
+ assert_equal(2, Pager.calculate_pages([1,2,3], '2'))
10
+ assert_equal(2, Pager.calculate_pages([1,2,3,4], '2'))
11
+ assert_equal(3, Pager.calculate_pages([1,2,3,4,5], '2'))
12
+ end
13
+
14
+ context "pagination disabled" do
15
+ setup do
16
+ stub(Jekyll).configuration do
17
+ Jekyll::DEFAULTS.merge({
18
+ 'source' => source_dir,
19
+ 'destination' => dest_dir
20
+ })
21
+ end
22
+ @config = Jekyll.configuration
23
+ end
24
+
25
+ should "report that pagination is disabled" do
26
+ assert !Pager.pagination_enabled?(@config, 'index.html')
27
+ end
28
+
29
+ end
30
+
31
+ context "pagination enabled for 2" do
32
+ setup do
33
+ stub(Jekyll).configuration do
34
+ Jekyll::DEFAULTS.merge({
35
+ 'source' => source_dir,
36
+ 'destination' => dest_dir,
37
+ 'paginate' => 2
38
+ })
39
+ end
40
+
41
+ @config = Jekyll.configuration
42
+ @site = Site.new(@config)
43
+ @site.process
44
+ @posts = @site.posts
45
+ end
46
+
47
+ should "report that pagination is enabled" do
48
+ assert Pager.pagination_enabled?(@config, 'index.html')
49
+ end
50
+
51
+ context "with 4 posts" do
52
+ setup do
53
+ @posts = @site.posts[1..4] # limit to 4
54
+ end
55
+
56
+ should "create first pager" do
57
+ pager = Pager.new(@config, 1, @posts)
58
+ assert_equal(2, pager.posts.size)
59
+ assert_equal(2, pager.total_pages)
60
+ assert_nil(pager.previous_page)
61
+ assert_equal(2, pager.next_page)
62
+ end
63
+
64
+ should "create second pager" do
65
+ pager = Pager.new(@config, 2, @posts)
66
+ assert_equal(2, pager.posts.size)
67
+ assert_equal(2, pager.total_pages)
68
+ assert_equal(1, pager.previous_page)
69
+ assert_nil(pager.next_page)
70
+ end
71
+
72
+ should "not create third pager" do
73
+ assert_raise(RuntimeError) { Pager.new(@config, 3, @posts) }
74
+ end
75
+
76
+ end
77
+
78
+ context "with 5 posts" do
79
+ setup do
80
+ @posts = @site.posts[1..5] # limit to 5
81
+ end
82
+
83
+ should "create first pager" do
84
+ pager = Pager.new(@config, 1, @posts)
85
+ assert_equal(2, pager.posts.size)
86
+ assert_equal(3, pager.total_pages)
87
+ assert_nil(pager.previous_page)
88
+ assert_equal(2, pager.next_page)
89
+ end
90
+
91
+ should "create second pager" do
92
+ pager = Pager.new(@config, 2, @posts)
93
+ assert_equal(2, pager.posts.size)
94
+ assert_equal(3, pager.total_pages)
95
+ assert_equal(1, pager.previous_page)
96
+ assert_equal(3, pager.next_page)
97
+ end
98
+
99
+ should "create third pager" do
100
+ pager = Pager.new(@config, 3, @posts)
101
+ assert_equal(1, pager.posts.size)
102
+ assert_equal(3, pager.total_pages)
103
+ assert_equal(2, pager.previous_page)
104
+ assert_nil(pager.next_page)
105
+ end
106
+
107
+ should "not create fourth pager" do
108
+ assert_raise(RuntimeError) { Pager.new(@config, 4, @posts) }
109
+ end
110
+
111
+ end
112
+ end
113
+ end
data/test/test_post.rb ADDED
@@ -0,0 +1,456 @@
1
+ require '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-09-09-foo-bar.textile")
22
+ assert Post.valid?("foo/bar/2008-09-09-foo-bar.textile")
23
+
24
+ assert !Post.valid?("lol2008-09-09-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-09-09-foo-bar.textile"
35
+ @source = source_dir('_posts')
36
+ end
37
+
38
+ should "keep date, title, and markup type" do
39
+ @post.categories = []
40
+ @post.process(@fake_file)
41
+
42
+ assert_equal Time.parse("2008-09-09"), @post.date
43
+ assert_equal "foo-bar", @post.slug
44
+ assert_equal ".textile", @post.ext
45
+ assert_equal "/2008/09/09", @post.dir
46
+ assert_equal "/2008/09/09/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/09/09/foo-bar.html", @post.url
53
+ end
54
+
55
+ should "raise a good error on invalid post date" do
56
+ assert_raise Jekyll::FatalException do
57
+ @post.process("2009-27-03-foo-bar.textile")
58
+ end
59
+ end
60
+
61
+ should "CGI escape urls" do
62
+ @post.categories = []
63
+ @post.process("2009-03-12-hash-#1.markdown")
64
+ assert_equal "/2009/03/12/hash-%231.html", @post.url
65
+ assert_equal "/2009/03/12/hash-#1", @post.id
66
+ end
67
+
68
+ should "respect permalink in yaml front matter" do
69
+ file = "2008-12-03-permalinked-post.textile"
70
+ @post.process(file)
71
+ @post.read_yaml(@source, file)
72
+
73
+ assert_equal "my_category/permalinked-post", @post.permalink
74
+ assert_equal "my_category", @post.dir
75
+ assert_equal "my_category/permalinked-post", @post.url
76
+ end
77
+
78
+ context "with CRLF linebreaks" do
79
+ setup do
80
+ @real_file = "2009-05-24-yaml-linebreak.markdown"
81
+ @source = source_dir('win/_posts')
82
+ end
83
+ should "read yaml front-matter" do
84
+ @post.read_yaml(@source, @real_file)
85
+
86
+ assert_equal({"title" => "Test title", "layout" => "post", "tag" => "Ruby"}, @post.data)
87
+ assert_equal "This is the content", @post.content
88
+ end
89
+ end
90
+
91
+ context "with embedded triple dash" do
92
+ setup do
93
+ @real_file = "2010-01-08-triple-dash.markdown"
94
+ end
95
+ should "consume the embedded dashes" do
96
+ @post.read_yaml(@source, @real_file)
97
+
98
+ assert_equal({"title" => "Foo --- Bar"}, @post.data)
99
+ assert_equal "Triple the fun!", @post.content
100
+ end
101
+ end
102
+
103
+ context "with site wide permalink" do
104
+ setup do
105
+ @post.categories = []
106
+ end
107
+
108
+ context "with unspecified (date) style" do
109
+ setup do
110
+ @post.process(@fake_file)
111
+ end
112
+
113
+ should "process the url correctly" do
114
+ assert_equal "/:categories/:year/:month/:day/:title.html", @post.template
115
+ assert_equal "/2008/09/09/foo-bar.html", @post.url
116
+ end
117
+ end
118
+
119
+ context "with unspecified (date) style and a category" do
120
+ setup do
121
+ @post.categories << "beer"
122
+ @post.process(@fake_file)
123
+ end
124
+
125
+ should "process the url correctly" do
126
+ assert_equal "/:categories/:year/:month/:day/:title.html", @post.template
127
+ assert_equal "/beer/2008/09/09/foo-bar.html", @post.url
128
+ end
129
+ end
130
+
131
+ context "with unspecified (date) style and categories" do
132
+ setup do
133
+ @post.categories << "food"
134
+ @post.categories << "beer"
135
+ @post.process(@fake_file)
136
+ end
137
+
138
+ should "process the url correctly" do
139
+ assert_equal "/:categories/:year/:month/:day/:title.html", @post.template
140
+ assert_equal "/food/beer/2008/09/09/foo-bar.html", @post.url
141
+ end
142
+ end
143
+
144
+ context "with space (categories)" do
145
+ setup do
146
+ @post.categories << "French cuisine"
147
+ @post.categories << "Belgian beer"
148
+ @post.process(@fake_file)
149
+ end
150
+
151
+ should "process the url correctly" do
152
+ assert_equal "/:categories/:year/:month/:day/:title.html", @post.template
153
+ assert_equal "/French%20cuisine/Belgian%20beer/2008/09/09/foo-bar.html", @post.url
154
+ end
155
+ end
156
+
157
+ context "with none style" do
158
+ setup do
159
+ @post.site.permalink_style = :none
160
+ @post.process(@fake_file)
161
+ end
162
+
163
+ should "process the url correctly" do
164
+ assert_equal "/:categories/:title.html", @post.template
165
+ assert_equal "/foo-bar.html", @post.url
166
+ end
167
+ end
168
+
169
+ context "with pretty style" do
170
+ setup do
171
+ @post.site.permalink_style = :pretty
172
+ @post.process(@fake_file)
173
+ end
174
+
175
+ should "process the url correctly" do
176
+ assert_equal "/:categories/:year/:month/:day/:title/", @post.template
177
+ assert_equal "/2008/09/09/foo-bar/", @post.url
178
+ end
179
+ end
180
+
181
+ context "with custom date permalink" do
182
+ setup do
183
+ @post.site.permalink_style = '/:categories/:year/:i_month/:i_day/:title/'
184
+ @post.process(@fake_file)
185
+ end
186
+
187
+ should "process the url correctly" do
188
+ assert_equal "/2008/9/9/foo-bar/", @post.url
189
+ end
190
+ end
191
+
192
+ context "with prefix style and no extension" do
193
+ setup do
194
+ @post.site.permalink_style = "/prefix/:title"
195
+ @post.process(@fake_file)
196
+ end
197
+
198
+ should "process the url correctly" do
199
+ assert_equal "/prefix/:title", @post.template
200
+ assert_equal "/prefix/foo-bar", @post.url
201
+ end
202
+ end
203
+ end
204
+
205
+ should "read yaml front-matter" do
206
+ @post.read_yaml(@source, @real_file)
207
+
208
+ assert_equal({"title" => "Foo Bar", "layout" => "default"}, @post.data)
209
+ assert_equal "h1. {{ page.title }}\n\nBest *post* ever", @post.content
210
+ end
211
+
212
+ should "transform textile" do
213
+ @post.process(@real_file)
214
+ @post.read_yaml(@source, @real_file)
215
+ @post.transform
216
+
217
+ assert_equal "<h1>{{ page.title }}</h1>\n<p>Best <strong>post</strong> ever</p>", @post.content
218
+ end
219
+ end
220
+
221
+ context "when in a site" do
222
+ setup do
223
+ clear_dest
224
+ stub(Jekyll).configuration { Jekyll::DEFAULTS }
225
+ @site = Site.new(Jekyll.configuration)
226
+ @site.posts = [setup_post('2008-02-02-published.textile'),
227
+ setup_post('2009-01-27-categories.textile')]
228
+ end
229
+
230
+ should "have next post" do
231
+ assert_equal(@site.posts.last, @site.posts.first.next)
232
+ end
233
+
234
+ should "have previous post" do
235
+ assert_equal(@site.posts.first, @site.posts.last.previous)
236
+ end
237
+
238
+ should "not have previous post if first" do
239
+ assert_equal(nil, @site.posts.first.previous)
240
+ end
241
+
242
+ should "not have next post if last" do
243
+ assert_equal(nil, @site.posts.last.next)
244
+ end
245
+ end
246
+
247
+ context "initializing posts" do
248
+ should "publish when published yaml is no specified" do
249
+ post = setup_post("2008-02-02-published.textile")
250
+ assert_equal true, post.published
251
+ end
252
+
253
+ should "not published when published yaml is false" do
254
+ post = setup_post("2008-02-02-not-published.textile")
255
+ assert_equal false, post.published
256
+ end
257
+
258
+ should "recognize date in yaml" do
259
+ post = setup_post("2010-01-09-date-override.textile")
260
+ do_render(post)
261
+ assert_equal Time, post.date.class
262
+ assert_equal Time, post.to_liquid["date"].class
263
+ assert_equal "/2010/01/10/date-override.html", post.url
264
+ assert_equal "<p>Post with a front matter date</p>\n<p>10 Jan 2010</p>", post.output
265
+ end
266
+
267
+ should "recognize time in yaml" do
268
+ post = setup_post("2010-01-09-time-override.textile")
269
+ do_render(post)
270
+ assert_equal Time, post.date.class
271
+ assert_equal Time, post.to_liquid["date"].class
272
+ assert_equal "/2010/01/10/time-override.html", post.url
273
+ assert_equal "<p>Post with a front matter time</p>\n<p>10 Jan 2010</p>", post.output
274
+ end
275
+
276
+ should "recognize time with timezone in yaml" do
277
+ post = setup_post("2010-01-09-timezone-override.textile")
278
+ do_render(post)
279
+ assert_equal Time, post.date.class
280
+ assert_equal Time, post.to_liquid["date"].class
281
+ assert_equal "/2010/01/10/timezone-override.html", post.url
282
+ assert_equal "<p>Post with a front matter time with timezone</p>\n<p>10 Jan 2010</p>", post.output
283
+ end
284
+
285
+ should "to_liquid prioritizes post attributes over data" do
286
+ post = setup_post("2010-01-16-override-data.textile")
287
+ assert_equal Array, post.tags.class
288
+ assert_equal Array, post.to_liquid["tags"].class
289
+ assert_equal Time, post.date.class
290
+ assert_equal Time, post.to_liquid["date"].class
291
+ end
292
+
293
+ should "recognize category in yaml" do
294
+ post = setup_post("2009-01-27-category.textile")
295
+ assert post.categories.include?('foo')
296
+ end
297
+
298
+ should "recognize several categories in yaml" do
299
+ post = setup_post("2009-01-27-categories.textile")
300
+ assert post.categories.include?('foo')
301
+ assert post.categories.include?('bar')
302
+ assert post.categories.include?('baz')
303
+ end
304
+
305
+ should "recognize empty category in yaml" do
306
+ post = setup_post("2009-01-27-empty-category.textile")
307
+ assert_equal [], post.categories
308
+ end
309
+
310
+ should "recognize empty categories in yaml" do
311
+ post = setup_post("2009-01-27-empty-categories.textile")
312
+ assert_equal [], post.categories
313
+ end
314
+
315
+ should "recognize tag in yaml" do
316
+ post = setup_post("2009-05-18-tag.textile")
317
+ assert post.tags.include?('code')
318
+ end
319
+
320
+ should "recognize tags in yaml" do
321
+ post = setup_post("2009-05-18-tags.textile")
322
+ assert post.tags.include?('food')
323
+ assert post.tags.include?('cooking')
324
+ assert post.tags.include?('pizza')
325
+ end
326
+
327
+ should "recognize empty tag in yaml" do
328
+ post = setup_post("2009-05-18-empty-tag.textile")
329
+ assert_equal [], post.tags
330
+ end
331
+
332
+ should "recognize empty tags in yaml" do
333
+ post = setup_post("2009-05-18-empty-tags.textile")
334
+ assert_equal [], post.tags
335
+ end
336
+
337
+ should "allow no yaml" do
338
+ post = setup_post("2009-06-22-no-yaml.textile")
339
+ assert_equal "No YAML.", post.content
340
+ end
341
+
342
+ should "allow empty yaml" do
343
+ post = setup_post("2009-06-22-empty-yaml.textile")
344
+ assert_equal "Empty YAML.", post.content
345
+ end
346
+
347
+ context "rendering" do
348
+ setup do
349
+ clear_dest
350
+ end
351
+
352
+ should "render properly" do
353
+ post = setup_post("2008-10-18-foo-bar.textile")
354
+ do_render(post)
355
+ assert_equal "<<< <h1>Foo Bar</h1>\n<p>Best <strong>post</strong> ever</p> >>>", post.output
356
+ end
357
+
358
+ should "write properly" do
359
+ post = setup_post("2008-10-18-foo-bar.textile")
360
+ do_render(post)
361
+ post.write(dest_dir)
362
+
363
+ assert File.directory?(dest_dir)
364
+ assert File.exists?(File.join(dest_dir, '2008', '10', '18', 'foo-bar.html'))
365
+ end
366
+
367
+ should "write properly without html extension" do
368
+ post = setup_post("2008-10-18-foo-bar.textile")
369
+ post.site.permalink_style = ":title"
370
+ do_render(post)
371
+ post.write(dest_dir)
372
+
373
+ assert File.directory?(dest_dir)
374
+ assert File.exists?(File.join(dest_dir, 'foo-bar', 'index.html'))
375
+ end
376
+
377
+ should "insert data" do
378
+ post = setup_post("2008-11-21-complex.textile")
379
+ do_render(post)
380
+
381
+ 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
382
+ end
383
+
384
+ should "include templates" do
385
+ post = setup_post("2008-12-13-include.markdown")
386
+ post.site.source = File.join(File.dirname(__FILE__), 'source')
387
+ do_render(post)
388
+
389
+ assert_equal "<<< <hr />\n<p>Tom Preston-Werner github.com/mojombo</p>\n\n<p>This <em>is</em> cool</p> >>>", post.output
390
+ end
391
+
392
+ should "render date specified in front matter properly" do
393
+ post = setup_post("2010-01-09-date-override.textile")
394
+ do_render(post)
395
+
396
+ assert_equal "<p>Post with a front matter date</p>\n<p>10 Jan 2010</p>", post.output
397
+ end
398
+
399
+ should "render time specified in front matter properly" do
400
+ post = setup_post("2010-01-09-time-override.textile")
401
+ do_render(post)
402
+
403
+ assert_equal "<p>Post with a front matter time</p>\n<p>10 Jan 2010</p>", post.output
404
+ end
405
+
406
+ end
407
+ end
408
+
409
+ should "generate categories and topics" do
410
+ post = Post.new(@site, File.join(File.dirname(__FILE__), *%w[source]), 'foo', 'bar/2008-12-12-topical-post.textile')
411
+ assert_equal ['foo'], post.categories
412
+ end
413
+ end
414
+
415
+ context "converter file extension settings" do
416
+ setup do
417
+ stub(Jekyll).configuration { Jekyll::DEFAULTS }
418
+ @site = Site.new(Jekyll.configuration)
419
+ end
420
+
421
+ should "process .md as markdown under default configuration" do
422
+ post = setup_post '2011-04-12-md-extension.md'
423
+ conv = post.converter
424
+ assert conv.kind_of? Jekyll::MarkdownConverter
425
+ end
426
+
427
+ should "process .text as indentity under default configuration" do
428
+ post = setup_post '2011-04-12-text-extension.text'
429
+ conv = post.converter
430
+ assert conv.kind_of? Jekyll::IdentityConverter
431
+ end
432
+
433
+ should "process .text as markdown under alternate configuration" do
434
+ @site.config['markdown_ext'] = 'markdown,mdw,mdwn,md,text'
435
+ post = setup_post '2011-04-12-text-extension.text'
436
+ conv = post.converter
437
+ assert conv.kind_of? Jekyll::MarkdownConverter
438
+ end
439
+
440
+ should "process .md as markdown under alternate configuration" do
441
+ @site.config['markdown_ext'] = 'markdown,mkd,mkdn,md,text'
442
+ post = setup_post '2011-04-12-text-extension.text'
443
+ conv = post.converter
444
+ assert conv.kind_of? Jekyll::MarkdownConverter
445
+ end
446
+
447
+ should "process .text as textile under alternate configuration" do
448
+ @site.config['textile_ext'] = 'textile,text'
449
+ post = setup_post '2011-04-12-text-extension.text'
450
+ conv = post.converter
451
+ assert conv.kind_of? Jekyll::TextileConverter
452
+ end
453
+
454
+ end
455
+
456
+ end