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,427 @@
1
+ module Tigefa
2
+ class Site
3
+ attr_accessor :config, :layouts, :posts, :pages, :static_files,
4
+ :categories, :exclude, :include, :source, :dest, :lsi, :pygments,
5
+ :permalink_style, :tags, :time, :future, :safe, :plugins, :limit_posts,
6
+ :show_drafts, :keep_files, :baseurl, :data, :file_read_opts, :gems
7
+
8
+ attr_accessor :converters, :generators
9
+
10
+ # Public: Initialize a new Site.
11
+ #
12
+ # config - A Hash containing site configuration details.
13
+ def initialize(config)
14
+ self.config = config.clone
15
+
16
+ %w[safe lsi pygments baseurl exclude include future show_drafts limit_posts keep_files gems].each do |opt|
17
+ self.send("#{opt}=", config[opt])
18
+ end
19
+
20
+ self.source = File.expand_path(config['source'])
21
+ self.dest = File.expand_path(config['destination'])
22
+ self.plugins = plugins_path
23
+ self.permalink_style = config['permalink'].to_sym
24
+
25
+ self.file_read_opts = {}
26
+ self.file_read_opts[:encoding] = config['encoding'] if config['encoding']
27
+
28
+ self.reset
29
+ self.setup
30
+ end
31
+
32
+ # Public: Read, process, and write this Site to output.
33
+ #
34
+ # Returns nothing.
35
+ def process
36
+ self.reset
37
+ self.read
38
+ self.generate
39
+ self.render
40
+ self.cleanup
41
+ self.write
42
+ end
43
+
44
+ # Reset Site details.
45
+ #
46
+ # Returns nothing
47
+ def reset
48
+ self.time = if self.config['time']
49
+ Time.parse(self.config['time'].to_s)
50
+ else
51
+ Time.now
52
+ end
53
+ self.layouts = {}
54
+ self.posts = []
55
+ self.pages = []
56
+ self.static_files = []
57
+ self.categories = Hash.new { |hash, key| hash[key] = [] }
58
+ self.tags = Hash.new { |hash, key| hash[key] = [] }
59
+ self.data = {}
60
+
61
+ if self.limit_posts < 0
62
+ raise ArgumentError, "limit_posts must be a non-negative number"
63
+ end
64
+ end
65
+
66
+ # Load necessary libraries, plugins, converters, and generators.
67
+ #
68
+ # Returns nothing.
69
+ def setup
70
+ ensure_not_in_dest
71
+
72
+ # If safe mode is off, load in any Ruby files under the plugins
73
+ # directory.
74
+ unless self.safe
75
+ self.plugins.each do |plugins|
76
+ Dir[File.join(plugins, "**/*.rb")].sort.each do |f|
77
+ require f
78
+ end
79
+ end
80
+ self.gems.each do |gem|
81
+ require gem
82
+ end
83
+ end
84
+
85
+ self.converters = instantiate_subclasses(Jekyll::Converter)
86
+ self.generators = instantiate_subclasses(Jekyll::Generator)
87
+ end
88
+
89
+ # Check that the destination dir isn't the source dir or a directory
90
+ # parent to the source dir.
91
+ def ensure_not_in_dest
92
+ dest = Pathname.new(self.dest)
93
+ Pathname.new(self.source).ascend do |path|
94
+ if path == dest
95
+ raise FatalException.new "Destination directory cannot be or contain the Source directory."
96
+ end
97
+ end
98
+ end
99
+
100
+ # Internal: Setup the plugin search path
101
+ #
102
+ # Returns an Array of plugin search paths
103
+ def plugins_path
104
+ if (config['plugins'] == Jekyll::Configuration::DEFAULTS['plugins'])
105
+ [File.join(self.source, config['plugins'])]
106
+ else
107
+ Array(config['plugins']).map { |d| File.expand_path(d) }
108
+ end
109
+ end
110
+
111
+ # Read Site data from disk and load it into internal data structures.
112
+ #
113
+ # Returns nothing.
114
+ def read
115
+ self.read_layouts
116
+ self.read_directories
117
+ self.read_data(config['data_source'])
118
+ end
119
+
120
+ # Read all the files in <source>/<layouts> and create a new Layout object
121
+ # with each one.
122
+ #
123
+ # Returns nothing.
124
+ def read_layouts
125
+ base = File.join(self.source, self.config['layouts'])
126
+ return unless File.exists?(base)
127
+ entries = []
128
+ Dir.chdir(base) { entries = filter_entries(Dir['**/*.*']) }
129
+
130
+ entries.each do |f|
131
+ name = f.split(".")[0..-2].join(".")
132
+ self.layouts[name] = Layout.new(self, base, f)
133
+ end
134
+ end
135
+
136
+ # Recursively traverse directories to find posts, pages and static files
137
+ # that will become part of the site according to the rules in
138
+ # filter_entries.
139
+ #
140
+ # dir - The String relative path of the directory to read. Default: ''.
141
+ #
142
+ # Returns nothing.
143
+ def read_directories(dir = '')
144
+ base = File.join(self.source, dir)
145
+ entries = Dir.chdir(base) { filter_entries(Dir.entries('.')) }
146
+
147
+ self.read_posts(dir)
148
+ self.read_drafts(dir) if self.show_drafts
149
+ self.posts.sort!
150
+ limit_posts! if limit_posts > 0 # limit the posts if :limit_posts option is set
151
+
152
+ entries.each do |f|
153
+ f_abs = File.join(base, f)
154
+ if File.directory?(f_abs)
155
+ f_rel = File.join(dir, f)
156
+ read_directories(f_rel) unless self.dest.sub(/\/$/, '') == f_abs
157
+ elsif has_yaml_header?(f_abs)
158
+ pages << Page.new(self, self.source, dir, f)
159
+ else
160
+ static_files << StaticFile.new(self, self.source, dir, f)
161
+ end
162
+ end
163
+ end
164
+
165
+ # Read all the files in <source>/<dir>/_posts and create a new Post
166
+ # object with each one.
167
+ #
168
+ # dir - The String relative path of the directory to read.
169
+ #
170
+ # Returns nothing.
171
+ def read_posts(dir)
172
+ posts = read_things(dir, '_posts', Post)
173
+
174
+ posts.each do |post|
175
+ if post.published && (self.future || post.date <= self.time)
176
+ aggregate_post_info(post)
177
+ end
178
+ end
179
+ end
180
+
181
+ # Read all the files in <source>/<dir>/_drafts and create a new Post
182
+ # object with each one.
183
+ #
184
+ # dir - The String relative path of the directory to read.
185
+ #
186
+ # Returns nothing.
187
+ def read_drafts(dir)
188
+ drafts = read_things(dir, '_drafts', Draft)
189
+
190
+ drafts.each do |draft|
191
+ aggregate_post_info(draft)
192
+ end
193
+ end
194
+
195
+ def read_things(dir, magic_dir, klass)
196
+ get_entries(dir, magic_dir).map do |entry|
197
+ klass.new(self, self.source, dir, entry) if klass.valid?(entry)
198
+ end.reject do |entry|
199
+ entry.nil?
200
+ end
201
+ end
202
+
203
+ # Read and parse all yaml files under <source>/<dir>
204
+ #
205
+ # Returns nothing
206
+ def read_data(dir)
207
+ base = File.join(self.source, dir)
208
+ return unless File.directory?(base) && (!self.safe || !File.symlink?(base))
209
+
210
+ entries = Dir.chdir(base) { Dir['*.{yaml,yml}'] }
211
+ entries.delete_if { |e| File.directory?(File.join(base, e)) }
212
+
213
+ entries.each do |entry|
214
+ path = File.join(self.source, dir, entry)
215
+ next if File.symlink?(path) && self.safe
216
+
217
+ key = sanitize_filename(File.basename(entry, '.*'))
218
+ self.data[key] = YAML.safe_load_file(path)
219
+ end
220
+ end
221
+
222
+ # Run each of the Generators.
223
+ #
224
+ # Returns nothing.
225
+ def generate
226
+ self.generators.each do |generator|
227
+ generator.generate(self)
228
+ end
229
+ end
230
+
231
+ # Render the site to the destination.
232
+ #
233
+ # Returns nothing.
234
+ def render
235
+ relative_permalinks_deprecation_method
236
+
237
+ payload = site_payload
238
+ [self.posts, self.pages].flatten.each do |page_or_post|
239
+ page_or_post.render(self.layouts, payload)
240
+ end
241
+
242
+ self.categories.values.map { |ps| ps.sort! { |a, b| b <=> a } }
243
+ self.tags.values.map { |ps| ps.sort! { |a, b| b <=> a } }
244
+ rescue Errno::ENOENT => e
245
+ # ignore missing layout dir
246
+ end
247
+
248
+ # Remove orphaned files and empty directories in destination.
249
+ #
250
+ # Returns nothing.
251
+ def cleanup
252
+ site_cleaner.cleanup!
253
+ end
254
+
255
+ # Write static files, pages, and posts.
256
+ #
257
+ # Returns nothing.
258
+ def write
259
+ each_site_file { |item| item.write(self.dest) }
260
+ end
261
+
262
+ # Construct a Hash of Posts indexed by the specified Post attribute.
263
+ #
264
+ # post_attr - The String name of the Post attribute.
265
+ #
266
+ # Examples
267
+ #
268
+ # post_attr_hash('categories')
269
+ # # => { 'tech' => [<Post A>, <Post B>],
270
+ # # 'ruby' => [<Post B>] }
271
+ #
272
+ # Returns the Hash: { attr => posts } where
273
+ # attr - One of the values for the requested attribute.
274
+ # posts - The Array of Posts with the given attr value.
275
+ def post_attr_hash(post_attr)
276
+ # Build a hash map based on the specified post attribute ( post attr =>
277
+ # array of posts ) then sort each array in reverse order.
278
+ hash = Hash.new { |hsh, key| hsh[key] = Array.new }
279
+ self.posts.each { |p| p.send(post_attr.to_sym).each { |t| hash[t] << p } }
280
+ hash.values.map { |sortme| sortme.sort! { |a, b| b <=> a } }
281
+ hash
282
+ end
283
+
284
+ # Prepare site data for site payload. The method maintains backward compatibility
285
+ # if the key 'data' is already used in _config.yml.
286
+ #
287
+ # Returns the Hash to be hooked to site.data.
288
+ def site_data
289
+ self.config['data'] || self.data
290
+ end
291
+
292
+ # The Hash payload containing site-wide data.
293
+ #
294
+ # Returns the Hash: { "site" => data } where data is a Hash with keys:
295
+ # "time" - The Time as specified in the configuration or the
296
+ # current time if none was specified.
297
+ # "posts" - The Array of Posts, sorted chronologically by post date
298
+ # and then title.
299
+ # "pages" - The Array of all Pages.
300
+ # "html_pages" - The Array of HTML Pages.
301
+ # "categories" - The Hash of category values and Posts.
302
+ # See Site#post_attr_hash for type info.
303
+ # "tags" - The Hash of tag values and Posts.
304
+ # See Site#post_attr_hash for type info.
305
+ def site_payload
306
+ {"jekyll" => { "version" => Tigefa::VERSION },
307
+ "site" => self.config.merge({
308
+ "time" => self.time,
309
+ "posts" => self.posts.sort { |a, b| b <=> a },
310
+ "pages" => self.pages,
311
+ "html_pages" => self.pages.reject { |page| !page.html? },
312
+ "categories" => post_attr_hash('categories'),
313
+ "tags" => post_attr_hash('tags'),
314
+ "data" => site_data})}
315
+ end
316
+
317
+ # Filter out any files/directories that are hidden or backup files (start
318
+ # with "." or "#" or end with "~"), or contain site content (start with "_"),
319
+ # or are excluded in the site configuration, unless they are web server
320
+ # files such as '.htaccess'.
321
+ #
322
+ # entries - The Array of String file/directory entries to filter.
323
+ #
324
+ # Returns the Array of filtered entries.
325
+ def filter_entries(entries)
326
+ EntryFilter.new(self).filter(entries)
327
+ end
328
+
329
+ # Get the implementation class for the given Converter.
330
+ #
331
+ # klass - The Class of the Converter to fetch.
332
+ #
333
+ # Returns the Converter instance implementing the given Converter.
334
+ def getConverterImpl(klass)
335
+ matches = self.converters.select { |c| c.class == klass }
336
+ if impl = matches.first
337
+ impl
338
+ else
339
+ raise "Converter implementation not found for #{klass}"
340
+ end
341
+ end
342
+
343
+ # Create array of instances of the subclasses of the class or module
344
+ # passed in as argument.
345
+ #
346
+ # klass - class or module containing the subclasses which should be
347
+ # instantiated
348
+ #
349
+ # Returns array of instances of subclasses of parameter
350
+ def instantiate_subclasses(klass)
351
+ klass.subclasses.select do |c|
352
+ !self.safe || c.safe
353
+ end.sort.map do |c|
354
+ c.new(self.config)
355
+ end
356
+ end
357
+
358
+ # Read the entries from a particular directory for processing
359
+ #
360
+ # dir - The String relative path of the directory to read
361
+ # subfolder - The String directory to read
362
+ #
363
+ # Returns the list of entries to process
364
+ def get_entries(dir, subfolder)
365
+ base = File.join(self.source, dir, subfolder)
366
+ return [] unless File.exists?(base)
367
+ entries = Dir.chdir(base) { filter_entries(Dir['**/*']) }
368
+ entries.delete_if { |e| File.directory?(File.join(base, e)) }
369
+ end
370
+
371
+ # Aggregate post information
372
+ #
373
+ # post - The Post object to aggregate information for
374
+ #
375
+ # Returns nothing
376
+ def aggregate_post_info(post)
377
+ self.posts << post
378
+ post.categories.each { |c| self.categories[c] << post }
379
+ post.tags.each { |c| self.tags[c] << post }
380
+ end
381
+
382
+ def relative_permalinks_deprecation_method
383
+ if config['relative_permalinks'] && has_relative_page?
384
+ $stderr.puts # Places newline after "Generating..."
385
+ Tigefa.logger.warn "Deprecation:", "Starting in 2.0, permalinks for pages" +
386
+ " in subfolders must be relative to the" +
387
+ " site source directory, not the parent" +
388
+ " directory. Check http://jekyllrb.com/docs/upgrading/"+
389
+ " for more info."
390
+ $stderr.print Tigefa.logger.formatted_topic("") + "..." # for "done."
391
+ end
392
+ end
393
+
394
+ def each_site_file
395
+ %w(posts pages static_files).each do |type|
396
+ self.send(type).each do |item|
397
+ yield item
398
+ end
399
+ end
400
+ end
401
+
402
+ private
403
+
404
+ def has_relative_page?
405
+ self.pages.any? { |page| page.uses_relative_permalinks }
406
+ end
407
+
408
+ def has_yaml_header?(file)
409
+ "---" == File.open(file) { |fd| fd.read(3) }
410
+ end
411
+
412
+ def limit_posts!
413
+ limit = self.posts.length < limit_posts ? self.posts.length : limit_posts
414
+ self.posts = self.posts[-limit, limit]
415
+ end
416
+
417
+ def site_cleaner
418
+ @site_cleaner ||= Cleaner.new(self)
419
+ end
420
+
421
+ def sanitize_filename(name)
422
+ name = name.gsub(/[^\w\s_-]+/, '')
423
+ name = name.gsub(/(^|\b\s)\s+($|\s?\b)/, '\\1\\2')
424
+ name = name.gsub(/\s+/, '_')
425
+ end
426
+ end
427
+ end
@@ -0,0 +1,70 @@
1
+ module Tigefa
2
+ class StaticFile
3
+ # The cache of last modification times [path] -> mtime.
4
+ @@mtimes = Hash.new
5
+
6
+ # Initialize a new StaticFile.
7
+ #
8
+ # site - The Site.
9
+ # base - The String path to the <source>.
10
+ # dir - The String path between <source> and the file.
11
+ # name - The String filename of the file.
12
+ def initialize(site, base, dir, name)
13
+ @site = site
14
+ @base = base
15
+ @dir = dir
16
+ @name = name
17
+ end
18
+
19
+ # Returns source file path.
20
+ def path
21
+ File.join(@base, @dir, @name)
22
+ end
23
+
24
+ # Obtain destination path.
25
+ #
26
+ # dest - The String path to the destination dir.
27
+ #
28
+ # Returns destination file path.
29
+ def destination(dest)
30
+ File.join(dest, @dir, @name)
31
+ end
32
+
33
+ # Returns last modification time for this file.
34
+ def mtime
35
+ File.stat(path).mtime.to_i
36
+ end
37
+
38
+ # Is source path modified?
39
+ #
40
+ # Returns true if modified since last write.
41
+ def modified?
42
+ @@mtimes[path] != mtime
43
+ end
44
+
45
+ # Write the static file to the destination directory (if modified).
46
+ #
47
+ # dest - The String path to the destination dir.
48
+ #
49
+ # Returns false if the file was not modified since last time (no-op).
50
+ def write(dest)
51
+ dest_path = destination(dest)
52
+
53
+ return false if File.exist?(dest_path) and !modified?
54
+ @@mtimes[path] = mtime
55
+
56
+ FileUtils.mkdir_p(File.dirname(dest_path))
57
+ FileUtils.cp(path, dest_path)
58
+
59
+ true
60
+ end
61
+
62
+ # Reset the mtimes cache (for testing purposes).
63
+ #
64
+ # Returns nothing.
65
+ def self.reset_cache
66
+ @@mtimes = Hash.new
67
+ nil
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,89 @@
1
+ module Tigefa
2
+ class Stevenson
3
+ attr_accessor :log_level
4
+
5
+ DEBUG = 0
6
+ INFO = 1
7
+ WARN = 2
8
+ ERROR = 3
9
+
10
+ # Public: Create a new instance of Stevenson, Tigefa's logger
11
+ #
12
+ # level - (optional, integer) the log level
13
+ #
14
+ # Returns nothing
15
+ def initialize(level = INFO)
16
+ @log_level = level
17
+ end
18
+
19
+ # Public: Print a jekyll debug message to stdout
20
+ #
21
+ # topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
22
+ # message - the message detail
23
+ #
24
+ # Returns nothing
25
+ def debug(topic, message = nil)
26
+ $stdout.puts(message(topic, message)) if log_level <= DEBUG
27
+ end
28
+
29
+ # Public: Print a jekyll message to stdout
30
+ #
31
+ # topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
32
+ # message - the message detail
33
+ #
34
+ # Returns nothing
35
+ def info(topic, message = nil)
36
+ $stdout.puts(message(topic, message)) if log_level <= INFO
37
+ end
38
+
39
+ # Public: Print a jekyll message to stderr
40
+ #
41
+ # topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
42
+ # message - the message detail
43
+ #
44
+ # Returns nothing
45
+ def warn(topic, message = nil)
46
+ $stderr.puts(message(topic, message).yellow) if log_level <= WARN
47
+ end
48
+
49
+ # Public: Print a Tigefa error message to stderr
50
+ #
51
+ # topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
52
+ # message - the message detail
53
+ #
54
+ # Returns nothing
55
+ def error(topic, message = nil)
56
+ $stderr.puts(message(topic, message).red) if log_level <= ERROR
57
+ end
58
+
59
+ # Public: Print a Tigefa error message to stderr and immediately abort the process
60
+ #
61
+ # topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
62
+ # message - the message detail (can be omitted)
63
+ #
64
+ # Returns nothing
65
+ def abort_with(topic, message = nil)
66
+ error(topic, message)
67
+ abort
68
+ end
69
+
70
+ # Public: Build a Tigefa topic method
71
+ #
72
+ # topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
73
+ # message - the message detail
74
+ #
75
+ # Returns the formatted message
76
+ def message(topic, message)
77
+ formatted_topic(topic) + message.to_s.gsub(/\s+/, ' ')
78
+ end
79
+
80
+ # Public: Format the topic
81
+ #
82
+ # topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
83
+ #
84
+ # Returns the formatted topic statement
85
+ def formatted_topic(topic)
86
+ "#{topic} ".rjust(20)
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,48 @@
1
+ # Gist Liquid Tag
2
+ #
3
+ # Example:
4
+ # {% gist 1234567 %}
5
+ # {% gist 1234567 file.rb %}
6
+
7
+ module Tigefa
8
+ class GistTag < Liquid::Tag
9
+
10
+ def render(context)
11
+ if tag_contents = determine_arguments(@markup.strip)
12
+ gist_id, filename = tag_contents[0], tag_contents[1]
13
+ gist_script_tag(gist_id, filename)
14
+ else
15
+ raise ArgumentError.new <<-eos
16
+ Syntax error in tag 'gist' while parsing the following markup:
17
+
18
+ #{@markup}
19
+
20
+ Valid syntax:
21
+ for public gists: {% gist 1234567 %}
22
+ for private gists: {% gist user/1234567 %}
23
+ eos
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def determine_arguments(input)
30
+ matched = if input.include?("/")
31
+ input.match(/\A([a-zA-Z0-9\/\-_]+) ?(\S*)\Z/)
32
+ else
33
+ input.match(/\A(\d+) ?(\S*)\Z/)
34
+ end
35
+ [matched[1].strip, matched[2].strip] if matched && matched.length >= 3
36
+ end
37
+
38
+ def gist_script_tag(gist_id, filename = nil)
39
+ if filename.empty?
40
+ "<script src=\"https://gist.github.com/#{gist_id}.js\"> </script>"
41
+ else
42
+ "<script src=\"https://gist.github.com/#{gist_id}.js?file=#{filename}\"> </script>"
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ Liquid::Template.register_tag('gist', Jekyll::GistTag)