nirvdrum-jekyll 0.6.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,28 @@
1
+ module Jekyll
2
+
3
+ class StaticFile
4
+ # Initialize a new StaticFile.
5
+ # +site+ is the Site
6
+ # +base+ is the String path to the <source>
7
+ # +dir+ is the String path between <source> and the file
8
+ # +name+ is the String filename of the file
9
+ #
10
+ # Returns <StaticFile>
11
+ def initialize(site, base, dir, name)
12
+ @site = site
13
+ @base = base
14
+ @dir = dir
15
+ @name = name
16
+ end
17
+
18
+ # Write the static file to the destination directory.
19
+ # +dest+ is the String path to the destination dir
20
+ #
21
+ # Returns nothing
22
+ def write(dest)
23
+ FileUtils.mkdir_p(File.join(dest, @dir))
24
+ FileUtils.cp(File.join(@base, @dir, @name), File.join(dest, @dir, @name))
25
+ end
26
+ end
27
+
28
+ end
@@ -23,19 +23,18 @@ module Jekyll
23
23
 
24
24
  def render(context)
25
25
  if context.registers[:site].pygments
26
- render_pygments(context, super.to_s)
26
+ render_pygments(context, super.join)
27
27
  else
28
- render_codehighlighter(context, super.to_s)
28
+ render_codehighlighter(context, super.join)
29
29
  end
30
30
  end
31
31
 
32
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)
33
+ output = add_code_tags(Albino.new(code, @lang).to_s(@options), @lang)
34
+ case context["content_type"]
35
+ when "markdown" then "\n" + output + "\n"
36
+ when "textile" then "<notextile>" + output + "</notextile>"
37
+ else output
39
38
  end
40
39
  end
41
40
 
@@ -49,6 +48,13 @@ module Jekyll
49
48
  </div>
50
49
  HTML
51
50
  end
51
+
52
+ def add_code_tags(code, lang)
53
+ # Add nested <code> tags to code blocks
54
+ code = code.sub(/<pre>/,'<pre><code class="' + lang + '">')
55
+ code = code.sub(/<\/pre>/,"</code></pre>")
56
+ end
57
+
52
58
  end
53
59
 
54
60
  end
@@ -1,5 +1,5 @@
1
1
  require 'rubygems'
2
- gem 'RedCloth', '= 4.2.1'
2
+ gem 'RedCloth', '>= 4.2.1'
3
3
 
4
4
  require File.join(File.dirname(__FILE__), *%w[.. lib jekyll])
5
5
 
@@ -0,0 +1,7 @@
1
+ ---
2
+ layout: default
3
+ title: Category in YAML
4
+ categories:
5
+ ---
6
+
7
+ Best *post* ever
@@ -0,0 +1,7 @@
1
+ ---
2
+ layout: default
3
+ title: Category in YAML
4
+ category:
5
+ ---
6
+
7
+ Best *post* ever
@@ -0,0 +1,6 @@
1
+ ---
2
+ title: A Tag
3
+ tag:
4
+ ---
5
+
6
+ Whoa.
@@ -0,0 +1,6 @@
1
+ ---
2
+ title: Some Tags
3
+ tags:
4
+ ---
5
+
6
+ Awesome!
@@ -0,0 +1,5 @@
1
+ ---
2
+ title: Foo --- Bar
3
+ ---
4
+
5
+ Triple the fun!
@@ -0,0 +1,5 @@
1
+ ---
2
+ date: 2010-01-10
3
+ ---
4
+
5
+ Post with a front matter date
@@ -0,0 +1,5 @@
1
+ ---
2
+ date: 2010-01-10 13:07:09
3
+ ---
4
+
5
+ Post with a front matter time
@@ -8,21 +8,21 @@ class TestConfiguration < Test::Unit::TestCase
8
8
 
9
9
  should "fire warning with no _config.yml" do
10
10
  mock(YAML).load_file(@path) { raise "No such file or directory - #{@path}" }
