henshin 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bin/henshin +149 -73
- data/henshin.gemspec +8 -3
- data/lib/henshin/ext.rb +42 -0
- data/lib/henshin/gen.rb +64 -44
- data/lib/henshin/plugin.rb +4 -0
- data/lib/henshin/plugins/maruku.rb +1 -1
- data/lib/henshin/plugins/sass.rb +9 -8
- data/lib/henshin/plugins/textile.rb +21 -0
- data/lib/henshin/post.rb +8 -6
- data/lib/henshin/site.rb +11 -64
- data/lib/henshin.rb +26 -19
- data/test/helper.rb +4 -1
- data/test/site/_site/2010/10/20-testing-stuff/index.html +2 -2
- data/test/site/_site/css/print.css +10 -24
- data/test/site/_site/index.html +29 -10
- data/test/site/{sass → css}/print.sass +0 -0
- data/test/site/index.html +2 -3
- data/test/site/options.yaml +2 -2
- data/test/site/posts/Testing-Stuff.markdown +2 -2
- data/test/site/posts/Textile-Test.textile +7 -0
- data/test/site/posts/cat/test.markdown +1 -1
- data/test/site/posts/same-date.markdown +7 -0
- data/test/test_gens.rb +33 -0
- data/test/test_henshin.rb +1 -24
- data/test/test_layouts.rb +1 -5
- data/test/test_options.rb +36 -7
- data/test/test_posts.rb +25 -4
- data/test/test_site.rb +36 -0
- metadata +9 -4
data/lib/henshin/site.rb
CHANGED
@@ -26,11 +26,9 @@ module Henshin
|
|
26
26
|
|
27
27
|
##
|
28
28
|
# Read, process, render and write everything
|
29
|
-
|
30
|
-
# @todo Make it take an array as an arg so that only specific files are updated
|
31
|
-
def build( paths=[] )
|
29
|
+
def build
|
32
30
|
self.reset
|
33
|
-
self.read
|
31
|
+
self.read
|
34
32
|
self.process
|
35
33
|
self.render
|
36
34
|
self.write
|
@@ -39,27 +37,10 @@ module Henshin
|
|
39
37
|
|
40
38
|
##
|
41
39
|
# Reads all necessary files and puts them into the necessary arrays
|
42
|
-
def read
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
self.read_others
|
47
|
-
else
|
48
|
-
paths.each do |path|
|
49
|
-
case determine_type( path )
|
50
|
-
when 'post'
|
51
|
-
@posts << Post.new(path, self)
|
52
|
-
when 'layout'
|
53
|
-
path =~ /([a-zA-Z0-9 _-]+)\.([a-zA-Z0-9-]+)/
|
54
|
-
@layouts[$1] = path
|
55
|
-
when 'gen'
|
56
|
-
@gens << Gen.new(path, self)
|
57
|
-
when 'static'
|
58
|
-
@statics << Static.new(path, self)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
end
|
40
|
+
def read
|
41
|
+
self.read_layouts
|
42
|
+
self.read_posts
|
43
|
+
self.read_others
|
63
44
|
end
|
64
45
|
|
65
46
|
# Adds all items in 'layouts' to the layouts array
|
@@ -88,58 +69,24 @@ module Henshin
|
|
88
69
|
items = items.select {|i| !i.include?( File.join(config[:root], r) )}
|
89
70
|
end
|
90
71
|
|
91
|
-
|
92
|
-
ignored.each do |r|
|
93
|
-
items -= [File.join(config[:root], r)]
|
94
|
-
items -= items.select {|i| i.include?( File.join(config[:root], r) )}
|
95
|
-
end
|
96
|
-
|
97
|
-
items -= @posts.collect {|i| i.path}
|
98
|
-
items -= @layouts.collect {|k, v| v}
|
99
|
-
|
100
|
-
gens = items.select {|i| config[:extensions].include?(i.extension) }
|
101
|
-
gens += items.select {|i| File.open(i, "r").read(3) == "---" }
|
102
|
-
|
72
|
+
gens = items.select {|i| i.gen?(self.config)}
|
103
73
|
gens.each do |g|
|
104
74
|
@gens << Gen.new(g, self)
|
105
75
|
end
|
106
76
|
|
107
|
-
|
108
|
-
static = items - @gens.collect {|i| i.path}
|
77
|
+
static = items.select {|i| i.static?(self.config)}
|
109
78
|
static.each do |s|
|
110
79
|
@statics << Static.new(s, self)
|
111
80
|
end
|
81
|
+
|
112
82
|
end
|
113
|
-
|
114
|
-
# Determines whether the file at the path is a post, layout, gen or static
|
115
|
-
#
|
116
|
-
# @param [Array]
|
117
|
-
# @return [String]
|
118
|
-
def determine_type( path )
|
119
|
-
ignored = ['/options.yaml'] + config[:exclude]
|
120
|
-
ignored.collect! {|i| File.join(config[:root], i)}
|
121
|
-
if ignored.include? path
|
122
|
-
return "ignored"
|
123
|
-
end
|
124
|
-
|
125
|
-
if path.include? File.join(config[:root], 'layouts')
|
126
|
-
return "layout"
|
127
|
-
elsif path.include? File.join(config[:root], 'posts')
|
128
|
-
return "post"
|
129
|
-
elsif config[:extensions].include? path.extension
|
130
|
-
return "gen"
|
131
|
-
elsif File.open(path, "r").read(3) == "---"
|
132
|
-
return "gen"
|
133
|
-
else
|
134
|
-
return "static"
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
83
|
+
|
138
84
|
|
139
85
|
##
|
140
86
|
# Processes all of the necessary files
|
141
87
|
def process
|
142
88
|
@posts.each_parallel {|p| p.process}
|
89
|
+
@posts.sort!
|
143
90
|
@gens.each_parallel {|g| g.process}
|
144
91
|
|
145
92
|
self.build_tags
|
data/lib/henshin.rb
CHANGED
@@ -47,17 +47,32 @@ module Henshin
|
|
47
47
|
rescue => e
|
48
48
|
$stderr.puts "\nCould not read configuration, falling back to defaults..."
|
49
49
|
$stderr.puts "-> #{e.to_s}"
|
50
|
-
settings = Defaults
|
50
|
+
settings = Defaults.merge(override)
|
51
51
|
end
|
52
52
|
|
53
|
+
|
54
|
+
|
55
|
+
# find the options for plugins, if any
|
53
56
|
settings.each do |k, v|
|
54
57
|
if settings[:plugins].include? k.to_s
|
55
58
|
settings[:plugin_options][k] = v.to_options
|
56
59
|
end
|
57
60
|
end
|
58
61
|
|
59
|
-
|
60
|
-
|
62
|
+
loaded_plugins = Henshin.load_plugins( settings[:plugins], settings[:root], settings[:plugin_options] )
|
63
|
+
|
64
|
+
settings[:plugins] = {:generators => {}, :layout_parsers => []}
|
65
|
+
loaded_plugins.each do |plugin|
|
66
|
+
if plugin.is_a? Generator
|
67
|
+
plugin.extensions[:input].each do |ext|
|
68
|
+
settings[:plugins][:generators][ext] = plugin
|
69
|
+
end
|
70
|
+
end
|
71
|
+
if plugin.is_a? LayoutParser
|
72
|
+
settings[:plugins][:layout_parsers] << plugin
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
61
76
|
settings
|
62
77
|
end
|
63
78
|
|
@@ -66,7 +81,7 @@ module Henshin
|
|
66
81
|
#
|
67
82
|
# @param [Array] plugins list of plugins to load
|
68
83
|
# @return [Array] list of loaded plugin instances
|
69
|
-
def self.load_plugins( to_load, root,
|
84
|
+
def self.load_plugins( to_load, root, opts={} )
|
70
85
|
plugins = []
|
71
86
|
to_load.each do |l|
|
72
87
|
begin
|
@@ -75,6 +90,13 @@ module Henshin
|
|
75
90
|
require File.join(root, 'plugins/', l)
|
76
91
|
end
|
77
92
|
end
|
93
|
+
|
94
|
+
# pass options to the plugins
|
95
|
+
@registered_plugins.each do |plugin|
|
96
|
+
if plugin.respond_to? :configure
|
97
|
+
plugin.configure( opts[plugin.opts_name] )
|
98
|
+
end
|
99
|
+
end
|
78
100
|
@registered_plugins
|
79
101
|
end
|
80
102
|
|
@@ -84,21 +106,6 @@ module Henshin
|
|
84
106
|
@registered_plugins << plug.new
|
85
107
|
end
|
86
108
|
|
87
|
-
|
88
|
-
# Lists the file extensions the currently loaded plugins use
|
89
|
-
#
|
90
|
-
# @param [Array] plugins array of loaded plugin instances
|
91
|
-
# @return [Array] a list of file extensions
|
92
|
-
def self.extensions( plugins )
|
93
|
-
extensions = []
|
94
|
-
plugins.each do |i|
|
95
|
-
if i.extensions[:input] != []
|
96
|
-
extensions << i.extensions[:input]
|
97
|
-
end
|
98
|
-
end
|
99
|
-
extensions.flatten!
|
100
|
-
end
|
101
|
-
|
102
109
|
|
103
110
|
# @return [String] current version
|
104
111
|
def self.version
|
data/test/helper.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'test/unit'
|
3
3
|
require 'shoulda'
|
4
|
+
require 'rr'
|
4
5
|
|
5
6
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
6
7
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
@@ -8,6 +9,8 @@ require 'henshin'
|
|
8
9
|
|
9
10
|
class Test::Unit::TestCase
|
10
11
|
|
12
|
+
include RR::Adapters::TestUnit
|
13
|
+
|
11
14
|
def root_dir
|
12
15
|
File.join(File.dirname(__FILE__), 'site')
|
13
16
|
end
|
@@ -21,7 +24,7 @@ class Test::Unit::TestCase
|
|
21
24
|
end
|
22
25
|
|
23
26
|
def new_site
|
24
|
-
override = {:root => File.join(File.dirname(__FILE__), 'site')
|
27
|
+
override = {:root => File.join(File.dirname(__FILE__), 'site'), :target => '_site'}
|
25
28
|
config = Henshin.configure(override)
|
26
29
|
Henshin::Site.new(config)
|
27
30
|
end
|
@@ -15,13 +15,13 @@
|
|
15
15
|
|
16
16
|
<li>test</li>
|
17
17
|
|
18
|
-
<li>
|
18
|
+
<li>markdown</li>
|
19
19
|
|
20
20
|
</ul>
|
21
21
|
|
22
22
|
</header>
|
23
23
|
|
24
|
-
<p>So Lorem ipsum dolor sit amet
|
24
|
+
<p>So Lorem ipsum dolor <em>sit amet</em>, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim <strong>ad minim</strong> veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
|
25
25
|
|
26
26
|
<span>Copyright © Joshua Hawxwell</span>
|
27
27
|
</body>
|
@@ -1,33 +1,19 @@
|
|
1
|
-
body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, form, fieldset, input, textarea, p, blockquote, th, td {
|
2
|
-
margin: 0;
|
3
|
-
padding: 0; }
|
1
|
+
body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, form, fieldset, input, textarea, p, blockquote, th, td { margin: 0; padding: 0; }
|
4
2
|
|
5
|
-
table {
|
6
|
-
border-collapse: collapse;
|
7
|
-
border-spacing: 0; }
|
3
|
+
table { border-collapse: collapse; border-spacing: 0; }
|
8
4
|
|
9
|
-
fieldset, img {
|
10
|
-
border: 0; }
|
5
|
+
fieldset, img { border: 0; }
|
11
6
|
|
12
|
-
address, caption, cite, code, dfn, em, strong, th, var {
|
13
|
-
font-style: normal;
|
14
|
-
font-weight: normal; }
|
7
|
+
address, caption, cite, code, dfn, em, strong, th, var { font-style: normal; font-weight: normal; }
|
15
8
|
|
16
|
-
ol, ul {
|
17
|
-
list-style: none; }
|
9
|
+
ol, ul { list-style: none; }
|
18
10
|
|
19
|
-
caption, th {
|
20
|
-
text-align: left; }
|
11
|
+
caption, th { text-align: left; }
|
21
12
|
|
22
|
-
h1, h2, h3, h4, h5, h6 {
|
23
|
-
font-size: 100%;
|
24
|
-
font-weight: normal; }
|
13
|
+
h1, h2, h3, h4, h5, h6 { font-size: 100%; font-weight: normal; }
|
25
14
|
|
26
|
-
q:before, q:after {
|
27
|
-
content: ”; }
|
15
|
+
q:before, q:after { content: ”; }
|
28
16
|
|
29
|
-
abbr, acronym {
|
30
|
-
border: 0; }
|
17
|
+
abbr, acronym { border: 0; }
|
31
18
|
|
32
|
-
h1 {
|
33
|
-
font-size: 2em; }
|
19
|
+
h1 { font-size: 2em; }
|
data/test/site/_site/index.html
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
<body>
|
9
9
|
|
10
10
|
<header>
|
11
|
-
<h1>
|
11
|
+
<h1>Home Page</h1>
|
12
12
|
</header>
|
13
13
|
|
14
14
|
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
|
@@ -21,11 +21,15 @@
|
|
21
21
|
<h2>A List of Posts</h2>
|
22
22
|
<ul>
|
23
23
|
|
24
|
-
<li><a href="/2010/
|
24
|
+
<li><a href="/2010/10/20-testing-stuff/">Testing Stuff</a> - 2010-10-20 17:33:23 +0100</li>
|
25
25
|
|
26
|
-
<li><a href="/2010/5/15-lorem-ipsum/
|
26
|
+
<li><a href="/2010/5/15-lorem-ipsum/">Lorem Ipsum</a> - 2010-05-15 13:23:47 +0100</li>
|
27
27
|
|
28
|
-
<li><a href="/2010/
|
28
|
+
<li><a href="/2010/5/15-same-date-as-lorem-ipsum/">Same Date as "Lorem Ipsum"</a> - 2010-05-15 13:23:47 +0100</li>
|
29
|
+
|
30
|
+
<li><a href="/2009/11/9-textile-test/">Textile Test</a> - 2009-11-09 13:23:47 +0000</li>
|
31
|
+
|
32
|
+
<li><a href="/2009/2/27-test/">Test</a> - 2009-02-27 18:54:02 +0000</li>
|
29
33
|
|
30
34
|
</ul>
|
31
35
|
|
@@ -36,8 +40,21 @@
|
|
36
40
|
test
|
37
41
|
<ul>
|
38
42
|
|
43
|
+
<li>Testing Stuff - 2010-10-20 17:33:23 +0100</li>
|
44
|
+
|
39
45
|
<li>Lorem Ipsum - 2010-05-15 13:23:47 +0100</li>
|
40
46
|
|
47
|
+
<li>Same Date as "Lorem Ipsum" - 2010-05-15 13:23:47 +0100</li>
|
48
|
+
|
49
|
+
<li>Textile Test - 2009-11-09 13:23:47 +0000</li>
|
50
|
+
|
51
|
+
</ul>
|
52
|
+
</li>
|
53
|
+
|
54
|
+
<li>
|
55
|
+
markdown
|
56
|
+
<ul>
|
57
|
+
|
41
58
|
<li>Testing Stuff - 2010-10-20 17:33:23 +0100</li>
|
42
59
|
|
43
60
|
</ul>
|
@@ -49,14 +66,16 @@
|
|
49
66
|
|
50
67
|
<li>Lorem Ipsum - 2010-05-15 13:23:47 +0100</li>
|
51
68
|
|
69
|
+
<li>Same Date as "Lorem Ipsum" - 2010-05-15 13:23:47 +0100</li>
|
70
|
+
|
52
71
|
</ul>
|
53
72
|
</li>
|
54
73
|
|
55
74
|
<li>
|
56
|
-
|
75
|
+
plugin
|
57
76
|
<ul>
|
58
77
|
|
59
|
-
<li>
|
78
|
+
<li>Textile Test - 2009-11-09 13:23:47 +0000</li>
|
60
79
|
|
61
80
|
</ul>
|
62
81
|
</li>
|
@@ -66,17 +85,17 @@
|
|
66
85
|
<h2>A List of Categories</h2>
|
67
86
|
<ul>
|
68
87
|
|
69
|
-
<li>
|
88
|
+
<li>test</li>
|
70
89
|
<ul>
|
71
90
|
|
72
|
-
<li>
|
91
|
+
<li>Testing Stuff - 2010-10-20 17:33:23 +0100</li>
|
73
92
|
|
74
93
|
</ul>
|
75
94
|
|
76
|
-
<li>
|
95
|
+
<li>cat</li>
|
77
96
|
<ul>
|
78
97
|
|
79
|
-
<li>
|
98
|
+
<li>Test - 2009-02-27 18:54:02 +0000</li>
|
80
99
|
|
81
100
|
</ul>
|
82
101
|
|
File without changes
|
data/test/site/index.html
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
---
|
2
2
|
layout: main
|
3
|
-
title:
|
4
|
-
date: 2009-10-07T17:17:45+00:00
|
3
|
+
title: Home Page
|
5
4
|
---
|
6
5
|
|
7
6
|
|
8
7
|
<header>
|
9
|
-
<h1>
|
8
|
+
<h1>Home Page</h1>
|
10
9
|
</header>
|
11
10
|
|
12
11
|
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
|
data/test/site/options.yaml
CHANGED
@@ -5,10 +5,10 @@ author: Joshua Hawxwell
|
|
5
5
|
|
6
6
|
layout: post
|
7
7
|
|
8
|
-
exclude: [
|
8
|
+
exclude: []
|
9
9
|
post_name: '{title-with-dashes}.{extension}'
|
10
10
|
permalink: '/{year}/{month}/{date}-{title}/index.html'
|
11
|
-
plugins: [maruku, sass, pygments, liquid, test]
|
11
|
+
plugins: [maruku, sass, pygments, liquid, test, textile]
|
12
12
|
|
13
13
|
sass:
|
14
14
|
style: :compact
|
@@ -1,8 +1,8 @@
|
|
1
1
|
---
|
2
2
|
title: Testing Stuff
|
3
3
|
date: 2010-10-20 at 17:33:23
|
4
|
-
tags: test,
|
4
|
+
tags: test, markdown
|
5
5
|
category: test
|
6
6
|
---
|
7
7
|
|
8
|
-
So Lorem ipsum dolor sit amet
|
8
|
+
So Lorem ipsum dolor *sit amet*, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim __ad minim__ veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
title: Textile Test
|
3
|
+
date: 2009-11-09 at 13:23:47
|
4
|
+
tags: test, plugin
|
5
|
+
---
|
6
|
+
|
7
|
+
So Lorem ipsum dolor sit _amet, consectetur_ adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris *nisi ut aliquip* ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
title: Same Date as "Lorem Ipsum"
|
3
|
+
date: 2010-05-15 at 13:23:47
|
4
|
+
tags: test, lorem
|
5
|
+
---
|
6
|
+
|
7
|
+
So Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
data/test/test_gens.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__) ,'helper')
|
2
|
+
|
3
|
+
class TestGens < Test::Unit::TestCase
|
4
|
+
context "A gen" do
|
5
|
+
|
6
|
+
setup do
|
7
|
+
@site = new_site
|
8
|
+
@gen = Henshin::Gen.new( "#{root_dir}/index.html", @site )
|
9
|
+
remove_site
|
10
|
+
end
|
11
|
+
|
12
|
+
should "read frontmatter" do
|
13
|
+
@site.read_layouts
|
14
|
+
@gen.read_yaml
|
15
|
+
assert_equal @gen.title, 'Home Page'
|
16
|
+
assert_equal @gen.layout, "#{root_dir}/layouts/main.html"
|
17
|
+
end
|
18
|
+
|
19
|
+
should "have the correct permalink" do
|
20
|
+
@gen.read_yaml
|
21
|
+
assert_equal @gen.permalink, '/index.html'
|
22
|
+
assert_equal @gen.url, '/'
|
23
|
+
end
|
24
|
+
|
25
|
+
should "allow a hash to be added to the payload" do
|
26
|
+
payload = { :name => 'people', :payload => {'fname' => 'John', 'sname' => 'Doe'} }
|
27
|
+
gen = Henshin::Gen.new( "#{root_dir}/index.html", @site, payload )
|
28
|
+
gen.read_yaml
|
29
|
+
assert_equal gen.payload['people'], payload[:payload]
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
data/test/test_henshin.rb
CHANGED
@@ -1,28 +1,5 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__) ,'helper')
|
2
2
|
|
3
|
-
class TestHenshin < Test::Unit::TestCase
|
4
|
-
context "Building sites" do
|
5
|
-
|
6
|
-
setup do
|
7
|
-
@site = new_site
|
8
|
-
end
|
9
|
-
|
10
|
-
should "reset all data before anything else" do
|
11
|
-
remove_site
|
12
|
-
@site.reset
|
13
|
-
|
14
|
-
assert_equal @site.posts.length, 0
|
15
|
-
assert_equal @site.gens.length, 0
|
16
|
-
assert_equal @site.statics.length, 0
|
17
|
-
assert_equal @site.archive.length, 0
|
18
|
-
assert_equal @site.tags.length, 0
|
19
|
-
assert_equal @site.categories.length, 0
|
20
|
-
assert_equal @site.layouts.length, 0
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
|
27
3
|
test_files = Dir.glob( File.join(File.dirname(__FILE__), "test_*.rb") )
|
4
|
+
test_files -= [File.join(File.dirname(__FILE__), 'test_henshin.rb')] # don't include self!
|
28
5
|
test_files.each {|f| require f }
|
data/test/test_layouts.rb
CHANGED
data/test/test_options.rb
CHANGED
@@ -1,27 +1,56 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__) ,'helper')
|
2
2
|
|
3
|
+
# Need to remember to remove loaded plugins from the returned
|
4
|
+
# config when comparing against Defaults!
|
3
5
|
class TestOptions < Test::Unit::TestCase
|
4
6
|
context "Loading and setting options" do
|
5
7
|
|
6
8
|
setup do
|
7
|
-
@opts =
|
9
|
+
@opts = './options.yaml'
|
8
10
|
end
|
9
11
|
|
10
12
|
should "warn of invalid options.yaml" do
|
11
|
-
|
13
|
+
mock(YAML).load_file(@opts) {"boo"}
|
14
|
+
mock($stderr).puts("\nCould not read configuration, falling back to defaults...")
|
15
|
+
mock($stderr).puts("-> undefined method `to_options' for \"boo\":String")
|
16
|
+
|
17
|
+
configured = Henshin.configure
|
18
|
+
configured[:plugins] = ["maruku", "liquid"]
|
19
|
+
assert_equal Henshin::Defaults, configured
|
12
20
|
end
|
13
21
|
|
14
22
|
should "warn of no options.yaml" do
|
15
|
-
|
23
|
+
mock(YAML).load_file(@opts) { raise "No such file or directory - #{@opts}" }
|
24
|
+
mock($stderr).puts("\nCould not read configuration, falling back to defaults...")
|
25
|
+
mock($stderr).puts("-> No such file or directory - #{@opts}")
|
26
|
+
|
27
|
+
configured = Henshin.configure
|
28
|
+
configured[:plugins] = ["maruku", "liquid"]
|
29
|
+
assert_equal Henshin::Defaults, configured
|
16
30
|
end
|
17
|
-
|
31
|
+
|
18
32
|
should "use defaults if no options.yaml" do
|
19
|
-
|
33
|
+
mock($stderr).puts("\nCould not read configuration, falling back to defaults...")
|
34
|
+
mock($stderr).puts("-> No such file or directory - #{@opts}")
|
35
|
+
|
36
|
+
configured = Henshin.configure
|
37
|
+
configured[:plugins] = ["maruku", "liquid"]
|
38
|
+
assert_equal Henshin::Defaults, configured
|
20
39
|
end
|
21
40
|
|
22
|
-
should "
|
41
|
+
should "merge override with defaults" do
|
42
|
+
mock($stderr).puts("\nCould not read configuration, falling back to defaults...")
|
43
|
+
mock($stderr).puts("-> No such file or directory - #{@opts}")
|
44
|
+
|
45
|
+
override = {:time_zone => '+01:00'}
|
46
|
+
configured = Henshin.configure(override)
|
47
|
+
assert_equal configured[:time_zone], '+01:00'
|
48
|
+
end
|
23
49
|
|
50
|
+
should "load plugins" do
|
51
|
+
loaded = Henshin.load_plugins( ['maruku'], '.', {} )
|
52
|
+
assert loaded[0].is_a? MarukuPlugin
|
24
53
|
end
|
25
|
-
|
54
|
+
|
26
55
|
end
|
27
56
|
end
|
data/test/test_posts.rb
CHANGED
@@ -8,10 +8,31 @@ class TestPosts < Test::Unit::TestCase
|
|
8
8
|
remove_site
|
9
9
|
end
|
10
10
|
|
11
|
-
should "
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
should "get data from the filename" do
|
12
|
+
post_file = "#{root_dir}/posts/2010-08-10-lorem-ipsum.markdown"
|
13
|
+
site = @site
|
14
|
+
site.config[:file_name] = "{date}-{title-with-dashes}.{extension}"
|
15
|
+
post = Henshin::Post.new( post_file, site )
|
16
|
+
post.read_name
|
17
|
+
assert_equal post.title, 'lorem ipsum'
|
18
|
+
assert_equal post.date, Time.parse('2010-08-10')
|
19
|
+
assert_equal post.extension, 'markdown'
|
20
|
+
end
|
21
|
+
|
22
|
+
should "read frontmatter" do
|
23
|
+
post_file = "#{root_dir}/posts/lorem-ipsum.markdown"
|
24
|
+
post = Henshin::Post.new( post_file, @site )
|
25
|
+
post.read_yaml
|
26
|
+
assert_equal post.title, 'Lorem Ipsum'
|
27
|
+
assert_equal post.date, Time.parse('2010-05-15 at 13:23:47')
|
28
|
+
assert_equal post.tags, ['test', 'lorem']
|
29
|
+
end
|
30
|
+
|
31
|
+
should "have the correct permalink" do
|
32
|
+
post_file = "#{root_dir}/posts/lorem-ipsum.markdown"
|
33
|
+
post = Henshin::Post.new( post_file, @site )
|
34
|
+
post.process
|
35
|
+
assert_equal post.permalink, "/2010/5/15-lorem-ipsum/index.html"
|
15
36
|
end
|
16
37
|
|
17
38
|
end
|
data/test/test_site.rb
CHANGED
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__) ,'helper')
|
2
|
+
|
3
|
+
class TestSite < Test::Unit::TestCase
|
4
|
+
context "Building sites" do
|
5
|
+
|
6
|
+
setup do
|
7
|
+
@site = new_site
|
8
|
+
end
|
9
|
+
|
10
|
+
should "reset all data before anything else" do
|
11
|
+
remove_site
|
12
|
+
@site.reset
|
13
|
+
|
14
|
+
assert_equal @site.posts.length, 0
|
15
|
+
assert_equal @site.gens.length, 0
|
16
|
+
assert_equal @site.statics.length, 0
|
17
|
+
assert_equal @site.archive.length, 0
|
18
|
+
assert_equal @site.tags.length, 0
|
19
|
+
assert_equal @site.categories.length, 0
|
20
|
+
assert_equal @site.layouts.length, 0
|
21
|
+
end
|
22
|
+
|
23
|
+
should "read posts" do
|
24
|
+
@site.read_posts
|
25
|
+
p = Dir.glob( File.join(root_dir, 'posts', '**', '*.*') )
|
26
|
+
assert_equal p.size, @site.posts.size
|
27
|
+
end
|
28
|
+
|
29
|
+
should "read layouts" do
|
30
|
+
@site.read_layouts
|
31
|
+
l = Dir.glob( File.join(root_dir, 'layouts', '*.*') )
|
32
|
+
assert_equal l.size, @site.layouts.size
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|