indirect-jekyll 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. data/.gitignore +6 -0
  2. data/History.txt +151 -0
  3. data/README.textile +42 -0
  4. data/Rakefile +90 -0
  5. data/VERSION.yml +4 -0
  6. data/bin/jekyll +150 -0
  7. data/features/create_sites.feature +46 -0
  8. data/features/embed_filters.feature +60 -0
  9. data/features/pagination.feature +40 -0
  10. data/features/permalinks.feature +65 -0
  11. data/features/post_data.feature +153 -0
  12. data/features/site_configuration.feature +63 -0
  13. data/features/site_data.feature +82 -0
  14. data/features/step_definitions/jekyll_steps.rb +136 -0
  15. data/features/support/env.rb +16 -0
  16. data/indirect-jekyll.gemspec +139 -0
  17. data/jekyll.gemspec +135 -0
  18. data/lib/jekyll.rb +85 -0
  19. data/lib/jekyll/albino.rb +122 -0
  20. data/lib/jekyll/converters/csv.rb +26 -0
  21. data/lib/jekyll/converters/mephisto.rb +79 -0
  22. data/lib/jekyll/converters/mt.rb +59 -0
  23. data/lib/jekyll/converters/textpattern.rb +50 -0
  24. data/lib/jekyll/converters/typo.rb +49 -0
  25. data/lib/jekyll/converters/wordpress.rb +54 -0
  26. data/lib/jekyll/convertible.rb +84 -0
  27. data/lib/jekyll/core_ext.rb +30 -0
  28. data/lib/jekyll/filters.rb +47 -0
  29. data/lib/jekyll/layout.rb +36 -0
  30. data/lib/jekyll/page.rb +112 -0
  31. data/lib/jekyll/pager.rb +45 -0
  32. data/lib/jekyll/post.rb +268 -0
  33. data/lib/jekyll/site.rb +265 -0
  34. data/lib/jekyll/tags/highlight.rb +56 -0
  35. data/lib/jekyll/tags/include.rb +31 -0
  36. data/test/helper.rb +27 -0
  37. data/test/source/_includes/sig.markdown +3 -0
  38. data/test/source/_layouts/default.html +27 -0
  39. data/test/source/_layouts/simple.html +1 -0
  40. data/test/source/_posts/2008-02-02-not-published.textile +8 -0
  41. data/test/source/_posts/2008-02-02-published.textile +8 -0
  42. data/test/source/_posts/2008-10-18-foo-bar.textile +8 -0
  43. data/test/source/_posts/2008-11-21-complex.textile +8 -0
  44. data/test/source/_posts/2008-12-03-permalinked-post.textile +9 -0
  45. data/test/source/_posts/2008-12-13-include.markdown +8 -0
  46. data/test/source/_posts/2009-01-27-array-categories.textile +10 -0
  47. data/test/source/_posts/2009-01-27-categories.textile +7 -0
  48. data/test/source/_posts/2009-01-27-category.textile +7 -0
  49. data/test/source/_posts/2009-03-12-hash-#1.markdown +6 -0
  50. data/test/source/_posts/2009-05-18-tag.textile +6 -0
  51. data/test/source/_posts/2009-05-18-tags.textile +9 -0
  52. data/test/source/_posts/2009-06-22-empty-yaml.textile +3 -0
  53. data/test/source/_posts/2009-06-22-no-yaml.textile +1 -0
  54. data/test/source/about.html +6 -0
  55. data/test/source/category/_posts/2008-9-23-categories.textile +6 -0
  56. data/test/source/contacts.html +5 -0
  57. data/test/source/css/screen.css +76 -0
  58. data/test/source/foo/_posts/bar/2008-12-12-topical-post.textile +8 -0
  59. data/test/source/index.html +22 -0
  60. data/test/source/sitemap.xml +23 -0
  61. data/test/source/win/_posts/2009-05-24-yaml-linebreak.markdown +7 -0
  62. data/test/source/z_category/_posts/2008-9-23-categories.textile +6 -0
  63. data/test/suite.rb +9 -0
  64. data/test/test_configuration.rb +29 -0
  65. data/test/test_filters.rb +49 -0
  66. data/test/test_generated_site.rb +40 -0
  67. data/test/test_page.rb +98 -0
  68. data/test/test_pager.rb +47 -0
  69. data/test/test_post.rb +302 -0
  70. data/test/test_site.rb +85 -0
  71. data/test/test_tags.rb +116 -0
  72. metadata +194 -0