11
- mock(STDERR).puts("WARNING: Could not read configuration. Using defaults (and options).")
12
- mock(STDERR).puts("\tNo such file or directory - #{@path}")
11
+ mock($stderr).puts("WARNING: Could not read configuration. Using defaults (and options).")
12
+ mock($stderr).puts("\tNo such file or directory - #{@path}")
13
13
  assert_equal Jekyll::DEFAULTS, Jekyll.configuration({})
14
14
  end
15
15
 
16
16
  should "load configuration as hash" do
17
17
  mock(YAML).load_file(@path) { Hash.new }
18
- mock(STDOUT).puts("Configuration from #{@path}")
18
+ mock($stdout).puts("Configuration from #{@path}")
19
19
  assert_equal Jekyll::DEFAULTS, Jekyll.configuration({})
20
20
  end
21
21
 
22
22
  should "fire warning with bad config" do
23
23
  mock(YAML).load_file(@path) { Array.new }
24
- mock(STDERR).puts("WARNING: Could not read configuration. Using defaults (and options).")
25
- mock(STDERR).puts("\tInvalid configuration - #{@path}")
24
+ mock($stderr).puts("WARNING: Could not read configuration. Using defaults (and options).")
25
+ mock($stderr).puts("\tInvalid configuration - #{@path}")
26
26
  assert_equal Jekyll::DEFAULTS, Jekyll.configuration({})
27
27
  end
28
28
  end
@@ -0,0 +1,66 @@
1
+ require File.dirname(__FILE__) + '/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
+ end
@@ -13,6 +13,10 @@ class TestGeneratedSite < Test::Unit::TestCase
13
13
  @index = File.read(dest_dir('index.html'))
14
14
  end
15
15
 
16
+ should "ensure post count is as expected" do
17
+ assert_equal 24, @site.posts.size
18
+ end
19
+
16
20
  should "insert site.posts into the index" do
17
21
  assert @index.include?("#{@site.posts.size} Posts")
18
22
  end
@@ -1,11 +1,38 @@
1
1
  require File.dirname(__FILE__) + '/helper'
2
2
 
3
3
  class TestPager < Test::Unit::TestCase
4
- context "pagination enabled" do
4
+
5
+ should "calculate number of pages" do
6
+ assert_equal(0, Pager.calculate_pages([], '2'))
7
+ assert_equal(1, Pager.calculate_pages([1], '2'))
8
+ assert_equal(1, Pager.calculate_pages([1,2], '2'))
9
+ assert_equal(2, Pager.calculate_pages([1,2,3], '2'))
10
+ assert_equal(2, Pager.calculate_pages([1,2,3,4], '2'))
11
+ assert_equal(3, Pager.calculate_pages([1,2,3,4,5], '2'))
12
+ end
13
+
14
+ context "pagination disabled" do
15
+ setup do
16
+ stub(Jekyll).configuration do
17
+ Jekyll::DEFAULTS.merge({
18
+ 'source' => source_dir,
19
+ 'destination' => dest_dir
20
+ })
21
+ end
22
+ @config = Jekyll.configuration
23
+ end
24
+
25
+ should "report that pagination is disabled" do
26
+ assert !Pager.pagination_enabled?(@config, 'index.html')
27
+ end
28
+
29
+ end
30
+
31
+ context "pagination enabled for 2" do
5
32
  setup do
6
33
  stub(Jekyll).configuration do
7
34
  Jekyll::DEFAULTS.merge({
8
- 'source' => source_dir,
35
+ 'source' => source_dir,
9
36
  'destination' => dest_dir,
10
37
  'paginate' => 2
11
38
  })
@@ -13,35 +40,74 @@ class TestPager < Test::Unit::TestCase
13
40
 
14
41
  @config = Jekyll.configuration
15
42
  @site = Site.new(@config)
16
- @posts = @site.read_posts('')
43
+ @site.process
44
+ @posts = @site.posts
17
45
  end
