nirvdrum-jekyll 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. data/.gitignore +7 -0
  2. data/History.txt +143 -0
  3. data/README.textile +42 -0
  4. data/Rakefile +92 -0
  5. data/VERSION.yml +4 -0
  6. data/bin/jekyll +150 -0
  7. data/features/create_sites.feature +60 -0
  8. data/features/embed_filters.feature +60 -0
  9. data/features/pagination.feature +40 -0
  10. data/features/permalinks.feature +63 -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/jekyll.gemspec +134 -0
  17. data/lib/jekyll.rb +86 -0
  18. data/lib/jekyll/albino.rb +122 -0
  19. data/lib/jekyll/converters/csv.rb +26 -0
  20. data/lib/jekyll/converters/mephisto.rb +79 -0
  21. data/lib/jekyll/converters/mt.rb +59 -0
  22. data/lib/jekyll/converters/textpattern.rb +50 -0
  23. data/lib/jekyll/converters/typo.rb +49 -0
  24. data/lib/jekyll/converters/wordpress.rb +54 -0
  25. data/lib/jekyll/convertible.rb +89 -0
  26. data/lib/jekyll/core_ext.rb +30 -0
  27. data/lib/jekyll/filters.rb +47 -0
  28. data/lib/jekyll/layout.rb +36 -0
  29. data/lib/jekyll/page.rb +112 -0
  30. data/lib/jekyll/pager.rb +45 -0
  31. data/lib/jekyll/post.rb +251 -0
  32. data/lib/jekyll/site.rb +295 -0
  33. data/lib/jekyll/stylesheet.rb +88 -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/_stylesheets/nested/override.less +1 -0
  55. data/test/source/_stylesheets/simple.less +3 -0
  56. data/test/source/about.html +6 -0
  57. data/test/source/category/_posts/2008-9-23-categories.textile +6 -0
  58. data/test/source/contacts.html +5 -0
  59. data/test/source/css/screen.css +76 -0
  60. data/test/source/foo/_posts/bar/2008-12-12-topical-post.textile +8 -0
  61. data/test/source/index.html +22 -0
  62. data/test/source/win/_posts/2009-05-24-yaml-linebreak.markdown +7 -0
  63. data/test/source/z_category/_posts/2008-9-23-categories.textile +6 -0
  64. data/test/suite.rb +9 -0
  65. data/test/test_configuration.rb +29 -0
  66. data/test/test_filters.rb +49 -0
  67. data/test/test_generated_site.rb +53 -0
  68. data/test/test_page.rb +87 -0
  69. data/test/test_pager.rb +47 -0
  70. data/test/test_post.rb +302 -0
  71. data/test/test_site.rb +85 -0
  72. data/test/test_stylesheet.rb +67 -0
  73. data/test/test_tags.rb +116 -0
  74. metadata +196 -0