@@ -0,0 +1,265 @@
1
+ module Jekyll
2
+
3
+ class Site
4
+ attr_accessor :config, :layouts, :posts, :categories, :exclude,
5
+ :source, :dest, :lsi, :pygments, :permalink_style, :tags
6
+
7
+ # Initialize the site
8
+ # +config+ is a Hash containing site configurations details
9
+ #
10
+ # Returns <Site>
11
+ def initialize(config)
12
+ self.config = config.clone
13
+
14
+ self.source = config['source']
15
+ self.dest = config['destination']
16
+ self.lsi = config['lsi']
17
+ self.pygments = config['pygments']
18
+ self.permalink_style = config['permalink'].to_sym
19
+ self.exclude = config['exclude'] || []
20
+
21
+ self.reset
22
+ self.setup
23
+ end
24
+
25
+ def reset
26
+ self.layouts = {}
27
+ self.posts = []
28
+ self.categories = Hash.new { |hash, key| hash[key] = [] }
29
+ self.tags = Hash.new { |hash, key| hash[key] = [] }
30
+ end
31
+
32
+ def setup
33
+ # Check to see if LSI is enabled.
34
+ require 'classifier' if self.lsi
35
+
36
+ # Set the Markdown interpreter (and Maruku self.config, if necessary)
37
+ case self.config['markdown']
38
+ when 'rdiscount'
39
+ begin
40
+ require 'rdiscount'
41
+
42
+ def markdown(content)
43
+ RDiscount.new(content).to_html
44
+ end
45
+
46
+ rescue LoadError
47
+ puts 'You must have the rdiscount gem installed first'
48
+ end
49
+ when 'maruku'
50
+ begin
51
+ require 'maruku'
52
+
53
+ def markdown(content)
54
+ Maruku.new(content).to_html
55
+ end
56
+
57
+ if self.config['maruku']['use_divs']
58
+ require 'maruku/ext/div'
59
+ puts 'Maruku: Using extended syntax for div elements.'
60
+ end
61
+
62
+ if self.config['maruku']['use_tex']
63
+ require 'maruku/ext/math'
64
+ puts "Maruku: Using LaTeX extension. Images in `#{self.config['maruku']['png_dir']}`."
65
+
66
+ # Switch off MathML output
67
+ MaRuKu::Globals[:html_math_output_mathml] = false
68
+ MaRuKu::Globals[:html_math_engine] = 'none'
69
+
70
+ # Turn on math to PNG support with blahtex
71
+ # Resulting PNGs stored in `images/latex`
72
+ MaRuKu::Globals[:html_math_output_png] = true
73
+ MaRuKu::Globals[:html_png_engine] = self.config['maruku']['png_engine']
74
+ MaRuKu::Globals[:html_png_dir] = self.config['maruku']['png_dir']
75
+ MaRuKu::Globals[:html_png_url] = self.config['maruku']['png_url']
76
+ end
77
+ rescue LoadError
78
+ puts "The maruku gem is required for markdown support!"
79
+ end
80
+ else
81
+ raise "Invalid Markdown processor: '#{self.config['markdown']}' -- did you mean 'maruku' or 'rdiscount'?"
82
+ end
83
+ end
84
+
85
+ def textile(content)
86
+ RedCloth.new(content).to_html
87
+ end
88
+
89
+ # Do the actual work of processing the site and generating the
90
+ # real deal.
91
+ #
92
+ # Returns nothing
93
+ def process
94
+ self.reset
95
+ self.read_layouts
96
+ self.transform_pages
97
+ self.write_posts
98
+ end
99
+
100
+ # Read all the files in <source>/_layouts into memory for later use.
101
+ #
102
+ # Returns nothing
103
+ def read_layouts
104
+ base = File.join(self.source, "_layouts")
105
+ entries = []
106
+ Dir.chdir(base) { entries = filter_entries(Dir['*.*']) }
107
+
108
+ entries.each do |f|
109
+ name = f.split(".")[0..-2].join(".")
110
+ self.layouts[name] = Layout.new(self, base, f)
111
+ end
112
+ rescue Errno::ENOENT => e
113
+ # ignore missing layout dir
114
+ end
115
+
116
+ # Read all the files in <base>/_posts and create a new Post object with each one.
117
+ #
118
+ # Returns nothing
119
+ def read_posts(dir)
120
+ base = File.join(self.source, dir, '_posts')
121
+ entries = []
122
+ Dir.chdir(base) { entries = filter_entries(Dir['**/*']) }
123
+
124
+ # first pass processes, but does not yet render post content
125
+ entries.each do |f|
126
+ if Post.valid?(f)
127
+ post = Post.new(self, self.source, dir, f)
128
+
129
+ if post.published
130
+ self.posts << post
131
+ post.categories.each { |c| self.categories[c] << post }
132
+ post.tags.each { |c| self.tags[c] << post }
133
+ end
134
+ end
135
+ end
136
+
137
+ self.posts.sort!
138
+
139
+ # second pass renders each post now that full site payload is available
140
+ self.posts.each do |post|
141
+ post.render(self.layouts, site_payload)
142
+ end
143
+
144
+ self.categories.values.map { |ps| ps.sort! { |a, b| b <=> a} }
145
+ self.tags.values.map { |ps| ps.sort! { |a, b| b <=> a} }
146
+ rescue Errno::ENOENT => e
147
+ # ignore missing layout dir
148
+ end
149
+
150
+ # Write each post to <dest>/<year>/<month>/<day>/<slug>
151
+ #
152
+ # Returns nothing
153
+ def write_posts
154
+ self.posts.each do |post|
155
+ post.write(self.dest)
156
+ end
157
+ end
158
+
159
+ # Copy all regular files from <source> to <dest>/ ignoring
160
+ # any files/directories that are hidden or backup files (start
161
+ # with "." or "#" or end with "~") or contain site content (start with "_")
162
+ # unless they are "_posts" directories or web server files such as
163
+ # '.htaccess'
164
+ # The +dir+ String is a relative path used to call this method
165
+ # recursively as it descends through directories
166
+ #
167
+ # Returns nothing
168
+ def transform_pages(dir = '')
169
+ base = File.join(self.source, dir)
170
+ entries = filter_entries(Dir.entries(base))
171
+ directories = entries.select { |e| File.directory?(File.join(base, e)) }
172
+ files = entries.reject { |e| File.directory?(File.join(base, e)) || File.symlink?(File.join(base, e)) }
173
+
174
+ # we need to make sure to process _posts *first* otherwise they
175
+ # might not be available yet to other templates as {{ site.posts }}
176
+ if directories.include?('_posts')
177
+ directories.delete('_posts')
178
+ read_posts(dir)
179
+ end
180
+
181
+ [directories, files].each do |entries|
182
+ entries.each do |f|
183
+ if File.directory?(File.join(base, f))
184
+ next if self.dest.sub(/\/$/, '') == File.join(base, f)
185
+ transform_pages(File.join(dir, f))
186
+ elsif Pager.pagination_enabled?(self.config, f)
187
+ paginate_posts(f, dir)
188
+ else
189
+ first3 = File.open(File.join(self.source, dir, f)) { |fd| fd.read(3) }
190
+ if first3 == "---"
191
+ # file appears to have a YAML header so process it as a page
192
+ page = Page.new(self, self.source, dir, f)
193
+ page.render(self.layouts, site_payload)
194
+ page.write(self.dest)
195
+ else
196
+ # otherwise copy the file without transforming it
197
+ FileUtils.mkdir_p(File.join(self.dest, dir))
198
+ FileUtils.cp(File.join(self.source, dir, f), File.join(self.dest, dir, f))
199
+ end
200
+ end
201
+ end
202
+ end
203
+ end
204
+
205
+ # Constructs a hash map of Posts indexed by the specified Post attribute
206
+ #
207
+ # Returns {post_attr => [<Post>]}
208
+ def post_attr_hash(post_attr)
209
+ # Build a hash map based on the specified post attribute ( post attr => array of posts )
210
+ # then sort each array in reverse order
211
+ hash = Hash.new { |hash, key| hash[key] = Array.new }
212
+ self.posts.each { |p| p.send(post_attr.to_sym).each { |t| hash[t] << p } }
213
+ hash.values.map { |sortme| sortme.sort! { |a, b| b <=> a} }
214
+ return hash
215
+ end
216
+
217
+ # The Hash payload containing site-wide data
218
+ #
219
+ # Returns {"site" => {"time" => <Time>,
220
+ # "posts" => [<Post>],
221
+ # "categories" => [<Post>]}
222
+ def site_payload
223
+ {"site" => self.config.merge({
224
+ "time" => Time.now,
225
+ "posts" => self.posts.sort { |a,b| b <=> a },
226
+ "categories" => post_attr_hash('categories'),
227
+ "tags" => post_attr_hash('tags')})}
228
+ end
229
+
230
+ # Filter out any files/directories that are hidden or backup files (start
231
+ # with "." or "#" or end with "~") or contain site content (start with "_")
232
+ # unless they are "_posts" directories or web server files such as
233
+ # '.htaccess'
234
+ def filter_entries(entries)
235
+ entries = entries.reject do |e|
236
+ unless ['_posts', '.htaccess'].include?(e)
237
+ ['.', '_', '#'].include?(e[0..0]) || e[-1..-1] == '~' || self.exclude.include?(e)
238
+ end
239
+ end
240
+ end
241
+
242
+ # Paginates the blog's posts. Renders the index.html file into paginated directories, ie: page2, page3...
243
+ # and adds more wite-wide data
244
+ #
245
+ # {"paginator" => { "page" => <Number>,
246
+ # "per_page" => <Number>,
247
+ # "posts" => [<Post>],
248
+ # "total_posts" => <Number>,
249
+ # "total_pages" => <Number>,
250
+ # "previous_page" => <Number>,
251
+ # "next_page" => <Number> }}
252
+ def paginate_posts(file, dir)
253
+ all_posts = self.posts.sort { |a,b| b <=> a }
254
+ pages = Pager.calculate_pages(all_posts, self.config['paginate'].to_i)
255
+ pages += 1
256
+ (1..pages).each do |num_page|
257
+ pager = Pager.new(self.config, num_page, all_posts, pages)
258
+ page = Page.new(self, self.source, dir, file)
259
+ page.render(self.layouts, site_payload.merge({'paginator' => pager.to_hash}))
260
+ suffix = "page#{num_page}" if num_page > 1
261
+ page.write(self.dest, suffix)
262
+ end
263
+ end
264
+ end
265
+ end
@@ -0,0 +1,56 @@
1
+ module Jekyll
2
+
3
+ class HighlightBlock < Liquid::Block
4
+ include Liquid::StandardFilters
5
+
6
+ # we need a language, but the linenos argument is optional.
7
+ SYNTAX = /(\w+)\s?(:?linenos)?\s?/
8
+
9
+ def initialize(tag_name, markup, tokens)
10
+ super
11
+ if markup =~ SYNTAX
12
+ @lang = $1
13
+ if defined? $2
14
+ # additional options to pass to Albino.
15
+ @options = { 'O' => 'linenos=inline' }
16
+ else
17
+ @options = {}
18
+ end
19
+ else
20
+ raise SyntaxError.new("Syntax Error in 'highlight' - Valid syntax: highlight <lang> [linenos]")
21
+ end
22
+ end
23
+
24
+ def render(context)
25
+ if context.registers[:site].pygments
26
+ render_pygments(context, super.to_s)
27
+ else
28
+ render_codehighlighter(context, super.to_s)
29
+ end
30
+ end
31
+
32
+ def render_pygments(context, code)
33
+ if context["content_type"] == "markdown"
34
+ return "\n" + Albino.new(code, @lang).to_s(@options) + "\n"
35
+ elsif context["content_type"] == "textile"
36
+ return "<notextile>" + Albino.new(code, @lang).to_s(@options) + "</notextile>"
37
+ else
38
+ return Albino.new(code, @lang).to_s(@options)
39
+ end
40
+ end
41
+
42
+ def render_codehighlighter(context, code)
43
+ #The div is required because RDiscount blows ass
44
+ <<-HTML
45
+ <div>
46
+ <pre>
47
+ <code class='#{@lang}'>#{h(code).strip}</code>
48
+ </pre>
49
+ </div>
50
+ HTML
51
+ end
52
+ end
53
+
54
+ end
55
+
56
+ Liquid::Template.register_tag('highlight', Jekyll::HighlightBlock)
@@ -0,0 +1,31 @@
1
+ module Jekyll
2
+
3
+ class IncludeTag < Liquid::Tag
4
+ def initialize(tag_name, file, tokens)
5
+ super
6
+ @file = file.strip
7
+ end
8
+
9
+ def render(context)
10
+ if @file !~ /^[a-zA-Z0-9_\/\.-]+$/ || @file =~ /\.\// || @file =~ /\/\./
11
+ return "Include file '#{@file}' contains invalid characters or sequences"
12
+ end
13
+
14
+ Dir.chdir(File.join(context.registers[:site].source, '_includes')) do
15
+ choices = Dir['**/*'].reject { |x| File.symlink?(x) }
16
+ if choices.include?(@file)
17
+ source = File.read(@file)
18
+ partial = Liquid::Template.parse(source)
19
+ context.stack do
20
+ partial.render(context)
21
+ end
22
+ else
23
+ "Included file '#{@file}' not found in _includes directory"
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ end
30
+
31
+ Liquid::Template.register_tag('include', Jekyll::IncludeTag)
data/test/helper.rb ADDED
@@ -0,0 +1,27 @@
1
+ require 'rubygems'
2
+ gem 'RedCloth', '= 4.2.1'
3
+
4
+ require File.join(File.dirname(__FILE__), *%w[.. lib jekyll])
5
+
6
+ require 'test/unit'
7
+ require 'redgreen'
8
+ require 'shoulda'
9
+ require 'rr'
10
+
11
+ include Jekyll
12
+
13
+ class Test::Unit::TestCase
14
+ include RR::Adapters::TestUnit
15
+
16
+ def dest_dir(*subdirs)
17
+ File.join(File.dirname(__FILE__), 'dest', *subdirs)
18
+ end
19
+
20
+ def source_dir(*subdirs)
21
+ File.join(File.dirname(__FILE__), 'source', *subdirs)
22
+ end
23
+
24
+ def clear_dest
25
+ FileUtils.rm_rf(dest_dir)
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ --
2
+ Tom Preston-Werner
3
+ github.com/mojombo
@@ -0,0 +1,27 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en-us">
5
+ <head>
6
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
7
+ <title>{{ page.title }}</title>
8
+ <meta name="author" content="<%= @page.author %>" />
9
+
10
+ <!-- CodeRay syntax highlighting CSS -->
11
+ <link rel="stylesheet" href="/css/coderay.css" type="text/css" />
12
+
13
+ <!-- Homepage CSS -->
14
+ <link rel="stylesheet" href="/css/screen.css" type="text/css" media="screen, projection" />
15
+ </head>
16
+ <body>
17
+
18
+ <div class="site">
19
+ <div class="title">
20
+ Tom Preston-Werner
21
+ </div>
22
+
23
+ {{ content }}
24
+ </div>
25
+
26
+ </body>
27
+ </html>
@@ -0,0 +1 @@
1
+ <<< {{ content }} >>>
@@ -0,0 +1,8 @@
1
+ ---
2
+ layout: default
3
+ title: Not published!
4
+ published: false
5
+ category: publish_test
6
+ ---
7
+
8
+ This should *not* be published!
@@ -0,0 +1,8 @@
1
+ ---
2
+ layout: default
3
+ title: Publish
4
+ category: publish_test
5
+ ---
6
+
7
+ This should be published.
8
+
@@ -0,0 +1,8 @@
1
+ ---
2
+ layout: default
3
+ title: Foo Bar
4
+ ---
5
+
6
+ h1. {{ page.title }}
7
+
8
+ Best *post* ever