18
46
 
19
- should "calculate number of pages" do
20
- assert_equal(2, Pager.calculate_pages(@posts, @config['paginate']))
47
+ should "report that pagination is enabled" do
48
+ assert Pager.pagination_enabled?(@config, 'index.html')
21
49
  end
22
50
 
23
- should "create first pager" do
24
- pager = Pager.new(@config, 1, @posts)
25
- assert_equal(@config['paginate'].to_i, pager.posts.size)
26
- assert_equal(2, pager.total_pages)
27
- assert_nil(pager.previous_page)
28
- assert_equal(2, pager.next_page)
29
- end
30
-
31
- should "create second pager" do
32
- pager = Pager.new(@config, 2, @posts)
33
- assert_equal(@posts.size - @config['paginate'].to_i, pager.posts.size)
34
- assert_equal(2, pager.total_pages)
35
- assert_equal(1, pager.previous_page)
36
- assert_nil(pager.next_page)
37
- end
38
-
39
- should "not create third pager" do
40
- assert_raise(RuntimeError) { Pager.new(@config, 3, @posts) }
51
+ context "with 4 posts" do
52
+ setup do
53
+ @posts = @site.posts[1..4] # limit to 4
54
+ end
55
+
56
+ should "create first pager" do
57
+ pager = Pager.new(@config, 1, @posts)
58
+ assert_equal(2, pager.posts.size)
59
+ assert_equal(2, pager.total_pages)
60
+ assert_nil(pager.previous_page)
61
+ assert_equal(2, pager.next_page)
62
+ end
63
+
64
+ should "create second pager" do
65
+ pager = Pager.new(@config, 2, @posts)
66
+ assert_equal(2, pager.posts.size)
67
+ assert_equal(2, pager.total_pages)
68
+ assert_equal(1, pager.previous_page)
69
+ assert_nil(pager.next_page)
70
+ end
71
+
72
+ should "not create third pager" do
73
+ assert_raise(RuntimeError) { Pager.new(@config, 3, @posts) }
74
+ end
75
+
41
76
  end
42
-
43
- should "report that pagination is enabled" do
44
- assert Pager.pagination_enabled?(@config, 'index.html')
77
+
78
+ context "with 5 posts" do
79
+ setup do
80
+ @posts = @site.posts[1..5] # limit to 5
81
+ end
82
+
83
+ should "create first pager" do
84
+ pager = Pager.new(@config, 1, @posts)
85
+ assert_equal(2, pager.posts.size)
86
+ assert_equal(3, pager.total_pages)
87
+ assert_nil(pager.previous_page)
88
+ assert_equal(2, pager.next_page)
89
+ end
90
+
91
+ should "create second pager" do
92
+ pager = Pager.new(@config, 2, @posts)
93
+ assert_equal(2, pager.posts.size)
94
+ assert_equal(3, pager.total_pages)
95
+ assert_equal(1, pager.previous_page)
96
+ assert_equal(3, pager.next_page)
97
+ end
98
+
99
+ should "create third pager" do
100
+ pager = Pager.new(@config, 3, @posts)
101
+ assert_equal(1, pager.posts.size)
102
+ assert_equal(3, pager.total_pages)
103
+ assert_equal(2, pager.previous_page)
104
+ assert_nil(pager.next_page)
105
+ end
106
+
107
+ should "not create fourth pager" do
108
+ assert_raise(RuntimeError) { Pager.new(@config, 4, @posts) }
109
+ end
110
+
45
111
  end
46
112
  end
47
113
  end
@@ -36,6 +36,7 @@ class TestPost < Test::Unit::TestCase
36
36
  end
37
37
 
38
38
  should "keep date, title, and markup type" do
39
+ @post.categories = []
39
40
  @post.process(@fake_file)
40
41
 
41
42
  assert_equal Time.parse("2008-10-19"), @post.date
