tigefa 1.0.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (249) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.markdown +91 -0
  3. data/Gemfile +2 -0
  4. data/History.markdown +871 -0
  5. data/LICENSE +15 -14
  6. data/README.markdown +59 -0
  7. data/Rakefile +298 -0
  8. data/bin/tigefa +158 -0
  9. data/cucumber.yml +3 -0
  10. data/features/create_sites.feature +141 -0
  11. data/features/data.feature +65 -0
  12. data/features/drafts.feature +25 -0
  13. data/features/embed_filters.feature +60 -0
  14. data/features/include_tag.feature +57 -0
  15. data/features/markdown.feature +67 -0
  16. data/features/pagination.feature +82 -0
  17. data/features/permalinks.feature +85 -0
  18. data/features/post_data.feature +214 -0
  19. data/features/post_excerpts.feature +50 -0
  20. data/features/site_configuration.feature +235 -0
  21. data/features/site_data.feature +107 -0
  22. data/features/step_definitions/tigefa_steps.rb +189 -0
  23. data/features/support/env.rb +75 -0
  24. data/lib/site_template/.gitignore +1 -0
  25. data/lib/site_template/_config.yml +3 -0
  26. data/lib/site_template/_layouts/default.html +44 -0
  27. data/lib/site_template/_layouts/post.html +9 -0
  28. data/lib/site_template/_posts/0000-00-00-welcome-to-jekyll.markdown.erb +24 -0
  29. data/lib/site_template/css/main.css +160 -0
  30. data/lib/site_template/css/syntax.css +60 -0
  31. data/lib/site_template/index.html +13 -0
  32. data/lib/tigefa/cleaner.rb +73 -0
  33. data/lib/tigefa/command.rb +27 -0
  34. data/lib/tigefa/commands/build.rb +70 -0
  35. data/lib/tigefa/commands/doctor.rb +67 -0
  36. data/lib/tigefa/commands/new.rb +67 -0
  37. data/lib/tigefa/commands/serve.rb +65 -0
  38. data/lib/tigefa/configuration.rb +238 -0
  39. data/lib/tigefa/converter.rb +48 -0
  40. data/lib/tigefa/converters/identity.rb +21 -0
  41. data/lib/tigefa/converters/markdown/kramdown_parser.rb +29 -0
  42. data/lib/tigefa/converters/markdown/maruku_parser.rb +56 -0
  43. data/lib/tigefa/converters/markdown/rdiscount_parser.rb +37 -0
  44. data/lib/tigefa/converters/markdown/redcarpet_parser.rb +70 -0
  45. data/lib/tigefa/converters/markdown.rb +43 -0
  46. data/lib/tigefa/converters/textile.rb +50 -0
  47. data/lib/tigefa/convertible.rb +174 -0
  48. data/lib/tigefa/core_ext.rb +90 -0
  49. data/lib/tigefa/deprecator.rb +36 -0
  50. data/lib/tigefa/draft.rb +35 -0
  51. data/lib/tigefa/entry_filter.rb +35 -0
  52. data/lib/tigefa/errors.rb +4 -0
  53. data/lib/tigefa/excerpt.rb +113 -0
  54. data/lib/tigefa/filters.rb +174 -0
  55. data/lib/tigefa/generator.rb +4 -0
  56. data/lib/tigefa/generators/pagination.rb +217 -0
  57. data/lib/tigefa/layout.rb +45 -0
  58. data/lib/tigefa/mime.types +85 -0
  59. data/lib/tigefa/page.rb +160 -0
  60. data/lib/tigefa/plugin.rb +75 -0
  61. data/lib/tigefa/post.rb +312 -0
  62. data/lib/tigefa/related_posts.rb +59 -0
  63. data/lib/tigefa/site.rb +427 -0
  64. data/lib/tigefa/static_file.rb +70 -0
  65. data/lib/tigefa/stevenson.rb +89 -0
  66. data/lib/tigefa/tags/gist.rb +48 -0
  67. data/lib/tigefa/tags/highlight.rb +85 -0
  68. data/lib/tigefa/tags/include.rb +134 -0
  69. data/lib/tigefa/tags/post_url.rb +63 -0
  70. data/lib/tigefa/url.rb +69 -0
  71. data/lib/tigefa.rb +98 -4
  72. data/script/bootstrap +2 -0
  73. data/site/.gitignore +4 -0
  74. data/site/CNAME +1 -0
  75. data/site/README +1 -0
  76. data/site/_config.yml +6 -0
  77. data/site/_includes/analytics.html +32 -0
  78. data/site/_includes/docs_contents.html +16 -0
  79. data/site/_includes/docs_contents_mobile.html +23 -0
  80. data/site/_includes/docs_option.html +11 -0
  81. data/site/_includes/docs_ul.html +20 -0
  82. data/site/_includes/footer.html +15 -0
  83. data/site/_includes/header.html +18 -0
  84. data/site/_includes/news_contents.html +23 -0
  85. data/site/_includes/news_contents_mobile.html +11 -0
  86. data/site/_includes/news_item.html +24 -0
  87. data/site/_includes/primary-nav-items.html +14 -0
  88. data/site/_includes/section_nav.html +22 -0
  89. data/site/_includes/top.html +17 -0
  90. data/site/_layouts/default.html +12 -0
  91. data/site/_layouts/docs.html +23 -0
  92. data/site/_layouts/news.html +19 -0
  93. data/site/_layouts/news_item.html +27 -0
  94. data/site/_posts/2013-05-06-jekyll-1-0-0-released.markdown +23 -0
  95. data/site/_posts/2013-05-08-jekyll-1-0-1-released.markdown +27 -0
  96. data/site/_posts/2013-05-12-jekyll-1-0-2-released.markdown +28 -0
  97. data/site/_posts/2013-06-07-jekyll-1-0-3-released.markdown +25 -0
  98. data/site/_posts/2013-07-14-jekyll-1-1-0-released.markdown +27 -0
  99. data/site/_posts/2013-07-24-jekyll-1-1-1-released.markdown +31 -0
  100. data/site/_posts/2013-07-25-jekyll-1-0-4-released.markdown +20 -0
  101. data/site/_posts/2013-07-25-jekyll-1-1-2-released.markdown +20 -0
  102. data/site/_posts/2013-09-06-jekyll-1-2-0-released.markdown +23 -0
  103. data/site/_posts/2013-09-14-jekyll-1-2-1-released.markdown +19 -0
  104. data/site/_posts/2013-10-28-jekyll-1-3-0-rc1-released.markdown +19 -0
  105. data/site/_posts/2013-11-04-jekyll-1-3-0-released.markdown +43 -0
  106. data/site/_posts/2013-11-26-jekyll-1-3-1-released.markdown +21 -0
  107. data/site/_posts/2013-12-07-jekyll-1-4-0-released.markdown +30 -0
  108. data/site/_posts/2013-12-16-jekyll-1-4-2-released.markdown +18 -0
  109. data/site/_posts/2014-01-13-jekyll-1-4-3-released.markdown +27 -0
  110. data/site/css/gridism.css +110 -0
  111. data/site/css/normalize.css +1 -0
  112. data/site/css/pygments.css +70 -0
  113. data/site/css/style.css +946 -0
  114. data/site/docs/configuration.md +375 -0
  115. data/site/docs/contributing.md +128 -0
  116. data/site/docs/datafiles.md +63 -0
  117. data/site/docs/deployment-methods.md +109 -0
  118. data/site/docs/drafts.md +21 -0
  119. data/site/docs/extras.md +56 -0
  120. data/site/docs/frontmatter.md +180 -0
  121. data/site/docs/github-pages.md +91 -0
  122. data/site/docs/heroku.md +9 -0
  123. data/site/docs/history.md +866 -0
  124. data/site/docs/index.md +52 -0
  125. data/site/docs/installation.md +76 -0
  126. data/site/docs/migrations.md +11 -0
  127. data/site/docs/pages.md +86 -0
  128. data/site/docs/pagination.md +211 -0
  129. data/site/docs/permalinks.md +180 -0
  130. data/site/docs/plugins.md +534 -0
  131. data/site/docs/posts.md +181 -0
  132. data/site/docs/quickstart.md +32 -0
  133. data/site/docs/resources.md +46 -0
  134. data/site/docs/sites.md +29 -0
  135. data/site/docs/structure.md +190 -0
  136. data/site/docs/templates.md +339 -0
  137. data/site/docs/troubleshooting.md +150 -0
  138. data/site/docs/upgrading.md +146 -0
  139. data/site/docs/usage.md +63 -0
  140. data/site/docs/variables.md +322 -0
  141. data/site/favicon.png +0 -0
  142. data/site/feed.xml +36 -0
  143. data/site/freenode.txt +1 -0
  144. data/site/img/article-footer.png +0 -0
  145. data/site/img/footer-arrow.png +0 -0
  146. data/site/img/footer-logo.png +0 -0
  147. data/site/img/logo-2x.png +0 -0
  148. data/site/img/octojekyll.png +0 -0
  149. data/site/img/tube.png +0 -0
  150. data/site/img/tube1x.png +0 -0
  151. data/site/index.html +90 -0
  152. data/site/js/modernizr-2.5.3.min.js +4 -0
  153. data/site/news/index.html +10 -0
  154. data/site/news/releases/index.html +10 -0
  155. data/test/fixtures/broken_front_matter1.erb +5 -0
  156. data/test/fixtures/broken_front_matter2.erb +4 -0
  157. data/test/fixtures/broken_front_matter3.erb +7 -0
  158. data/test/fixtures/exploit_front_matter.erb +4 -0
  159. data/test/fixtures/front_matter.erb +4 -0
  160. data/test/helper.rb +65 -0
  161. data/test/source/+/foo.md +7 -0
  162. data/test/source/.htaccess +8 -0
  163. data/test/source/_config.dev.toml +2 -0
  164. data/test/source/_data/languages.yml +2 -0
  165. data/test/source/_data/members.yaml +7 -0
  166. data/test/source/_data/products.yml +1 -0
  167. data/test/source/_includes/params.html +7 -0
  168. data/test/source/_includes/sig.markdown +3 -0
  169. data/test/source/_includes/tmp +1 -0
  170. data/test/source/_layouts/default.html +27 -0
  171. data/test/source/_layouts/post/simple.html +1 -0
  172. data/test/source/_layouts/simple.html +1 -0
  173. data/test/source/_plugins/dummy.rb +8 -0
  174. data/test/source/_posts/2008-02-02-not-published.textile +8 -0
  175. data/test/source/_posts/2008-02-02-published.textile +8 -0
  176. data/test/source/_posts/2008-10-18-foo-bar.textile +8 -0
  177. data/test/source/_posts/2008-11-21-complex.textile +8 -0
  178. data/test/source/_posts/2008-12-03-permalinked-post.textile +9 -0
  179. data/test/source/_posts/2008-12-13-include.markdown +8 -0
  180. data/test/source/_posts/2009-01-27-array-categories.textile +10 -0
  181. data/test/source/_posts/2009-01-27-categories.textile +7 -0
  182. data/test/source/_posts/2009-01-27-category.textile +7 -0
  183. data/test/source/_posts/2009-01-27-empty-categories.textile +7 -0
  184. data/test/source/_posts/2009-01-27-empty-category.textile +7 -0
  185. data/test/source/_posts/2009-03-12-hash-#1.markdown +6 -0
  186. data/test/source/_posts/2009-05-18-empty-tag.textile +6 -0
  187. data/test/source/_posts/2009-05-18-empty-tags.textile +6 -0
  188. data/test/source/_posts/2009-05-18-tag.textile +6 -0
  189. data/test/source/_posts/2009-05-18-tags.textile +9 -0
  190. data/test/source/_posts/2009-06-22-empty-yaml.textile +3 -0
  191. data/test/source/_posts/2009-06-22-no-yaml.textile +1 -0
  192. data/test/source/_posts/2010-01-08-triple-dash.markdown +5 -0
  193. data/test/source/_posts/2010-01-09-date-override.textile +7 -0
  194. data/test/source/_posts/2010-01-09-time-override.textile +7 -0
  195. data/test/source/_posts/2010-01-09-timezone-override.textile +7 -0
  196. data/test/source/_posts/2010-01-16-override-data.textile +4 -0
  197. data/test/source/_posts/2011-04-12-md-extension.md +7 -0
  198. data/test/source/_posts/2011-04-12-text-extension.text +0 -0
  199. data/test/source/_posts/2013-01-02-post-excerpt.markdown +14 -0
  200. data/test/source/_posts/2013-01-12-nil-layout.textile +6 -0
  201. data/test/source/_posts/2013-01-12-no-layout.textile +5 -0
  202. data/test/source/_posts/2013-03-19-not-a-post.markdown/.gitkeep +0 -0
  203. data/test/source/_posts/2013-04-11-custom-excerpt.markdown +10 -0
  204. data/test/source/_posts/2013-05-10-number-category.textile +7 -0
  205. data/test/source/_posts/2013-07-22-post-excerpt-with-layout.markdown +23 -0
  206. data/test/source/_posts/2013-08-01-mkdn-extension.mkdn +0 -0
  207. data/test/source/_posts/2014-01-06-permalink-traversal.md +5 -0
  208. data/test/source/_posts/es/2008-11-21-nested.textile +8 -0
  209. data/test/source/about.html +6 -0
  210. data/test/source/category/_posts/2008-9-23-categories.textile +6 -0
  211. data/test/source/contacts/bar.html +5 -0
  212. data/test/source/contacts/index.html +5 -0
  213. data/test/source/contacts.html +5 -0
  214. data/test/source/css/screen.css +76 -0
  215. data/test/source/deal.with.dots.html +7 -0
  216. data/test/source/exploit.md +5 -0
  217. data/test/source/foo/_posts/bar/2008-12-12-topical-post.textile +8 -0
  218. data/test/source/index.html +22 -0
  219. data/test/source/products.yml +4 -0
  220. data/test/source/sitemap.xml +32 -0
  221. data/test/source/symlink-test/_data +1 -0
  222. data/test/source/symlink-test/symlinked-dir +1 -0
  223. data/test/source/symlink-test/symlinked-file +1 -0
  224. data/test/source/win/_posts/2009-05-24-yaml-linebreak.markdown +7 -0
  225. data/test/source/z_category/_posts/2008-9-23-categories.textile +6 -0
  226. data/test/suite.rb +11 -0
  227. data/test/test_command.rb +39 -0
  228. data/test/test_configuration.rb +181 -0
  229. data/test/test_convertible.rb +51 -0
  230. data/test/test_core_ext.rb +88 -0
  231. data/test/test_entry_filter.rb +74 -0
  232. data/test/test_excerpt.rb +78 -0
  233. data/test/test_filters.rb +113 -0
  234. data/test/test_generated_site.rb +83 -0
  235. data/test/test_kramdown.rb +62 -0
  236. data/test/test_new_command.rb +104 -0
  237. data/test/test_page.rb +212 -0
  238. data/test/test_pager.rb +116 -0
  239. data/test/test_post.rb +592 -0
  240. data/test/test_rdiscount.rb +22 -0
  241. data/test/test_redcarpet.rb +61 -0
  242. data/test/test_redcloth.rb +86 -0
  243. data/test/test_related_posts.rb +47 -0
  244. data/test/test_site.rb +333 -0
  245. data/test/test_tags.rb +490 -0
  246. data/test/test_url.rb +28 -0
  247. data/tigefa.gemspec +306 -0
  248. metadata +575 -45
  249. data/README.md +0 -4