@@ -0,0 +1,47 @@
1
+ module Jekyll
2
+
3
+ module Filters
4
+ def textilize(input)
5
+ RedCloth.new(input).to_html
6
+ end
7
+
8
+ def date_to_string(date)
9
+ date.strftime("%d %b %Y")
10
+ end
11
+
12
+ def date_to_long_string(date)
13
+ date.strftime("%d %B %Y")
14
+ end
15
+
16
+ def date_to_xmlschema(date)
17
+ date.xmlschema
18
+ end
19
+
20
+ def xml_escape(input)
21
+ CGI.escapeHTML(input)
22
+ end
23
+
24
+ def cgi_escape(input)
25
+ CGI::escape(input)
26
+ end
27
+
28
+ def number_of_words(input)
29
+ input.split.length
30
+ end
31
+
32
+ def array_to_sentence_string(array)
33
+ connector = "and"
34
+ case array.length
35
+ when 0
36
+ ""
37
+ when 1
38
+ array[0].to_s
39
+ when 2
40
+ "#{array[0]} #{connector} #{array[1]}"
41
+ else
42
+ "#{array[0...-1].join(', ')}, #{connector} #{array[-1]}"
43
+ end
44
+ end
45
+
46
+ end
47
+ end
@@ -0,0 +1,36 @@
1
+ module Jekyll
2
+
3
+ class Layout
4
+ include Convertible
5
+
6
+ attr_accessor :site
7
+ attr_accessor :ext
8
+ attr_accessor :data, :content
9
+
10
+ # Initialize a new Layout.
11
+ # +site+ is the Site
12
+ # +base+ is the String path to the <source>
13
+ # +name+ is the String filename of the post file
14
+ #
15
+ # Returns <Page>
16
+ def initialize(site, base, name)
17
+ @site = site
18
+ @base = base
19
+ @name = name
20
+
21
+ self.data = {}
22
+
23
+ self.process(name)
24
+ self.read_yaml(base, name)
25
+ end
26
+
27
+ # Extract information from the layout filename
28
+ # +name+ is the String filename of the layout file
29
+ #
30
+ # Returns nothing
31
+ def process(name)
32
+ self.ext = File.extname(name)
33
+ end
34
+ end
35
+
36
+ end
@@ -0,0 +1,112 @@
1
+ module Jekyll
2
+
3
+ class Page
4
+ include Convertible
5
+
6
+ attr_accessor :site
7
+ attr_accessor :name, :ext, :basename
8
+ attr_accessor :data, :content, :output
9
+
10
+ # Initialize a new Page.
11
+ # +site+ is the Site
12
+ # +base+ is the String path to the <source>
13
+ # +dir+ is the String path between <source> and the file
14
+ # +name+ is the String filename of the file
15
+ #
16
+ # Returns <Page>
17
+ def initialize(site, base, dir, name)
18
+ @site = site
19
+ @base = base
20
+ @dir = dir
21
+ @name = name
22
+
23
+ self.process(name)
24
+ self.read_yaml(File.join(base, dir), name)
25
+ end
26
+
27
+ # The generated directory into which the page will be placed
28
+ # upon generation. This is derived from the permalink or, if
29
+ # permalink is absent, set to '/'
30
+ #
31
+ # Returns <String>
32
+ def dir
33
+ url[-1, 1] == '/' ? url : File.dirname(url)
34
+ end
35
+
36
+ # The full path and filename of the post.
37
+ # Defined in the YAML of the post body
38
+ # (Optional)
39
+ #
40
+ # Returns <String>
41
+ def permalink
42
+ self.data && self.data['permalink']
43
+ end
44
+
45
+ def template
46
+ if self.site.permalink_style == :pretty && !index?
47
+ "/:name/"
48
+ else
49
+ "/:name.html"
50
+ end
51
+ end
52
+
53
+ # The generated relative url of this page
54
+ # e.g. /about.html
55
+ #
56
+ # Returns <String>
57
+ def url
58
+ return permalink if permalink
59
+
60
+ @url ||= template.gsub(':name', basename)
61
+ end
62
+
63
+ # Extract information from the page filename
64
+ # +name+ is the String filename of the page file
65
+ #
66
+ # Returns nothing
67
+ def process(name)
68
+ self.ext = File.extname(name)
69
+ self.basename = name.split('.')[0..-2].first
70
+ end
71
+
72
+ # Add any necessary layouts to this post
73
+ # +layouts+ is a Hash of {"name" => "layout"}
74
+ # +site_payload+ is the site payload hash
75
+ #
76
+ # Returns nothing
77
+ def render(layouts, site_payload)
78
+ payload = {"page" => self.data}.deep_merge(site_payload)
79
+ do_layout(payload, layouts)
80
+ end
81
+
82
+ # Write the generated page file to the destination directory.
83
+ # +dest_prefix+ is the String path to the destination dir
84
+ # +dest_suffix+ is a suffix path to the destination dir
85
+ #
86
+ # Returns nothing
87
+ def write(dest_prefix, dest_suffix = nil)
88
+ dest = File.join(dest_prefix, @dir)
89
+ dest = File.join(dest, dest_suffix) if dest_suffix
90
+ FileUtils.mkdir_p(dest)
91
+
92
+ # The url needs to be unescaped in order to preserve the correct filename
93
+ path = File.join(dest, CGI.unescape(self.url))
94
+ if self.url[/\.html$/].nil?
95
+ FileUtils.mkdir_p(path)
96
+ path = File.join(path, "index.html")
97
+ end
98
+
99
+ File.open(path, 'w') do |f|
100
+ f.write(self.output)
101
+ end
102
+ end
103
+
104
+ private
105
+
106
+ def index?
107
+ basename == 'index'
108
+ end
109
+
110
+ end
111
+
112
+ end
@@ -0,0 +1,45 @@
1
+ module Jekyll
2
+ class Pager
3
+ attr_reader :page, :per_page, :posts, :total_posts, :total_pages, :previous_page, :next_page
4
+
5
+ def self.calculate_pages(all_posts, per_page)
6
+ num_pages = all_posts.size / per_page.to_i
7
+ num_pages.abs + 1 if all_posts.size % per_page.to_i != 0
8
+ num_pages
9
+ end
10
+
11
+ def self.pagination_enabled?(config, file)
12
+ file == 'index.html' && !config['paginate'].nil?
13
+ end
14
+
15
+ def initialize(config, page, all_posts, num_pages = nil)
16
+ @page = page
17
+ @per_page = config['paginate'].to_i
18
+ @total_pages = num_pages || Pager.calculate_pages(all_posts, @per_page)
19
+
20
+ if @page > @total_pages
21
+ raise RuntimeError, "page number can't be greater than total pages: #{@page} > #{@total_pages}"
22
+ end
23
+
24
+ init = (@page - 1) * @per_page
25
+ offset = (init + @per_page - 1) >= all_posts.size ? all_posts.size : (init + @per_page - 1)
26
+
27
+ @total_posts = all_posts.size
28
+ @posts = all_posts[init..offset]
29
+ @previous_page = @page != 1 ? @page - 1 : nil
30
+ @next_page = @page != @total_pages ? @page + 1 : nil
31
+ end
32
+
33
+ def to_hash
34
+ {
35
+ 'page' => page,
36
+ 'per_page' => per_page,
37
+ 'posts' => posts,
38
+ 'total_posts' => total_posts,
39
+ 'total_pages' => total_pages,
40
+ 'previous_page' => previous_page,
41
+ 'next_page' => next_page
42
+ }
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,251 @@
1
+ module Jekyll
2
+
3
+ class Post
4
+ include Comparable
5
+ include Convertible
6
+
7
+ class << self
8
+ attr_accessor :lsi
9
+ end
10
+
11
+ MATCHER = /^(.+\/)*(\d+-\d+-\d+)-(.*)(\.[^.]+)$/
12
+
13
+ # Post name validator. Post filenames must be like:
14
+ # 2008-11-05-my-awesome-post.textile
15
+ #
16
+ # Returns <Bool>
17
+ def self.valid?(name)
18
+ name =~ MATCHER
19
+ end
20
+
21
+ attr_accessor :site, :date, :slug, :ext, :published, :data, :content, :output, :tags
22
+ attr_writer :categories
23
+
24
+ def categories
25
+ @categories ||= []
26
+ end
27
+
28
+ # Initialize this Post instance.
29
+ # +site+ is the Site
30
+ # +base+ is the String path to the dir containing the post file
31
+ # +name+ is the String filename of the post file
32
+ # +categories+ is an Array of Strings for the categories for this post
33
+ #
34
+ # Returns <Post>
35
+ def initialize(site, source, dir, name)
36
+ @site = site
37
+ @base = File.join(source, dir, '_posts')
38
+ @name = name
39
+
40
+ self.categories = dir.split('/').reject { |x| x.empty? }
41
+ self.process(name)
42
+ self.read_yaml(@base, name)
43
+
44
+ if self.data.has_key?('published') && self.data['published'] == false
45
+ self.published = false
46
+ else
47
+ self.published = true
48
+ end
49
+
50
+ if self.data.has_key?("tag")
51
+ self.tags = [self.data["tag"]]
52
+ elsif self.data.has_key?("tags")
53
+ self.tags = self.data['tags']
54
+ else
55
+ self.tags = []
56
+ end
57
+
58
+ if self.categories.empty?
59
+ if self.data.has_key?('category')
60
+ self.categories << self.data['category']
61
+ elsif self.data.has_key?('categories')
62
+ # Look for categories in the YAML-header, either specified as
63
+ # an array or a string.
64
+ if self.data['categories'].kind_of? String
65
+ self.categories = self.data['categories'].split
66
+ else
67
+ self.categories = self.data['categories']
68
+ end
69
+ end
70
+ end
71
+ end
72
+
73
+ # Spaceship is based on Post#date, slug
74
+ #
75
+ # Returns -1, 0, 1
76
+ def <=>(other)
77
+ cmp = self.date <=> other.date
78
+ if 0 == cmp
79
+ cmp = self.slug <=> other.slug
80
+ end
81
+ return cmp
82
+ end
83
+
84
+ # Extract information from the post filename
85
+ # +name+ is the String filename of the post file
86
+ #
87
+ # Returns nothing
88
+ def process(name)
89
+ m, cats, date, slug, ext = *name.match(MATCHER)
90
+ self.date = Time.parse(date)
91
+ self.slug = slug
92
+ self.ext = ext
93
+ end
94
+
95
+ # The generated directory into which the post will be placed
96
+ # upon generation. This is derived from the permalink or, if
97
+ # permalink is absent, set to the default date
98
+ # e.g. "/2008/11/05/" if the permalink style is :date, otherwise nothing
99
+ #
100
+ # Returns <String>
101
+ def dir
102
+ File.dirname(url)
103
+ end
104
+
105
+ # The full path and filename of the post.
106
+ # Defined in the YAML of the post body
107
+ # (Optional)
108
+ #
109
+ # Returns <String>
110
+ def permalink
111
+ self.data && self.data['permalink']
112
+ end
113
+
114
+ def template
115
+ case self.site.permalink_style
116
+ when :pretty
117
+ "/:categories/:year/:month/:day/:title/"
118
+ when :none
119
+ "/:categories/:title.html"
120
+ when :date
121
+ "/:categories/:year/:month/:day/:title.html"
122
+ else
123
+ self.site.permalink_style.to_s
124
+ end
125
+ end
126
+
127
+ # The generated relative url of this post
128
+ # e.g. /2008/11/05/my-awesome-post.html
129
+ #
130
+ # Returns <String>
131
+ def url
132
+ return permalink if permalink
133
+
134
+ @url ||= {
135
+ "year" => date.strftime("%Y"),
136
+ "month" => date.strftime("%m"),
137
+ "day" => date.strftime("%d"),
138
+ "title" => CGI.escape(slug),
139
+ "categories" => categories.sort.join('/')
140
+ }.inject(template) { |result, token|
141
+ result.gsub(/:#{token.first}/, token.last)
142
+ }.gsub(/\/\//, "/")
143
+ end
144
+
145
+ # The UID for this post (useful in feeds)
146
+ # e.g. /2008/11/05/my-awesome-post
147
+ #
148
+ # Returns <String>
149
+ def id
150
+ File.join(self.dir, self.slug)
151
+ end
152
+
153
+ # Calculate related posts.
154
+ #
155
+ # Returns [<Post>]
156
+ def related_posts(posts)
157
+ return [] unless posts.size > 1
158
+
159
+ if self.site.lsi
160
+ self.class.lsi ||= begin
161
+ puts "Running the classifier... this could take a while."
162
+ lsi = Classifier::LSI.new
163
+ posts.each { |x| $stdout.print(".");$stdout.flush;lsi.add_item(x) }
164
+ puts ""
165
+ lsi
166
+ end
167
+
168
+ related = self.class.lsi.find_related(self.content, 11)
169
+ related - [self]
170
+ else
171
+ (posts - [self])[0..9]
172
+ end
173
+ end
174
+
175
+ # Add any necessary layouts to this post
176
+ # +layouts+ is a Hash of {"name" => "layout"}
177
+ # +site_payload+ is the site payload hash
178
+ #
179
+ # Returns nothing
180
+ def render(layouts, site_payload)
181
+ # construct payload
182
+ payload =
183
+ {
184
+ "site" => { "related_posts" => related_posts(site_payload["site"]["posts"]) },
185
+ "page" => self.to_liquid
186
+ }
187
+ payload = payload.deep_merge(site_payload)
188
+
189
+ do_layout(payload, layouts)
190
+ end
191
+
192
+ # Write the generated post file to the destination directory.
193
+ # +dest+ is the String path to the destination dir
194
+ #
195
+ # Returns nothing
196
+ def write(dest)
197
+ FileUtils.mkdir_p(File.join(dest, dir))
198
+
199
+ # The url needs to be unescaped in order to preserve the correct filename
200
+ path = File.join(dest, CGI.unescape(self.url))
201
+
202
+ if template[/\.html$/].nil?
203
+ FileUtils.mkdir_p(path)
204
+ path = File.join(path, "index.html")
205
+ end
206
+
207
+ File.open(path, 'w') do |f|
208
+ f.write(self.output)
209
+ end
210
+ end
211
+
212
+ # Convert this post into a Hash for use in Liquid templates.
213
+ #
214
+ # Returns <Hash>
215
+ def to_liquid
216
+ { "title" => self.data["title"] || self.slug.split('-').select {|w| w.capitalize! || w }.join(' '),
217
+ "url" => self.url,
218
+ "date" => self.date,
219
+ "id" => self.id,
220
+ "categories" => self.categories,
221
+ "next" => self.next,
222
+ "previous" => self.previous,
223
+ "tags" => self.tags,
224
+ "content" => self.content }.deep_merge(self.data)
225
+ end
226
+
227
+ def inspect
228
+ "<Post: #{self.id}>"
229
+ end
230
+
231
+ def next
232
+ pos = self.site.posts.index(self)
233
+
234
+ if pos && pos < self.site.posts.length-1
235
+ self.site.posts[pos+1]
236
+ else
237
+ nil
238
+ end
239
+ end
240
+
241
+ def previous
242
+ pos = self.site.posts.index(self)
243
+ if pos && pos > 0
244
+ self.site.posts[pos-1]
245
+ else
246
+ nil
247
+ end
248
+ end
249
+ end
250
+
251
+ end