henshin 0.2.0 → 0.2.1
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.
- data/VERSION +1 -1
- data/henshin.gemspec +12 -4
- data/lib/henshin.rb +18 -9
- data/lib/henshin/categories.rb +6 -1
- data/lib/henshin/gen.rb +5 -0
- data/lib/henshin/plugin.rb +13 -6
- data/lib/henshin/plugins/liquid.rb +2 -1
- data/lib/henshin/plugins/maruku.rb +2 -1
- data/lib/henshin/plugins/pygments.rb +2 -1
- data/lib/henshin/plugins/sass.rb +1 -0
- data/lib/henshin/site.rb +49 -9
- data/lib/henshin/static.rb +5 -0
- data/lib/henshin/tags.rb +6 -1
- data/test/helper.rb +19 -0
- data/test/test_henshin.rb +24 -3
- data/test/test_layouts.rb +18 -0
- data/test/test_options.rb +27 -0
- data/test/test_posts.rb +18 -0
- data/test/test_site.rb +0 -0
- metadata +11 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
data/henshin.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{henshin}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["hawx"]
|
12
|
-
s.date = %q{2010-05-
|
12
|
+
s.date = %q{2010-05-31}
|
13
13
|
s.default_executable = %q{henshin}
|
14
14
|
s.description = %q{Henshin is a static site generator, with a plugin system and more}
|
15
15
|
s.email = %q{m@hawx.me}
|
@@ -60,7 +60,11 @@ Gem::Specification.new do |s|
|
|
60
60
|
"test/site/posts/lorem-ipsum.markdown",
|
61
61
|
"test/site/sass/print.sass",
|
62
62
|
"test/site/static.html",
|
63
|
-
"test/test_henshin.rb"
|
63
|
+
"test/test_henshin.rb",
|
64
|
+
"test/test_layouts.rb",
|
65
|
+
"test/test_options.rb",
|
66
|
+
"test/test_posts.rb",
|
67
|
+
"test/test_site.rb"
|
64
68
|
]
|
65
69
|
s.homepage = %q{http://github.com/hawx/henshin}
|
66
70
|
s.rdoc_options = ["--charset=UTF-8"]
|
@@ -70,7 +74,11 @@ Gem::Specification.new do |s|
|
|
70
74
|
s.test_files = [
|
71
75
|
"test/helper.rb",
|
72
76
|
"test/site/plugins/test.rb",
|
73
|
-
"test/test_henshin.rb"
|
77
|
+
"test/test_henshin.rb",
|
78
|
+
"test/test_layouts.rb",
|
79
|
+
"test/test_options.rb",
|
80
|
+
"test/test_posts.rb",
|
81
|
+
"test/test_site.rb"
|
74
82
|
]
|
75
83
|
|
76
84
|
if s.respond_to? :specification_version then
|
data/lib/henshin.rb
CHANGED
@@ -27,7 +27,7 @@ module Henshin
|
|
27
27
|
:layout => '',
|
28
28
|
:file_name => '<{category}/>{title-with-dashes}.{extension}',
|
29
29
|
:permalink => '/{year}/{month}/{date}/{title}.html',
|
30
|
-
:plugins => ['
|
30
|
+
:plugins => ['maruku', 'liquid'],
|
31
31
|
:root => '.',
|
32
32
|
:target => '_site',
|
33
33
|
:plugin_options => {},
|
@@ -40,9 +40,15 @@ module Henshin
|
|
40
40
|
# @return [Hash] the merged configuration hash
|
41
41
|
def self.configure( override={} )
|
42
42
|
config_file = (override[:root] || Defaults[:root]) + '/options.yaml'
|
43
|
-
config = YAML.load_file( config_file ).to_options
|
44
43
|
|
45
|
-
|
44
|
+
begin
|
45
|
+
config = YAML.load_file( config_file ).to_options
|
46
|
+
settings = Defaults.merge(config).merge(override)
|
47
|
+
rescue => e
|
48
|
+
$stderr.puts "\nCould not read configuration, falling back to defaults..."
|
49
|
+
$stderr.puts "-> #{e.to_s}"
|
50
|
+
settings = Defaults
|
51
|
+
end
|
46
52
|
|
47
53
|
settings.each do |k, v|
|
48
54
|
if settings[:plugins].include? k.to_s
|
@@ -63,15 +69,19 @@ module Henshin
|
|
63
69
|
def self.load_plugins( to_load, root, options )
|
64
70
|
plugins = []
|
65
71
|
to_load.each do |l|
|
66
|
-
p
|
67
72
|
begin
|
68
73
|
require 'henshin/plugins/' + l
|
69
74
|
rescue LoadError
|
70
75
|
require File.join(root, 'plugins/', l)
|
71
76
|
end
|
72
|
-
plugins << eval("#{l.capitalize}Plugin.new( #{options[l.to_sym]} )")
|
73
77
|
end
|
74
|
-
|
78
|
+
@registered_plugins
|
79
|
+
end
|
80
|
+
|
81
|
+
# Each plugin will call this method when loaded from #load_plugins, these plugins then populate @registered_plugins, which is returned from #load_plugins. Complicated? Maybe, but it works!
|
82
|
+
def self.register!( plug )
|
83
|
+
@registered_plugins ||= []
|
84
|
+
@registered_plugins << plug.new
|
75
85
|
end
|
76
86
|
|
77
87
|
|
@@ -89,9 +99,8 @@ module Henshin
|
|
89
99
|
extensions.flatten!
|
90
100
|
end
|
91
101
|
|
92
|
-
|
93
|
-
|
94
|
-
|
102
|
+
|
103
|
+
# @return [String] current version
|
95
104
|
def self.version
|
96
105
|
File.read( File.join(File.dirname(__FILE__), *%w[.. VERSION]) )
|
97
106
|
end
|
data/lib/henshin/categories.rb
CHANGED
data/lib/henshin/gen.rb
CHANGED
data/lib/henshin/plugin.rb
CHANGED
@@ -4,9 +4,7 @@ module Henshin
|
|
4
4
|
#
|
5
5
|
# class MyPlugin < NoName::StandardPlugin
|
6
6
|
#
|
7
|
-
# or it can inherit a subclass from below
|
8
|
-
#
|
9
|
-
# This is quite useful if a dummy plugin is needed
|
7
|
+
# or it can (and should) inherit a subclass from below
|
10
8
|
|
11
9
|
attr_accessor :extensions, :config
|
12
10
|
|
@@ -17,23 +15,32 @@ module Henshin
|
|
17
15
|
:output => ''}
|
18
16
|
@config = {}
|
19
17
|
end
|
18
|
+
|
19
|
+
# Uncomment to have the plugin loaded
|
20
|
+
# Henshin.register! self
|
20
21
|
end
|
21
22
|
|
22
23
|
class Generator < StandardPlugin
|
23
24
|
# a plugin which returns anything*
|
24
25
|
|
25
26
|
def generate( content )
|
26
|
-
# return
|
27
|
+
# return string
|
27
28
|
end
|
29
|
+
|
30
|
+
# Uncomment to have the plugin loaded
|
31
|
+
# Henshin.register! self
|
28
32
|
end
|
29
33
|
|
30
34
|
class LayoutParser < StandardPlugin
|
31
35
|
# a plugin which returns anything*
|
32
|
-
# given a layout and data to insert
|
33
36
|
|
37
|
+
# given a layout and data to insert
|
34
38
|
def generate( layout, data )
|
35
|
-
# return
|
39
|
+
# return string
|
36
40
|
end
|
41
|
+
|
42
|
+
# Uncomment to have the plugin loaded
|
43
|
+
# Henshin.register! self
|
37
44
|
end
|
38
45
|
|
39
46
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'henshin/plugin'
|
2
2
|
require 'maruku'
|
3
3
|
|
4
|
-
class
|
4
|
+
class MarukuPlug < Henshin::Generator
|
5
5
|
|
6
6
|
attr_accessor :extensions, :config
|
7
7
|
|
@@ -17,4 +17,5 @@ class MarukuPlugin < Henshin::Generator
|
|
17
17
|
Maruku.new(content).to_html
|
18
18
|
end
|
19
19
|
|
20
|
+
Henshin.register! self
|
20
21
|
end
|
data/lib/henshin/plugins/sass.rb
CHANGED
data/lib/henshin/site.rb
CHANGED
@@ -28,9 +28,9 @@ module Henshin
|
|
28
28
|
# Read, process, render and write everything
|
29
29
|
#
|
30
30
|
# @todo Make it take an array as an arg so that only specific files are updated
|
31
|
-
def build
|
31
|
+
def build( paths=[] )
|
32
32
|
self.reset
|
33
|
-
self.read
|
33
|
+
self.read( paths )
|
34
34
|
self.process
|
35
35
|
self.render
|
36
36
|
self.write
|
@@ -39,11 +39,27 @@ module Henshin
|
|
39
39
|
|
40
40
|
##
|
41
41
|
# Reads all necessary files and puts them into the necessary arrays
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
42
|
+
def read( paths=[] )
|
43
|
+
if paths == []
|
44
|
+
self.read_layouts
|
45
|
+
self.read_posts
|
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
|
47
63
|
end
|
48
64
|
|
49
65
|
# Adds all items in 'layouts' to the layouts array
|
@@ -95,6 +111,30 @@ module Henshin
|
|
95
111
|
end
|
96
112
|
end
|
97
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
|
+
|
98
138
|
|
99
139
|
##
|
100
140
|
# Processes all of the necessary files
|
@@ -171,7 +211,7 @@ module Henshin
|
|
171
211
|
self.write_categories
|
172
212
|
end
|
173
213
|
|
174
|
-
|
214
|
+
# Writes the necessary pages for tags, but only if the correct layouts are present
|
175
215
|
def write_tags
|
176
216
|
if @layouts['tag_index']
|
177
217
|
write_path = File.join( config[:root], 'tags', 'index.html' )
|
@@ -197,6 +237,7 @@ module Henshin
|
|
197
237
|
end
|
198
238
|
end
|
199
239
|
|
240
|
+
# Writes the necessary pages for categories, but only if the correct layouts are present
|
200
241
|
def write_categories
|
201
242
|
if @layouts['category_index']
|
202
243
|
write_path = File.join( config[:root], 'categories', 'index.html' )
|
@@ -223,5 +264,4 @@ module Henshin
|
|
223
264
|
end
|
224
265
|
|
225
266
|
end
|
226
|
-
|
227
267
|
end
|
data/lib/henshin/static.rb
CHANGED
data/lib/henshin/tags.rb
CHANGED
data/test/helper.rb
CHANGED
@@ -7,4 +7,23 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
7
7
|
require 'henshin'
|
8
8
|
|
9
9
|
class Test::Unit::TestCase
|
10
|
+
|
11
|
+
def root_dir
|
12
|
+
File.join(File.dirname(__FILE__), 'site')
|
13
|
+
end
|
14
|
+
|
15
|
+
def target_dir
|
16
|
+
"_site"
|
17
|
+
end
|
18
|
+
|
19
|
+
def remove_site
|
20
|
+
FileUtils.rm_rf(File.join(root_dir, target_dir))
|
21
|
+
end
|
22
|
+
|
23
|
+
def new_site
|
24
|
+
override = {:root => File.join(File.dirname(__FILE__), 'site'),:target => '_site'}
|
25
|
+
config = Henshin.configure(override)
|
26
|
+
Henshin::Site.new(config)
|
27
|
+
end
|
28
|
+
|
10
29
|
end
|
data/test/test_henshin.rb
CHANGED
@@ -1,7 +1,28 @@
|
|
1
|
-
require 'helper'
|
1
|
+
require File.join(File.dirname(__FILE__) ,'helper')
|
2
2
|
|
3
3
|
class TestHenshin < Test::Unit::TestCase
|
4
|
-
|
5
|
-
|
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
|
+
|
6
23
|
end
|
7
24
|
end
|
25
|
+
|
26
|
+
|
27
|
+
test_files = Dir.glob( File.join(File.dirname(__FILE__), "test_*.rb") )
|
28
|
+
test_files.each {|f| require f }
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__) ,'helper')
|
2
|
+
|
3
|
+
class TestLayouts < Test::Unit::TestCase
|
4
|
+
context "A layout" do
|
5
|
+
|
6
|
+
setup do
|
7
|
+
@site = new_site
|
8
|
+
remove_site
|
9
|
+
end
|
10
|
+
|
11
|
+
should "read layouts" do
|
12
|
+
@site.read_layouts
|
13
|
+
l = Dir.glob( File.join(root_dir, 'layouts', '*.*') )
|
14
|
+
assert_equal l.size, @site.layouts.size
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__) ,'helper')
|
2
|
+
|
3
|
+
class TestOptions < Test::Unit::TestCase
|
4
|
+
context "Loading and setting options" do
|
5
|
+
|
6
|
+
setup do
|
7
|
+
@opts = File.join(root_dir, 'options.yaml')
|
8
|
+
end
|
9
|
+
|
10
|
+
should "warn of invalid options.yaml" do
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
should "warn of no options.yaml" do
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
should "use defaults if no options.yaml" do
|
19
|
+
assert_equal Henshin::Defaults, Henshin.configure
|
20
|
+
end
|
21
|
+
|
22
|
+
should "load options and merge with defaults" do
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
data/test/test_posts.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__) ,'helper')
|
2
|
+
|
3
|
+
class TestPosts < Test::Unit::TestCase
|
4
|
+
context "A post" do
|
5
|
+
|
6
|
+
setup do
|
7
|
+
@site = new_site
|
8
|
+
remove_site
|
9
|
+
end
|
10
|
+
|
11
|
+
should "read posts" do
|
12
|
+
@site.read_posts
|
13
|
+
p = Dir.glob( File.join(root_dir, 'posts', '**', '*.*') )
|
14
|
+
assert_equal p.size, @site.posts.size
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
data/test/test_site.rb
ADDED
File without changes
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 1
|
9
|
+
version: 0.2.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- hawx
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-05-
|
17
|
+
date: 2010-05-31 00:00:00 +01:00
|
18
18
|
default_executable: henshin
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -93,6 +93,10 @@ files:
|
|
93
93
|
- test/site/sass/print.sass
|
94
94
|
- test/site/static.html
|
95
95
|
- test/test_henshin.rb
|
96
|
+
- test/test_layouts.rb
|
97
|
+
- test/test_options.rb
|
98
|
+
- test/test_posts.rb
|
99
|
+
- test/test_site.rb
|
96
100
|
has_rdoc: true
|
97
101
|
homepage: http://github.com/hawx/henshin
|
98
102
|
licenses: []
|
@@ -127,3 +131,7 @@ test_files:
|
|
127
131
|
- test/helper.rb
|
128
132
|
- test/site/plugins/test.rb
|
129
133
|
- test/test_henshin.rb
|
134
|
+
- test/test_layouts.rb
|
135
|
+
- test/test_options.rb
|
136
|
+
- test/test_posts.rb
|
137
|
+
- test/test_site.rb
|