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
@@ -0,0 +1,181 @@
1
+ require 'helper'
2
+
3
+ class TestConfiguration < Test::Unit::TestCase
4
+ context "#stringify_keys" do
5
+ setup do
6
+ @mixed_keys = Configuration[{
7
+ 'markdown' => 'maruku',
8
+ :permalink => 'date',
9
+ 'baseurl' => '/',
10
+ :include => ['.htaccess'],
11
+ :source => './'
12
+ }]
13
+ @string_keys = Configuration[{
14
+ 'markdown' => 'maruku',
15
+ 'permalink' => 'date',
16
+ 'baseurl' => '/',
17
+ 'include' => ['.htaccess'],
18
+ 'source' => './'
19
+ }]
20
+ end
21
+ should "stringify symbol keys" do
22
+ assert_equal @string_keys, @mixed_keys.stringify_keys
23
+ end
24
+ should "not mess with keys already strings" do
25
+ assert_equal @string_keys, @string_keys.stringify_keys
26
+ end
27
+ end
28
+ context "#config_files" do
29
+ setup do
30
+ @config = Configuration[{"source" => source_dir}]
31
+ @no_override = {}
32
+ @one_config_file = {"config" => "config.yml"}
33
+ @multiple_files = {"config" => %w[config/site.yml config/deploy.toml configuration.yml]}
34
+ end
35
+
36
+ should "always return an array" do
37
+ assert @config.config_files(@no_override).is_a?(Array)
38
+ assert @config.config_files(@one_config_file).is_a?(Array)
39
+ assert @config.config_files(@multiple_files).is_a?(Array)
40
+ end
41
+ should "return the default config path if no config files are specified" do
42
+ assert_equal [File.join(source_dir, "_config.yml")], @config.config_files(@no_override)
43
+ end
44
+ should "return the config if given one config file" do
45
+ assert_equal %w[config.yml], @config.config_files(@one_config_file)
46
+ end
47
+ should "return an array of the config files if given many config files" do
48
+ assert_equal %w[config/site.yml config/deploy.toml configuration.yml], @config.config_files(@multiple_files)
49
+ end
50
+ end
51
+ context "#backwards_compatibilize" do
52
+ setup do
53
+ @config = Configuration[{
54
+ "auto" => true,
55
+ "watch" => true,
56
+ "server" => true,
57
+ "exclude" => "READ-ME.md, Gemfile,CONTRIBUTING.hello.markdown",
58
+ "include" => "STOP_THE_PRESSES.txt,.heloses, .git"
59
+ }]
60
+ end
61
+ should "unset 'auto' and 'watch'" do
62
+ assert @config.has_key?("auto")
63
+ assert @config.has_key?("watch")
64
+ assert !@config.backwards_compatibilize.has_key?("auto")
65
+ assert !@config.backwards_compatibilize.has_key?("watch")
66
+ end
67
+ should "unset 'server'" do
68
+ assert @config.has_key?("server")
69
+ assert !@config.backwards_compatibilize.has_key?("server")
70
+ end
71
+ should "transform string exclude into an array" do
72
+ assert @config.has_key?("exclude")
73
+ assert @config.backwards_compatibilize.has_key?("exclude")
74
+ assert_equal @config.backwards_compatibilize["exclude"], %w[READ-ME.md Gemfile CONTRIBUTING.hello.markdown]
75
+ end
76
+ should "transform string include into an array" do
77
+ assert @config.has_key?("include")
78
+ assert @config.backwards_compatibilize.has_key?("include")
79
+ assert_equal @config.backwards_compatibilize["include"], %w[STOP_THE_PRESSES.txt .heloses .git]
80
+ end
81
+ end
82
+ context "#fix_common_issues" do
83
+ setup do
84
+ @config = Proc.new do |val|
85
+ Configuration[{
86
+ 'paginate' => val
87
+ }]
88
+ end
89
+ end
90
+ should "sets an invalid 'paginate' value to nil" do
91
+ assert_nil @config.call(0).fix_common_issues['paginate']
92
+ assert_nil @config.call(-1).fix_common_issues['paginate']
93
+ assert_nil @config.call(true).fix_common_issues['paginate']
94
+ end
95
+ end
96
+ context "loading configuration" do
97
+ setup do
98
+ @path = File.join(Dir.pwd, '_config.yml')
99
+ @user_config = File.join(Dir.pwd, "my_config_file.yml")
100
+ end
101
+
102
+ should "fire warning with no _config.yml" do
103
+ mock(YAML).safe_load_file(@path) { raise SystemCallError, "No such file or directory - #{@path}" }
104
+ mock($stderr).puts("Configuration file: none".yellow)
105
+ assert_equal Tigefa::Configuration::DEFAULTS, TigefaTigefa.configuration({})
106
+ end
107
+
108
+ should "load configuration as hash" do
109
+ mock(YAML).safe_load_file(@path) { Hash.new }
110
+ mock($stdout).puts("Configuration file: #{@path}")
111
+ assert_equal TigefaTigefa::Configuration::DEFAULTS, TigefaTigefa.configuration({})
112
+ end
113
+
114
+ should "fire warning with bad config" do
115
+ mock(YAML).safe_load_file(@path) { Array.new }
116
+ mock($stderr).puts(("WARNING: ".rjust(20) + "Error reading configuration. Using defaults (and options).").yellow)
117
+ mock($stderr).puts("Configuration file: (INVALID) #{@path}".yellow)
118
+ assert_equal TigefaTigefa::Configuration::DEFAULTS, TigefaTigefa.configuration({})
119
+ end
120
+
121
+ should "fire warning when user-specified config file isn't there" do
122
+ mock(YAML).safe_load_file(@user_config) { raise SystemCallError, "No such file or directory - #{@user_config}" }
123
+ mock($stderr).puts(("Fatal: ".rjust(20) + "The configuration file '#{@user_config}' could not be found.").red)
124
+ assert_raises LoadError do
125
+ TigefaTigefa.configuration({'config' => [@user_config]})
126
+ end
127
+ end
128
+ end
129
+ context "loading config from external file" do
130
+ setup do
131
+ @paths = {
132
+ :default => File.join(Dir.pwd, '_config.yml'),
133
+ :other => File.join(Dir.pwd, '_config.live.yml'),
134
+ :toml => source_dir('_config.dev.toml'),
135
+ :empty => ""
136
+ }
137
+ end
138
+
139
+ should "load default config if no config_file is set" do
140
+ mock(YAML).safe_load_file(@paths[:default]) { Hash.new }
141
+ mock($stdout).puts("Configuration file: #{@paths[:default]}")
142
+ assert_equal Tigefa::Configuration::DEFAULTS, Tigefa.configuration({})
143
+ end
144
+
145
+ should "load different config if specified" do
146
+ mock(YAML).safe_load_file(@paths[:other]) { {"baseurl" => "http://wahoo.dev"} }
147
+ mock($stdout).puts("Configuration file: #{@paths[:other]}")
148
+ assert_equal Tigefa::Configuration::DEFAULTS.deep_merge({ "baseurl" => "http://wahoo.dev" }), Tigefa.configuration({ "config" => @paths[:other] })
149
+ end
150
+
151
+ should "load default config if path passed is empty" do
152
+ mock(YAML).safe_load_file(@paths[:default]) { Hash.new }
153
+ mock($stdout).puts("Configuration file: #{@paths[:default]}")
154
+ assert_equal Tigefa::Configuration::DEFAULTS, Tigefa.configuration({ "config" => @paths[:empty] })
155
+ end
156
+
157
+ should "successfully load a TOML file" do
158
+ Tigefa.logger.log_level = Tigefa::Stevenson::WARN
159
+ assert_equal Tigefa::Configuration::DEFAULTS.merge({ "baseurl" => "/you-beautiful-blog-you", "title" => "My magnificent site, wut" }), Tigefa.configuration({ "config" => [@paths[:toml]] })
160
+ Tigefa.logger.log_level = Tigefa::Stevenson::INFO
161
+ end
162
+
163
+ should "load multiple config files" do
164
+ mock(YAML).safe_load_file(@paths[:default]) { Hash.new }
165
+ mock(YAML).safe_load_file(@paths[:other]) { Hash.new }
166
+ mock(TOML).load_file(@paths[:toml]) { Hash.new }
167
+ mock($stdout).puts("Configuration file: #{@paths[:default]}")
168
+ mock($stdout).puts("Configuration file: #{@paths[:other]}")
169
+ mock($stdout).puts("Configuration file: #{@paths[:toml]}")
170
+ assert_equal Tigefa::Configuration::DEFAULTS, Tigefa.configuration({ "config" => [@paths[:default], @paths[:other], @paths[:toml]] })
171
+ end
172
+
173
+ should "load multiple config files and last config should win" do
174
+ mock(YAML).safe_load_file(@paths[:default]) { {"baseurl" => "http://example.dev"} }
175
+ mock(YAML).safe_load_file(@paths[:other]) { {"baseurl" => "http://wahoo.dev"} }
176
+ mock($stdout).puts("Configuration file: #{@paths[:default]}")
177
+ mock($stdout).puts("Configuration file: #{@paths[:other]}")
178
+ assert_equal Tigefa::Configuration::DEFAULTS.deep_merge({ "baseurl" => "http://wahoo.dev" }), Tigefa.configuration({ "config" => [@paths[:default], @paths[:other]] })
179
+ end
180
+ end
181
+ end
@@ -0,0 +1,51 @@
1
+ require 'helper'
2
+ require 'ostruct'
3
+
4
+ class TestConvertible < Test::Unit::TestCase
5
+ context "yaml front-matter" do
6
+ setup do
7
+ @convertible = OpenStruct.new
8
+ @convertible.extend Tigefa::Convertible
9
+ @base = File.expand_path('../fixtures', __FILE__)
10
+ end
11
+
12
+ should "parse the front-matter correctly" do
13
+ ret = @convertible.read_yaml(@base, 'front_matter.erb')
14
+ assert_equal({'test' => 'good'}, ret)
15
+ end
16
+
17
+ should "not parse if the front-matter is not at the start of the file" do
18
+ ret = @convertible.read_yaml(@base, 'broken_front_matter1.erb')
19
+ assert_equal({}, ret)
20
+ end
21
+
22
+ should "not parse if there is syntax error in front-matter" do
23
+ name = 'broken_front_matter2.erb'
24
+ out = capture_stdout do
25
+ ret = @convertible.read_yaml(@base, name)
26
+ assert_equal({}, ret)
27
+ end
28
+ assert_match(/YAML Exception|syntax error|Error reading file/, out)
29
+ assert_match(/#{File.join(@base, name)}/, out)
30
+ end
31
+
32
+ should "not allow ruby objects in yaml" do
33
+ out = capture_stdout do
34
+ @convertible.read_yaml(@base, 'exploit_front_matter.erb')
35
+ end
36
+ assert_no_match /undefined class\/module DoesNotExist/, out
37
+ end
38
+
39
+ if RUBY_VERSION >= '1.9.2'
40
+ should "not parse if there is encoding error in file" do
41
+ name = 'broken_front_matter3.erb'
42
+ out = capture_stdout do
43
+ ret = @convertible.read_yaml(@base, name, :encoding => 'utf-8')
44
+ assert_equal({}, ret)
45
+ end
46
+ assert_match(/invalid byte sequence in UTF-8/, out)
47
+ assert_match(/#{File.join(@base, name)}/, out)
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,88 @@
1
+ require 'helper'
2
+
3
+ class TestCoreExt < Test::Unit::TestCase
4
+ context "hash" do
5
+
6
+ context "pluralized_array" do
7
+
8
+ should "return empty array with no values" do
9
+ data = {}
10
+ assert_equal [], data.pluralized_array('tag', 'tags')
11
+ end
12
+
13
+ should "return empty array with no matching values" do
14
+ data = { 'foo' => 'bar' }
15
+ assert_equal [], data.pluralized_array('tag', 'tags')
16
+ end
17
+
18
+ should "return empty array with matching nil singular" do
19
+ data = { 'foo' => 'bar', 'tag' => nil, 'tags' => ['dog', 'cat'] }
20
+ assert_equal [], data.pluralized_array('tag', 'tags')
21
+ end
22
+
23
+ should "return single value array with matching singular" do
24
+ data = { 'foo' => 'bar', 'tag' => 'dog', 'tags' => ['dog', 'cat'] }
25
+ assert_equal ['dog'], data.pluralized_array('tag', 'tags')
26
+ end
27
+
28
+ should "return single value array with matching singular with spaces" do
29
+ data = { 'foo' => 'bar', 'tag' => 'dog cat', 'tags' => ['dog', 'cat'] }
30
+ assert_equal ['dog cat'], data.pluralized_array('tag', 'tags')
31
+ end
32
+
33
+ should "return empty array with matching nil plural" do
34
+ data = { 'foo' => 'bar', 'tags' => nil }
35
+ assert_equal [], data.pluralized_array('tag', 'tags')
36
+ end
37
+
38
+ should "return empty array with matching empty array" do
39
+ data = { 'foo' => 'bar', 'tags' => [] }
40
+ assert_equal [], data.pluralized_array('tag', 'tags')
41
+ end
42
+
43
+ should "return single value array with matching plural with single string value" do
44
+ data = { 'foo' => 'bar', 'tags' => 'dog' }
45
+ assert_equal ['dog'], data.pluralized_array('tag', 'tags')
46
+ end
47
+
48
+ should "return multiple value array with matching plural with single string value with spaces" do
49
+ data = { 'foo' => 'bar', 'tags' => 'dog cat' }
50
+ assert_equal ['dog', 'cat'], data.pluralized_array('tag', 'tags')
51
+ end
52
+
53
+ should "return single value array with matching plural with single value array" do
54
+ data = { 'foo' => 'bar', 'tags' => ['dog'] }
55
+ assert_equal ['dog'], data.pluralized_array('tag', 'tags')
56
+ end
57
+
58
+ should "return multiple value array with matching plural with multiple value array" do
59
+ data = { 'foo' => 'bar', 'tags' => ['dog', 'cat'] }
60
+ assert_equal ['dog', 'cat'], data.pluralized_array('tag', 'tags')
61
+ end
62
+
63
+ end
64
+
65
+ end
66
+
67
+ context "enumerable" do
68
+ context "glob_include?" do
69
+ should "return false with no glob patterns" do
70
+ assert ![].glob_include?("a.txt")
71
+ end
72
+
73
+ should "return false with all not match path" do
74
+ data = ["a*", "b?"]
75
+ assert !data.glob_include?("ca.txt")
76
+ assert !data.glob_include?("ba.txt")
77
+ end
78
+
79
+ should "return true with match path" do
80
+ data = ["a*", "b?", "**/a*"]
81
+ assert data.glob_include?("a.txt")
82
+ assert data.glob_include?("ba")
83
+ assert data.glob_include?("c/a/a.txt")
84
+ assert data.glob_include?("c/a/b/a.txt")
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,74 @@
1
+ require 'helper'
2
+
3
+ class TestEntryFilter < Test::Unit::TestCase
4
+ context "Filtering entries" do
5
+ setup do
6
+ stub(Tigefa).configuration do
7
+ Tigefa::Configuration::DEFAULTS.merge({'source' => source_dir, 'destination' => dest_dir})
8
+ end
9
+ @site = Site.new(Tigefa.configuration)
10
+ end
11
+
12
+ should "filter entries" do
13
+ ent1 = %w[foo.markdown bar.markdown baz.markdown #baz.markdown#
14
+ .baz.markdow foo.markdown~ .htaccess _posts _pages]
15
+
16
+ entries = EntryFilter.new(@site).filter(ent1)
17
+ assert_equal %w[foo.markdown bar.markdown baz.markdown .htaccess], entries
18
+ end
19
+
20
+ should "filter entries with exclude" do
21
+ excludes = %w[README TODO]
22
+ files = %w[index.html site.css .htaccess]
23
+
24
+ @site.exclude = excludes + ["exclude*"]
25
+ assert_equal files, @site.filter_entries(excludes + files + ["excludeA"])
26
+ end
27
+
28
+ should "not filter entries within include" do
29
+ includes = %w[_index.html .htaccess include*]
30
+ files = %w[index.html _index.html .htaccess includeA]
31
+
32
+ @site.include = includes
33
+ assert_equal files, @site.filter_entries(files)
34
+ end
35
+
36
+ should "filter symlink entries when safe mode enabled" do
37
+ stub(Tigefa).configuration do
38
+ Tigefa::Configuration::DEFAULTS.merge({'source' => source_dir, 'destination' => dest_dir, 'safe' => true})
39
+ end
40
+ site = Site.new(Tigefa.configuration)
41
+ stub(File).symlink?('symlink.js') {true}
42
+ files = %w[symlink.js]
43
+ assert_equal [], site.filter_entries(files)
44
+ end
45
+
46
+ should "not filter symlink entries when safe mode disabled" do
47
+ stub(File).symlink?('symlink.js') {true}
48
+ files = %w[symlink.js]
49
+ assert_equal files, @site.filter_entries(files)
50
+ end
51
+
52
+ should "not include symlinks in safe mode" do
53
+ stub(Tigefa).configuration do
54
+ Tigefa::Configuration::DEFAULTS.merge({'source' => source_dir, 'destination' => dest_dir, 'safe' => true})
55
+ end
56
+ site = Site.new(Tigefa.configuration)
57
+
58
+ site.read_directories("symlink-test")
59
+ assert_equal [], site.pages
60
+ assert_equal [], site.static_files
61
+ end
62
+
63
+ should "include symlinks in unsafe mode" do
64
+ stub(Tigefa).configuration do
65
+ Tigefa::Configuration::DEFAULTS.merge({'source' => source_dir, 'destination' => dest_dir, 'safe' => false})
66
+ end
67
+ site = Site.new(Tigefa.configuration)
68
+
69
+ site.read_directories("symlink-test")
70
+ assert_not_equal [], site.pages
71
+ assert_not_equal [], site.static_files
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,78 @@
1
+ require 'helper'
2
+
3
+ class TestExcerpt < 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 "With extraction disabled" do
14
+ setup do
15
+ clear_dest
16
+ stub(Tigefa).configuration do
17
+ Tigefa::Configuration::DEFAULTS.merge({'excerpt_separator' => ''})
18
+ end
19
+ @site = Site.new(Tigefa.configuration)
20
+ @post = setup_post("2013-07-22-post-excerpt-with-layout.markdown")
21
+ end
22
+
23
+ should "not be generated" do
24
+ excerpt = @post.send(:extract_excerpt)
25
+ assert_equal true, excerpt.empty?
26
+ end
27
+ end
28
+
29
+ context "An extracted excerpt" do
30
+ setup do
31
+ clear_dest
32
+ stub(Tigefa).configuration { Tigefa::Configuration::DEFAULTS }
33
+ @site = Site.new(Tigefa.configuration)
34
+ @post = setup_post("2013-07-22-post-excerpt-with-layout.markdown")
35
+ @excerpt = @post.send :extract_excerpt
36
+ end
37
+
38
+ context "#to_liquid" do
39
+ should "contain the proper page data to mimick the post liquid" do
40
+ assert_equal "Post Excerpt with Layout", @excerpt.to_liquid["title"]
41
+ assert_equal "/bar/baz/z_category/2013/07/22/post-excerpt-with-layout.html", @excerpt.to_liquid["url"]
42
+ assert_equal Time.parse("2013-07-22"), @excerpt.to_liquid["date"]
43
+ assert_equal %w[bar baz z_category], @excerpt.to_liquid["categories"]
44
+ assert_equal %w[first second third jekyllrb.com], @excerpt.to_liquid["tags"]
45
+ assert_equal "_posts/2013-07-22-post-excerpt-with-layout.markdown", @excerpt.to_liquid["path"]
46
+ end
47
+ end
48
+
49
+ context "#content" do
50
+
51
+ context "before render" do
52
+ should "be the first paragraph of the page" do
53
+ assert_equal "First paragraph with [link ref][link].\n\n[link]: http://www.jekyllrb.com/", @excerpt.content
54
+ end
55
+
56
+ should "contain any refs at the bottom of the page" do
57
+ assert @excerpt.content.include?("[link]: http://www.jekyllrb.com/")
58
+ end
59
+ end
60
+
61
+ context "after render" do
62
+ setup do
63
+ @rendered_post = @post.dup
64
+ do_render(@rendered_post)
65
+ @extracted_excerpt = @rendered_post.send :extracted_excerpt
66
+ end
67
+
68
+ should "be the first paragraph of the page" do
69
+ assert_equal "<p>First paragraph with <a href=\"http://www.jekyllrb.com/\">link ref</a>.</p>", @extracted_excerpt.content
70
+ end
71
+
72
+ should "link properly" do
73
+ assert @extracted_excerpt.content.include?("http://www.jekyllrb.com/")
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,113 @@
1
+ require 'helper'
2
+
3
+ class TestFilters < Test::Unit::TestCase
4
+ class JekyllFilter
5
+ include Tigefa::Filters
6
+
7
+ def initialize
8
+ site = Tigefa::Site.new(Tigefa.configuration({}))
9
+ @context = Liquid::Context.new({}, {}, { :site => site })
10
+ end
11
+ end
12
+
13
+ context "filters" do
14
+ setup do
15
+ @filter = TigefaFilter.new
16
+ @sample_time = Time.utc(2013, 03, 27, 11, 22, 33)
17
+ @time_as_string = "September 11, 2001 12:46:30 -0000"
18
+ end
19
+
20
+ should "textilize with simple string" do
21
+ assert_equal "<p>something <strong>really</strong> simple</p>", @filter.textilize("something *really* simple")
22
+ end
23
+
24
+ should "markdownify with simple string" do
25
+ assert_equal "<p>something <strong>really</strong> simple</p>", @filter.markdownify("something **really** simple")
26
+ end
27
+
28
+ should "convert array to sentence string with no args" do
29
+ assert_equal "", @filter.array_to_sentence_string([])
30
+ end
31
+
32
+ should "convert array to sentence string with one arg" do
33
+ assert_equal "1", @filter.array_to_sentence_string([1])
34
+ assert_equal "chunky", @filter.array_to_sentence_string(["chunky"])
35
+ end
36
+
37
+ should "convert array to sentence string with two args" do
38
+ assert_equal "1 and 2", @filter.array_to_sentence_string([1, 2])
39
+ assert_equal "chunky and bacon", @filter.array_to_sentence_string(["chunky", "bacon"])
40
+ end
41
+
42
+ should "convert array to sentence string with multiple args" do
43
+ assert_equal "1, 2, 3, and 4", @filter.array_to_sentence_string([1, 2, 3, 4])
44
+ assert_equal "chunky, bacon, bits, and pieces", @filter.array_to_sentence_string(["chunky", "bacon", "bits", "pieces"])
45
+ end
46
+
47
+ context "date filters" do
48
+ context "with Time object" do
49
+ should "format a date with short format" do
50
+ assert_equal "27 Mar 2013", @filter.date_to_string(@sample_time)
51
+ end
52
+
53
+ should "format a date with long format" do
54
+ assert_equal "27 March 2013", @filter.date_to_long_string(@sample_time)
55
+ end
56
+
57
+ should "format a time with xmlschema" do
58
+ assert_equal "2013-03-27T11:22:33Z", @filter.date_to_xmlschema(@sample_time)
59
+ end
60
+
61
+ should "format a time according to RFC-822" do
62
+ assert_equal "Wed, 27 Mar 2013 11:22:33 -0000", @filter.date_to_rfc822(@sample_time)
63
+ end
64
+ end
65
+
66
+ context "with String object" do
67
+ should "format a date with short format" do
68
+ assert_equal "11 Sep 2001", @filter.date_to_string(@time_as_string)
69
+ end
70
+
71
+ should "format a date with long format" do
72
+ assert_equal "11 September 2001", @filter.date_to_long_string(@time_as_string)
73
+ end
74
+
75
+ should "format a time with xmlschema" do
76
+ assert_equal "2001-09-11T12:46:30Z", @filter.date_to_xmlschema(@time_as_string)
77
+ end
78
+
79
+ should "format a time according to RFC-822" do
80
+ assert_equal "Tue, 11 Sep 2001 12:46:30 -0000", @filter.date_to_rfc822(@time_as_string)
81
+ end
82
+ end
83
+ end
84
+
85
+ should "escape xml with ampersands" do
86
+ assert_equal "AT&amp;T", @filter.xml_escape("AT&T")
87
+ assert_equal "&lt;code&gt;command &amp;lt;filename&amp;gt;&lt;/code&gt;", @filter.xml_escape("<code>command &lt;filename&gt;</code>")
88
+ end
89
+
90
+ should "escape space as plus" do
91
+ assert_equal "my+things", @filter.cgi_escape("my things")
92
+ end
93
+
94
+ should "escape special characters" do
95
+ assert_equal "hey%21", @filter.cgi_escape("hey!")
96
+ end
97
+
98
+ should "escape space as %20" do
99
+ assert_equal "my%20things", @filter.uri_escape("my things")
100
+ end
101
+
102
+ context "jsonify filter" do
103
+ should "convert hash to json" do
104
+ assert_equal "{\"age\":18}", @filter.jsonify({:age => 18})
105
+ end
106
+
107
+ should "convert array to json" do
108
+ assert_equal "[1,2]", @filter.jsonify([1, 2])
109
+ assert_equal "[{\"name\":\"Jack\"},{\"name\":\"Smith\"}]", @filter.jsonify([{:name => 'Jack'}, {:name => 'Smith'}])
110
+ end
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,83 @@
1
+ require 'helper'
2
+
3
+ class TestGeneratedSite < Test::Unit::TestCase
4
+ context "generated sites" do
5
+ setup do
6
+ clear_dest
7
+ stub(Tigefa).configuration do
8
+ Tigefa::Configuration::DEFAULTS.merge({'source' => source_dir, 'destination' => dest_dir})
9
+ end
10
+
11
+ @site = Site.new(Tigefa.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 37, @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(Tigefa).configuration do
49
+ Tigefa::Configuration::DEFAULTS.merge({'source' => source_dir, 'destination' => dest_dir, 'limit_posts' => 5})
50
+ end
51
+
52
+ @site = Site.new(Tigefa.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 0 or more" do
62
+ assert_raise ArgumentError do
63
+ clear_dest
64
+ stub(Tigefa).configuration do
65
+ Tigefa::Configuration::DEFAULTS.merge({'source' => source_dir, 'destination' => dest_dir, 'limit_posts' => -1})
66
+ end
67
+
68
+ @site = Site.new(Tigefa.configuration)
69
+ end
70
+ end
71
+
72
+ should "acceptable limit post is 0" do
73
+ assert_nothing_raised ArgumentError do
74
+ clear_dest
75
+ stub(Tigefa).configuration do
76
+ Tigefa::Configuration::DEFAULTS.merge({'source' => source_dir, 'destination' => dest_dir, 'limit_posts' => 0})
77
+ end
78
+
79
+ @site = Site.new(Tigefa.configuration)
80
+ end
81
+ end
82
+ end
83
+ end