@@ -77,7 +78,19 @@ class TestPost < Test::Unit::TestCase
77
78
  @post.read_yaml(@source, @real_file)
78
79
 
79
80
  assert_equal({"title" => "Test title", "layout" => "post", "tag" => "Ruby"}, @post.data)
80
- assert_equal "\r\nThis is the content", @post.content
81
+ assert_equal "This is the content", @post.content
82
+ end
83
+ end
84
+
85
+ context "with embedded triple dash" do
86
+ setup do
87
+ @real_file = "2010-01-08-triple-dash.markdown"
88
+ end
89
+ should "consume the embedded dashes" do
90
+ @post.read_yaml(@source, @real_file)
91
+
92
+ assert_equal({"title" => "Foo --- Bar"}, @post.data)
93
+ assert_equal "Triple the fun!", @post.content
81
94
  end
82
95
  end
83
96
 
@@ -118,7 +131,7 @@ class TestPost < Test::Unit::TestCase
118
131
 
119
132
  should "process the url correctly" do
120
133
  assert_equal "/:categories/:year/:month/:day/:title.html", @post.template
121
- assert_equal "/beer/food/2008/10/19/foo-bar.html", @post.url
134
+ assert_equal "/food/beer/2008/10/19/foo-bar.html", @post.url
122
135
  end
123
136
  end
124
137
 
@@ -163,7 +176,7 @@ class TestPost < Test::Unit::TestCase
163
176
  @post.read_yaml(@source, @real_file)
164
177
 
165
178
  assert_equal({"title" => "Foo Bar", "layout" => "default"}, @post.data)
166
- assert_equal "\nh1. {{ page.title }}\n\nBest *post* ever", @post.content
179
+ assert_equal "h1. {{ page.title }}\n\nBest *post* ever", @post.content
167
180
  end
168
181
 
169
182
  should "transform textile" do
@@ -212,6 +225,16 @@ class TestPost < Test::Unit::TestCase
212
225
  assert_equal false, post.published
213
226
  end
214
227
 
228
+ should "recognize date in yaml" do
229
+ post = setup_post("2010-01-09-date-override.textile")
230
+ assert_equal "/2010/01/10/date-override.html", post.url
231
+ end
232
+
233
+ should "recognize time in yaml" do
234
+ post = setup_post("2010-01-09-time-override.textile")
235
+ assert_equal "/2010/01/10/time-override.html", post.url
236
+ end
237
+
215
238
  should "recognize category in yaml" do
216
239
  post = setup_post("2009-01-27-category.textile")
217
240
  assert post.categories.include?('foo')
@@ -224,6 +247,16 @@ class TestPost < Test::Unit::TestCase
224
247
  assert post.categories.include?('baz')
225
248
  end
226
249
 
250
+ should "recognize empty category in yaml" do
251
+ post = setup_post("2009-01-27-empty-category.textile")
252
+ assert_equal [], post.categories
253
+ end
254
+
255
+ should "recognize empty categories in yaml" do
256
+ post = setup_post("2009-01-27-empty-categories.textile")
257
+ assert_equal [], post.categories
258
+ end
259
+
227
260
  should "recognize tag in yaml" do
228
261
  post = setup_post("2009-05-18-tag.textile")
229
262
  assert post.tags.include?('code')
@@ -236,6 +269,16 @@ class TestPost < Test::Unit::TestCase
236
269
  assert post.tags.include?('pizza')
237
270
  end
238
271
 
272
+ should "recognize empty tag in yaml" do
273
+ post = setup_post("2009-05-18-empty-tag.textile")
274
+ assert_equal [], post.tags
275
+ end
276
+
277
+ should "recognize empty tags in yaml" do
278
+ post = setup_post("2009-05-18-empty-tags.textile")
279
+ assert_equal [], post.tags
280
+ end
281
+
239
282
  should "allow no yaml" do
240
283
  post = setup_post("2009-06-22-no-yaml.textile")
241
284
  assert_equal "No YAML.", post.content