data/test/test_post.rb ADDED
@@ -0,0 +1,592 @@
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(Tigefa).configuration { Tigefa::Configuration::DEFAULTS }
17
+ @site = Site.new(Tigefa.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 Tigefa::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
+ should "not be writable outside of destination" do
79
+ unexpected = File.expand_path("../../../baddie.html", dest_dir)
80
+ File.delete unexpected if File.exist?(unexpected)
81
+ post = setup_post("2014-01-06-permalink-traversal.md")
82
+ do_render(post)
83
+ post.write(dest_dir)
84
+
85
+ assert !File.exist?(unexpected)
86
+ assert File.exist?(File.expand_path("baddie.html", dest_dir))
87
+ end
88
+
89
+ context "with CRLF linebreaks" do
90
+ setup do
91
+ @real_file = "2009-05-24-yaml-linebreak.markdown"
92
+ @source = source_dir('win/_posts')
93
+ end
94
+ should "read yaml front-matter" do
95
+ @post.read_yaml(@source, @real_file)
96
+
97
+ assert_equal({"title" => "Test title", "layout" => "post", "tag" => "Ruby"}, @post.data)
98
+ assert_equal "This is the content", @post.content
99
+ end
100
+ end
101
+
102
+ context "with embedded triple dash" do
103
+ setup do
104
+ @real_file = "2010-01-08-triple-dash.markdown"
105
+ end
106
+ should "consume the embedded dashes" do
107
+ @post.read_yaml(@source, @real_file)
108
+
109
+ assert_equal({"title" => "Foo --- Bar"}, @post.data)
110
+ assert_equal "Triple the fun!", @post.content
111
+ end
112
+ end
113
+
114
+ context "with site wide permalink" do
115
+ setup do
116
+ @post.categories = []
117
+ end
118
+
119
+ context "with unspecified (date) style" do
120
+ setup do
121
+ @post.process(@fake_file)
122
+ end
123
+
124
+ should "process the url correctly" do
125
+ assert_equal "/:categories/:year/:month/:day/:title.html", @post.template
126
+ assert_equal "/2008/09/09/foo-bar.html", @post.url
127
+ end
128
+ end
129
+
130
+ context "with unspecified (date) style and a category" do
131
+ setup do
132
+ @post.categories << "beer"
133
+ @post.process(@fake_file)
134
+ end
135
+
136
+ should "process the url correctly" do
137
+ assert_equal "/:categories/:year/:month/:day/:title.html", @post.template
138
+ assert_equal "/beer/2008/09/09/foo-bar.html", @post.url
139
+ end
140
+ end
141
+
142
+ context "with unspecified (date) style and a numeric category" do
143
+ setup do
144
+ @post.categories << 2013
145
+ @post.process(@fake_file)
146
+ end
147
+
148
+ should "process the url correctly" do
149
+ assert_equal "/:categories/:year/:month/:day/:title.html", @post.template
150
+ assert_equal "/2013/2008/09/09/foo-bar.html", @post.url
151
+ end
152
+ end
153
+
154
+ context "with specified layout of nil" do
155
+ setup do
156
+ file = '2013-01-12-nil-layout.textile'
157
+ @post = setup_post(file)
158
+ @post.process(file)
159
+ end
160
+
161
+ should "layout of nil is respected" do
162
+ assert_equal "nil", @post.data["layout"]
163
+ end
164
+ end
165
+
166
+ context "with unspecified (date) style and categories" do
167
+ setup do
168
+ @post.categories << "food"
169
+ @post.categories << "beer"
170
+ @post.process(@fake_file)
171
+ end
172
+
173
+ should "process the url correctly" do
174
+ assert_equal "/:categories/:year/:month/:day/:title.html", @post.template
175
+ assert_equal "/food/beer/2008/09/09/foo-bar.html", @post.url
176
+ end
177
+ end
178
+
179
+ context "with space (categories)" do
180
+ setup do
181
+ @post.categories << "French cuisine"
182
+ @post.categories << "Belgian beer"
183
+ @post.process(@fake_file)
184
+ end
185
+
186
+ should "process the url correctly" do
187
+ assert_equal "/:categories/:year/:month/:day/:title.html", @post.template
188
+ assert_equal "/French%20cuisine/Belgian%20beer/2008/09/09/foo-bar.html", @post.url
189
+ end
190
+ end
191
+
192
+ context "with none style" do
193
+ setup do
194
+ @post.site.permalink_style = :none
195
+ @post.process(@fake_file)
196
+ end
197
+
198
+ should "process the url correctly" do
199
+ assert_equal "/:categories/:title.html", @post.template
200
+ assert_equal "/foo-bar.html", @post.url
201
+ end
202
+ end
203
+
204
+ context "with pretty style" do
205
+ setup do
206
+ @post.site.permalink_style = :pretty
207
+ @post.process(@fake_file)
208
+ end
209
+
210
+ should "process the url correctly" do
211
+ assert_equal "/:categories/:year/:month/:day/:title/", @post.template
212
+ assert_equal "/2008/09/09/foo-bar/", @post.url
213
+ end
214
+ end
215
+
216
+ context "with ordinal style" do
217
+ setup do
218
+ @post.site.permalink_style = :ordinal
219
+ @post.process(@fake_file)
220
+ end
221
+
222
+ should "process the url correctly" do
223
+ assert_equal "/:categories/:year/:y_day/:title.html", @post.template
224
+ assert_equal "/2008/253/foo-bar.html", @post.url
225
+ end
226
+ end
227
+
228
+ context "with custom date permalink" do
229
+ setup do
230
+ @post.site.permalink_style = '/:categories/:year/:i_month/:i_day/:title/'
231
+ @post.process(@fake_file)
232
+ end
233
+
234
+ should "process the url correctly" do
235
+ assert_equal "/2008/9/9/foo-bar/", @post.url
236
+ end
237
+ end
238
+
239
+ context "with custom abbreviated month date permalink" do
240
+ setup do
241
+ @post.site.permalink_style = '/:categories/:year/:short_month/:day/:title/'
242
+ @post.process(@fake_file)
243
+ end
244
+
245
+ should "process the url correctly" do
246
+ assert_equal "/2008/Sep/09/foo-bar/", @post.url
247
+ end
248
+ end
249
+
250
+ context "with prefix style and no extension" do
251
+ setup do
252
+ @post.site.permalink_style = "/prefix/:title"
253
+ @post.process(@fake_file)
254
+ end
255
+
256
+ should "process the url correctly" do
257
+ assert_equal "/prefix/:title", @post.template
258
+ assert_equal "/prefix/foo-bar", @post.url
259
+ end
260
+ end
261
+ end
262
+
263
+ should "read yaml front-matter" do
264
+ @post.read_yaml(@source, @real_file)
265
+
266
+ assert_equal({"title" => "Foo Bar", "layout" => "default"}, @post.data)
267
+ assert_equal "h1. {{ page.title }}\n\nBest *post* ever", @post.content
268
+ end
269
+
270
+ should "transform textile" do
271
+ @post.process(@real_file)
272
+ @post.read_yaml(@source, @real_file)
273
+ @post.transform
274
+
275
+ assert_equal "<h1>{{ page.title }}</h1>\n<p>Best <strong>post</strong> ever</p>", @post.content
276
+ end
277
+
278
+ context "#excerpt" do
279
+ setup do
280
+ file = "2013-01-02-post-excerpt.markdown"
281
+ @post = setup_post(file)
282
+ @post.process(file)
283
+ @post.read_yaml(@source, file)
284
+ do_render(@post)
285
+ end
286
+
287
+ should "return first paragraph by default" do
288
+ assert @post.excerpt.include?("First paragraph"), "contains first paragraph"
289
+ assert !@post.excerpt.include?("Second paragraph"), "does not contains second paragraph"
290
+ assert !@post.excerpt.include?("Third paragraph"), "does not contains third paragraph"
291
+ end
292
+
293
+ should "correctly resolve link references" do
294
+ assert @post.excerpt.include?("www.jekyllrb.com"), "contains referenced link URL"
295
+ end
296
+
297
+ should "return rendered HTML" do
298
+ assert_equal "<p>First paragraph with <a href=\"http://www.jekyllrb.com/\">link ref</a>.</p>",
299
+ @post.excerpt
300
+ end
301
+
302
+ context "with excerpt_separator setting" do
303
+ setup do
304
+ file = "2013-01-02-post-excerpt.markdown"
305
+
306
+ @post.site.config['excerpt_separator'] = "\n---\n"
307
+
308
+ @post.process(file)
309
+ @post.read_yaml(@source, file)
310
+ @post.transform
311
+ end
312
+
313
+ should "respect given separator" do
314
+ assert @post.excerpt.include?("First paragraph"), "contains first paragraph"
315
+ assert @post.excerpt.include?("Second paragraph"), "contains second paragraph"
316
+ assert !@post.excerpt.include?("Third paragraph"), "does not contains third paragraph"
317
+ end
318
+
319
+ should "replace separator with new-lines" do
320
+ assert !@post.excerpt.include?("---"), "does not contains separator"
321
+ end
322
+ end
323
+
324
+ context "with custom excerpt" do
325
+ setup do
326
+ file = "2013-04-11-custom-excerpt.markdown"
327
+ @post = setup_post(file)
328
+ do_render(@post)
329
+ end
330
+
331
+ should "use custom excerpt" do
332
+ assert_equal("I can set a custom excerpt", @post.excerpt)
333
+ end
334
+
335
+ should "expose custom excerpt to liquid" do
336
+ assert @post.content.include?("I can use the excerpt: <quote>I can set a custom excerpt</quote>"), "Exposes incorrect excerpt to liquid."
337
+ end
338
+
339
+ end
340
+
341
+ end
342
+ end
343
+
344
+ context "when in a site" do
345
+ setup do
346
+ clear_dest
347
+ stub(Tigefa).configuration { Tigefa::Configuration::DEFAULTS }
348
+ @site = Site.new(Tigefa.configuration)
349
+ @site.posts = [setup_post('2008-02-02-published.textile'),
350
+ setup_post('2009-01-27-categories.textile')]
351
+ end
352
+
353
+ should "have next post" do
354
+ assert_equal(@site.posts.last, @site.posts.first.next)
355
+ end
356
+
357
+ should "have previous post" do
358
+ assert_equal(@site.posts.first, @site.posts.last.previous)
359
+ end
360
+
361
+ should "not have previous post if first" do
362
+ assert_equal(nil, @site.posts.first.previous)
363
+ end
364
+
365
+ should "not have next post if last" do
366
+ assert_equal(nil, @site.posts.last.next)
367
+ end
368
+ end
369
+
370
+ context "initializing posts" do
371
+ should "publish when published yaml is no specified" do
372
+ post = setup_post("2008-02-02-published.textile")
373
+ assert_equal true, post.published
374
+ end
375
+
376
+ should "not published when published yaml is false" do
377
+ post = setup_post("2008-02-02-not-published.textile")
378
+ assert_equal false, post.published
379
+ end
380
+
381
+ should "recognize date in yaml" do
382
+ post = setup_post("2010-01-09-date-override.textile")
383
+ do_render(post)
384
+ assert_equal Time, post.date.class
385
+ assert_equal Time, post.to_liquid["date"].class
386
+ assert_equal "/2010/01/10/date-override.html", post.url
387
+ assert_equal "<p>Post with a front matter date</p>\n<p>10 Jan 2010</p>", post.output
388
+ end
389
+
390
+ should "recognize time in yaml" do
391
+ post = setup_post("2010-01-09-time-override.textile")
392
+ do_render(post)
393
+ assert_equal Time, post.date.class
394
+ assert_equal Time, post.to_liquid["date"].class
395
+ assert_equal "/2010/01/10/time-override.html", post.url
396
+ assert_equal "<p>Post with a front matter time</p>\n<p>10 Jan 2010</p>", post.output
397
+ end
398
+
399
+ should "recognize time with timezone in yaml" do
400
+ post = setup_post("2010-01-09-timezone-override.textile")
401
+ do_render(post)
402
+ assert_equal Time, post.date.class
403
+ assert_equal Time, post.to_liquid["date"].class
404
+ assert_equal "/2010/01/10/timezone-override.html", post.url
405
+ assert_equal "<p>Post with a front matter time with timezone</p>\n<p>10 Jan 2010</p>", post.output
406
+ end
407
+
408
+ should "to_liquid prioritizes post attributes over data" do
409
+ post = setup_post("2010-01-16-override-data.textile")
410
+ assert_equal Array, post.tags.class
411
+ assert_equal Array, post.to_liquid["tags"].class
412
+ assert_equal Time, post.date.class
413
+ assert_equal Time, post.to_liquid["date"].class
414
+ end
415
+
416
+ should "recognize category in yaml" do
417
+ post = setup_post("2009-01-27-category.textile")
418
+ assert post.categories.include?('foo')
419
+ end
420
+
421
+ should "recognize several categories in yaml" do
422
+ post = setup_post("2009-01-27-categories.textile")
423
+ assert post.categories.include?('foo')
424
+ assert post.categories.include?('bar')
425
+ assert post.categories.include?('baz')
426
+ end
427
+
428
+ should "recognize empty category in yaml" do
429
+ post = setup_post("2009-01-27-empty-category.textile")
430
+ assert_equal [], post.categories
431
+ end
432
+
433
+ should "recognize empty categories in yaml" do
434
+ post = setup_post("2009-01-27-empty-categories.textile")
435
+ assert_equal [], post.categories
436
+ end
437
+
438
+ should "recognize number category in yaml" do
439
+ post = setup_post("2013-05-10-number-category.textile")
440
+ assert post.categories.include?('2013')
441
+ assert !post.categories.include?(2013)
442
+ end
443
+
444
+ should "recognize tag in yaml" do
445
+ post = setup_post("2009-05-18-tag.textile")
446
+ assert post.tags.include?('code')
447
+ end
448
+
449
+ should "recognize tags in yaml" do
450
+ post = setup_post("2009-05-18-tags.textile")
451
+ assert post.tags.include?('food')
452
+ assert post.tags.include?('cooking')
453
+ assert post.tags.include?('pizza')
454
+ end
455
+
456
+ should "recognize empty tag in yaml" do
457
+ post = setup_post("2009-05-18-empty-tag.textile")
458
+ assert_equal [], post.tags
459
+ end
460
+
461
+ should "recognize empty tags in yaml" do
462
+ post = setup_post("2009-05-18-empty-tags.textile")
463
+ assert_equal [], post.tags
464
+ end
465
+
466
+ should "allow no yaml" do
467
+ post = setup_post("2009-06-22-no-yaml.textile")
468
+ assert_equal "No YAML.", post.content
469
+ end
470
+
471
+ should "allow empty yaml" do
472
+ post = setup_post("2009-06-22-empty-yaml.textile")
473
+ assert_equal "Empty YAML.", post.content
474
+ end
475
+
476
+ context "rendering" do
477
+ setup do
478
+ clear_dest
479
+ end
480
+
481
+ should "render properly" do
482
+ post = setup_post("2008-10-18-foo-bar.textile")
483
+ do_render(post)
484
+ assert_equal "<<< <h1>Foo Bar</h1>\n<p>Best <strong>post</strong> ever</p> >>>", post.output
485
+ end
486
+
487
+ should "write properly" do
488
+ post = setup_post("2008-10-18-foo-bar.textile")
489
+ do_render(post)
490
+ post.write(dest_dir)
491
+
492
+ assert File.directory?(dest_dir)
493
+ assert File.exists?(File.join(dest_dir, '2008', '10', '18', 'foo-bar.html'))
494
+ end
495
+
496
+ should "write properly without html extension" do
497
+ post = setup_post("2008-10-18-foo-bar.textile")
498
+ post.site.permalink_style = ":title"
499
+ do_render(post)
500
+ post.write(dest_dir)
501
+
502
+ assert File.directory?(dest_dir)
503
+ assert File.exists?(File.join(dest_dir, 'foo-bar', 'index.html'))
504
+ end
505
+
506
+ should "insert data" do
507
+ post = setup_post("2008-11-21-complex.textile")
508
+ do_render(post)
509
+
510
+ 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
511
+ end
512
+
513
+ should "include templates" do
514
+ post = setup_post("2008-12-13-include.markdown")
515
+ post.site.source = File.join(File.dirname(__FILE__), 'source')
516
+ do_render(post)
517
+
518
+ assert_equal "<<< <hr />\n<p>Tom Preston-Werner github.com/mojombo</p>\n\n<p>This <em>is</em> cool</p> >>>", post.output
519
+ end
520
+
521
+ should "render date specified in front matter properly" do
522
+ post = setup_post("2010-01-09-date-override.textile")
523
+ do_render(post)
524
+
525
+ assert_equal "<p>Post with a front matter date</p>\n<p>10 Jan 2010</p>", post.output
526
+ end
527
+
528
+ should "render time specified in front matter properly" do
529
+ post = setup_post("2010-01-09-time-override.textile")
530
+ do_render(post)
531
+
532
+ assert_equal "<p>Post with a front matter time</p>\n<p>10 Jan 2010</p>", post.output
533
+ end
534
+
535
+ end
536
+ end
537
+
538
+ should "generate categories and topics" do
539
+ post = Post.new(@site, File.join(File.dirname(__FILE__), *%w[source]), 'foo', 'bar/2008-12-12-topical-post.textile')
540
+ assert_equal ['foo'], post.categories
541
+ end
542
+ end
543
+
544
+ context "converter file extension settings" do
545
+ setup do
546
+ stub(Tigefa).configuration { Tigefa::Configuration::DEFAULTS }
547
+ @site = Site.new(Tigefa.configuration)
548
+ end
549
+
550
+ should "process .md as markdown under default configuration" do
551
+ post = setup_post '2011-04-12-md-extension.md'
552
+ conv = post.converter
553
+ assert conv.kind_of? Tigefa::Converters::Markdown
554
+ end
555
+
556
+ should "process .text as identity under default configuration" do
557
+ post = setup_post '2011-04-12-text-extension.text'
558
+ conv = post.converter
559
+ assert conv.kind_of? Tigefa::Converters::Identity
560
+ end
561
+
562
+ should "process .text as markdown under alternate configuration" do
563
+ @site.config['markdown_ext'] = 'markdown,mdw,mdwn,md,text'
564
+ post = setup_post '2011-04-12-text-extension.text'
565
+ conv = post.converter
566
+ assert conv.kind_of? Tigefa::Converters::Markdown
567
+ end
568
+
569
+ should "process .md as markdown under alternate configuration" do
570
+ @site.config['markdown_ext'] = 'markdown,mkd,mkdn,md,text'
571
+ post = setup_post '2011-04-12-text-extension.text'
572
+ conv = post.converter
573
+ assert conv.kind_of? Tigefa::Converters::Markdown
574
+ end
575
+
576
+ should "process .mkdn under text if it is not in the markdown config" do
577
+ @site.config['markdown_ext'] = 'markdown,mkd,md,text'
578
+ post = setup_post '2013-08-01-mkdn-extension.mkdn'
579
+ conv = post.converter
580
+ assert conv.kind_of? Tigefa::Converters::Identity
581
+ end
582
+
583
+ should "process .text as textile under alternate configuration" do
584
+ @site.config['textile_ext'] = 'textile,text'
585
+ post = setup_post '2011-04-12-text-extension.text'
586
+ conv = post.converter
587
+ assert conv.kind_of? Tigefa::Converters::Textile
588
+ end
589
+
590
+ end
591
+
592
+ end
@@ -0,0 +1,22 @@
1
+ require 'helper'
2
+
3
+ class TestRdiscount < Test::Unit::TestCase
4
+
5
+ context "rdiscount" do
6
+ setup do
7
+ config = {
8
+ 'markdown' => 'rdiscount',
9
+ 'rdiscount' => { 'extensions' => ['smart', 'generate_toc'], 'toc_token' => '{:toc}' }
10
+ }
11
+ @markdown = Converters::Markdown.new config
12
+ end
13
+
14
+ should "pass rdiscount extensions" do
15
+ assert_equal "<p>&ldquo;smart&rdquo;</p>", @markdown.convert('"smart"').strip
16
+ end
17
+
18
+ should "render toc" do
19
+ assert_equal "<h1 id=\"Header+1\">Header 1</h1>\n\n<h2 id=\"Header+2\">Header 2</h2>\n\n<p>\n <ul>\n <li><a href=\"#Header+1\">Header 1</a>\n <ul>\n <li><a href=\"#Header+2\">Header 2</a> </li>\n </ul>\n </li>\n </ul>\n\n</p>", @markdown.convert("# Header 1\n\n## Header 2\n\n{:toc}").strip
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,61 @@
1
+ require 'helper'
2
+
3
+ class TestRedcarpet < Test::Unit::TestCase
4
+ context "redcarpet" do
5
+ setup do
6
+ @config = {
7
+ 'redcarpet' => { 'extensions' => ['smart', 'strikethrough', 'filter_html'] },
8
+ 'markdown' => 'redcarpet'
9
+ }
10
+ @markdown = Converters::Markdown.new @config
11
+ end
12
+
13
+ should "pass redcarpet options" do
14
+ assert_equal "<h1>Some Header</h1>", @markdown.convert('# Some Header #').strip
15
+ end
16
+
17
+ should "pass redcarpet SmartyPants options" do
18
+ assert_equal "<p>&ldquo;smart&rdquo;</p>", @markdown.convert('"smart"').strip
19
+ end
20
+
21
+ should "pass redcarpet extensions" do
22
+ assert_equal "<p><del>deleted</del></p>", @markdown.convert('~~deleted~~').strip
23
+ end
24
+
25
+ should "pass redcarpet render options" do
26
+ assert_equal "<p><strong>bad code not here</strong>: i am bad</p>", @markdown.convert('**bad code not here**: <script>i am bad</script>').strip
27
+ end
28
+
29
+ context "with pygments enabled" do
30
+ setup do
31
+ @markdown = Converters::Markdown.new @config.merge({ 'pygments' => true })
32
+ end
33
+
34
+ should "render fenced code blocks with syntax highlighting" do
35
+ assert_equal "<div class=\"highlight\"><pre><code class=\"ruby language-ruby\" data-lang=\"ruby\"><span class=\"nb\">puts</span> <span class=\"s2\">&quot;Hello world&quot;</span>\n</code></pre></div>", @markdown.convert(
36
+ <<-EOS
37
+ ```ruby
38
+ puts "Hello world"
39
+ ```
40
+ EOS
41
+ ).strip
42
+ end
43
+ end
44
+
45
+ context "with pygments disabled" do
46
+ setup do
47
+ @markdown = Converters::Markdown.new @config.merge({ 'pygments' => false })
48
+ end
49
+
50
+ should "render fenced code blocks without syntax highlighting" do
51
+ assert_equal "<div class=\"highlight\"><pre><code class=\"ruby language-ruby\" data-lang=\"ruby\">puts &quot;Hello world&quot;\n</code></pre></div>", @markdown.convert(
52
+ <<-EOS
53
+ ```ruby
54
+ puts "Hello world"
55
+ ```
56
+ EOS
57
+ ).strip
58
+ end
59
+ end
60
+ end
61
+ end