henshin 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.2.0
@@ -11,8 +11,23 @@ EOS
11
11
 
12
12
 
13
13
  override = {}
14
+ build = {:server => false, :auto => false}
14
15
  opts = OptionParser.new do |opts|
15
16
  opts.banner = banner
17
+
18
+ opts.on("--server", "-s", "Start server") do
19
+ build[:server] = true
20
+ end
21
+
22
+ opts.on("--auto", "-a", "Auto regenerate files") do
23
+ build[:auto] = true
24
+ end
25
+
26
+ opts.on("--version", "Display current version of Henshin") do
27
+ puts "Henshin #{Henshin.version}"
28
+ exit 0
29
+ end
30
+
16
31
  end
17
32
  opts.parse!
18
33
 
@@ -25,13 +40,60 @@ end
25
40
  config = Henshin.configure(override)
26
41
  site = Henshin::Site.new(config)
27
42
 
28
- puts "Reading files..."
29
- site.read
30
43
 
31
- site.process
32
- site.render
44
+ # build normally
45
+ puts "Building site..."
46
+ site.build
47
+ puts "Site created in #{config[:target]}"
48
+
49
+
50
+ # regenerate files when changed
51
+ if build[:auto]
52
+ require 'directory_watcher'
53
+
54
+ puts "", "Auto-build initiated..."
55
+
56
+ # build the glob pattern
57
+ gl = Dir[ File.join(config[:root], '*')].select { |x| File.directory?(x) }
58
+ ['/_site', '/plugins'].each do |r|
59
+ gl = gl.select {|i| !i.include?( File.join(config[:root], r) )}
60
+ end
61
+ gl.collect! {|x| "#{x}/**/*"}
62
+ gl += ['*']
63
+
64
+ dw = DirectoryWatcher.new config[:root], :glob => gl
65
+ dw.interval = 2.0
66
+ dw.add_observer do |*args|
67
+ if args.size > 1
68
+ puts "rebuilding -> #{args.size} files"
69
+ else
70
+ puts "rebuilding -> #{args[0].path}"
71
+ end
72
+ site.build
73
+ end
74
+
75
+ dw.start
76
+
77
+ unless build[:server]
78
+ loop {sleep 1000}
79
+ end
80
+ end
81
+
82
+
83
+ # start a server
84
+ if build[:server]
85
+ require 'webrick'
86
+
87
+ server = WEBrick::HTTPServer.new(
88
+ :Port => '3000',
89
+ :DocumentRoot => File.join(config[:root], config[:target]),
90
+ :MimeTypes => WEBrick::HTTPUtils::DefaultMimeTypes
91
+ )
92
+
93
+ thread = Thread.new { server.start }
94
+ trap("INT") { server.shutdown }
95
+
96
+ thread.join()
97
+ end
33
98
 
34
- puts "Writing files..."
35
- site.write
36
99
 
37
- puts "Site created in #{config[:target]}"
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{henshin}
8
- s.version = "0.1.3"
8
+ s.version = "0.2.0"
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-27}
12
+ s.date = %q{2010-05-30}
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}
@@ -47,8 +47,12 @@ Gem::Specification.new do |s|
47
47
  "test/site/_site/static.html",
48
48
  "test/site/css/screen.css",
49
49
  "test/site/index.html",
50
+ "test/site/layouts/category_index.html",
51
+ "test/site/layouts/category_page.html",
50
52
  "test/site/layouts/main.html",
51
53
  "test/site/layouts/post.html",
54
+ "test/site/layouts/tag_index.html",
55
+ "test/site/layouts/tag_page.html",
52
56
  "test/site/options.yaml",
53
57
  "test/site/plugins/test.rb",
54
58
  "test/site/posts/Testing-Stuff.markdown",
@@ -81,10 +81,19 @@ module Henshin
81
81
  # @return [Array] a list of file extensions
82
82
  def self.extensions( plugins )
83
83
  extensions = []
84
- plugins.each do |i|
85
- extensions << i.extensions
84
+ plugins.each do |i|
85
+ if i.extensions[:input] != []
86
+ extensions << i.extensions[:input]
87
+ end
86
88
  end
87
89
  extensions.flatten!
88
90
  end
91
+
92
+
93
+
94
+
95
+ def self.version
96
+ File.read( File.join(File.dirname(__FILE__), *%w[.. VERSION]) )
97
+ end
89
98
 
90
99
  end
@@ -4,13 +4,14 @@ module Henshin
4
4
  class Gen
5
5
 
6
6
  attr_accessor :path, :extension, :content, :layout, :date, :title
7
- attr_accessor :site, :config, :renderer
7
+ attr_accessor :site, :config, :renderer, :data
8
8
 
9
- def initialize( path, site )
9
+ def initialize( path, site, data={} )
10
10
  @path = path
11
11
  @site = site
12
12
  @config = site.config
13
13
  @extension = path.extension
14
+ @data = data
14
15
  end
15
16
 
16
17
 
@@ -47,7 +48,7 @@ module Henshin
47
48
  def render
48
49
  # render the posts content
49
50
  config[:plugins].each do |plugin|
50
- if plugin.extensions.include?( @extension ) && !plugin.is_a?( LayoutParser )
51
+ if plugin.extensions[:input].include?( @extension ) && plugin.is_a?( Generator )
51
52
  @content = plugin.generate( @content )
52
53
  @renderer = plugin
53
54
  end
@@ -65,14 +66,22 @@ module Henshin
65
66
  end
66
67
  end
67
68
 
68
- # Creates the data to be sent to the layout engine
69
+ # Creates the data to be sent to the layout engine. Uses optional data if available
69
70
  #
70
71
  # @return [Hash] the payload for the layout engine
71
72
  def payload
72
- {
73
- 'yield' => @content,
74
- 'site' => @site.payload['site']
75
- }
73
+ if @data == {}
74
+ {
75
+ 'yield' => @content,
76
+ 'site' => @site.payload['site']
77
+ }
78
+ else
79
+ {
80
+ 'yield' => @content,
81
+ 'site' => @site.payload['site'],
82
+ @data[:name] => @data[:payload]
83
+ }
84
+ end
76
85
  end
77
86
 
78
87
 
@@ -88,8 +97,8 @@ module Henshin
88
97
  write_path.gsub!("/#{@renderer.config[:root]}", "/#{@renderer.config[:target]}")
89
98
  end
90
99
 
91
- render_type = @renderer.config[:file_type] if @renderer
92
- if render_type
100
+ render_type = @renderer.extensions[:output] if @renderer
101
+ if render_type != ''
93
102
  # files should have different extension
94
103
  write_path.gsub!(".#{@extension}", ".#{render_type}")
95
104
  end
@@ -5,47 +5,34 @@ module Henshin
5
5
  # class MyPlugin < NoName::StandardPlugin
6
6
  #
7
7
  # or it can inherit a subclass from below
8
-
8
+ #
9
9
  # This is quite useful if a dummy plugin is needed
10
10
 
11
11
  attr_accessor :extensions, :config
12
12
 
13
13
  def initialize
14
- @extensions = []
14
+ # inputs are the file types it will take
15
+ # output should be the type it creates
16
+ @extensions = {:input => [],
17
+ :output => ''}
15
18
  @config = {}
16
19
  end
17
20
  end
18
21
 
19
- class HTMLGenerator < StandardPlugin
20
- # a plugin which returns html
21
-
22
- def generate( content )
23
- #return html
24
- end
25
- end
26
-
27
- class CSSGenerator < StandardPlugin
28
- # a plugin which returns css
29
-
30
- def generate( content )
31
- #return css
32
- end
33
- end
34
-
35
- class JSGenerator < StandardPlugin
36
- # a plugin which returns javascript
22
+ class Generator < StandardPlugin
23
+ # a plugin which returns anything*
37
24
 
38
25
  def generate( content )
39
- #return javascript
26
+ # return stuff
40
27
  end
41
28
  end
42
29
 
43
30
  class LayoutParser < StandardPlugin
44
- # a plugin which returns html
31
+ # a plugin which returns anything*
45
32
  # given a layout and data to insert
46
33
 
47
34
  def generate( layout, data )
48
- #return html
35
+ # return stuff
49
36
  end
50
37
  end
51
38
 
@@ -6,7 +6,8 @@ class LiquidPlugin < Henshin::LayoutParser
6
6
  attr_accessor :extensions
7
7
 
8
8
  def initialize
9
- @extensions = []
9
+ @extensions = {:input => [],
10
+ :output => ''}
10
11
  end
11
12
 
12
13
  def generate( layout, data )
@@ -1,14 +1,15 @@
1
1
  require 'henshin/plugin'
2
2
  require 'maruku'
3
3
 
4
- class MarukuPlugin < Henshin::HTMLGenerator
4
+ class MarukuPlugin < Henshin::Generator
5
5
 
6
6
  attr_accessor :extensions, :config
7
7
 
8
8
  Defaults = {}
9
9
 
10
10
  def initialize( override={} )
11
- @extensions = ['markdown', 'mkdwn', 'md']
11
+ @extensions = {:input => ['markdown', 'mkdwn', 'md'],
12
+ :output => 'html'}
12
13
  @config = Defaults.merge(override)
13
14
  end
14
15
 
@@ -1,11 +1,12 @@
1
1
  require 'henshin/plugin'
2
2
 
3
- class PygmentsPlugin < Henshin::HTMLGenerator
3
+ class PygmentsPlugin < Henshin::Generator
4
4
 
5
5
  attr_accessor :extensions
6
6
 
7
7
  def initialize
8
- @extensions = ['hmm']
8
+ @extensions = {:input => [],
9
+ :output => ''}
9
10
  end
10
11
 
11
12
  def generate( content )
@@ -2,18 +2,18 @@ require 'henshin/plugin'
2
2
  require 'haml'
3
3
  require 'sass/engine'
4
4
 
5
- class SassPlugin < Henshin::CSSGenerator
5
+ class SassPlugin < Henshin::Generator
6
6
 
7
7
  attr_accessor :extensions, :config
8
8
 
9
9
  Defaults = {:target => 'css',
10
10
  :root => 'sass',
11
- :file_type => 'css',
12
11
  :ignore_layouts => true,
13
12
  :style => :nested}
14
13
 
15
14
  def initialize( override={} )
16
- @extensions = ['sass', 'scss']
15
+ @extensions = {:input => ['sass', 'scss'],
16
+ :output => 'css'}
17
17
  @config = Defaults.merge(override)
18
18
  end
19
19
 
@@ -84,7 +84,7 @@ module Henshin
84
84
  @content = file[$1.size..-1]
85
85
  else
86
86
  @content = file
87
- end
87
+ end
88
88
  end
89
89
 
90
90
  # Uses the loaded data to override settings
@@ -102,7 +102,7 @@ module Henshin
102
102
 
103
103
  if override[:tags]
104
104
  @tags << override[:tags].split(', ')
105
- @tags.flatten!
105
+ @tags.flatten!.uniq!
106
106
  end
107
107
  end
108
108
 
@@ -2,7 +2,7 @@ module Henshin
2
2
 
3
3
  class Site
4
4
 
5
- attr_accessor :posts, :gens, :statics, :archive, :tags, :categories, :plugins
5
+ attr_accessor :posts, :gens, :statics, :archive, :tags, :categories
6
6
  attr_accessor :layouts, :config
7
7
 
8
8
  def initialize( config )
@@ -15,13 +15,28 @@ module Henshin
15
15
  @posts = []
16
16
  @gens = []
17
17
  @statics = []
18
+
18
19
  @archive = {}
19
20
  @tags = Hash.new { |h, k| h[k] = Tag.new(k) }
20
21
  @categories = Hash.new { |h, k| h[k] = Category.new(k) }
22
+
21
23
  @layouts = {}
22
24
  end
23
25
 
24
26
 
27
+ ##
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
32
+ self.reset
33
+ self.read
34
+ self.process
35
+ self.render
36
+ self.write
37
+ end
38
+
39
+
25
40
  ##
26
41
  # Reads all necessary files and puts them into the necessary arrays
27
42
  #
@@ -151,6 +166,60 @@ module Henshin
151
166
  @posts.each_parallel {|p| p.write}
152
167
  @gens.each_parallel {|g| g.write}
153
168
  @statics.each_parallel {|s| s.write}
169
+
170
+ self.write_tags
171
+ self.write_categories
172
+ end
173
+
174
+
175
+ def write_tags
176
+ if @layouts['tag_index']
177
+ write_path = File.join( config[:root], 'tags', 'index.html' )
178
+
179
+ tag_index = Gen.new(write_path, self)
180
+ tag_index.layout = @layouts['tag_index']
181
+
182
+ tag_index.render
183
+ tag_index.write
184
+ end
185
+
186
+ if @layouts['tag_page']
187
+ @tags.each do |n, tag|
188
+ write_path = File.join( config[:root], 'tags', tag.name, 'index.html' )
189
+
190
+ payload = {:name => 'tag', :payload => tag.to_hash}
191
+ tag_page = Gen.new(write_path, self, payload)
192
+ tag_page.layout = @layouts['tag_page']
193
+
194
+ tag_page.render
195
+ tag_page.write
196
+ end
197
+ end
198
+ end
199
+
200
+ def write_categories
201
+ if @layouts['category_index']
202
+ write_path = File.join( config[:root], 'categories', 'index.html' )
203
+
204
+ category_index = Gen.new(write_path, self)
205
+ category_index.layout = @layouts['category_index']
206
+
207
+ category_index.render
208
+ category_index.write
209
+ end
210
+
211
+ if @layouts['category_page']
212
+ @categories.each do |n, category|
213
+ write_path = File.join( config[:root], 'categories', category.name, 'index.html' )
214
+
215
+ payload = {:name => 'category', :payload => category.to_hash}
216
+ category_page = Gen.new(write_path, self, payload)
217
+ category_page.layout = @layouts['category_page']
218
+
219
+ category_page.render
220
+ category_page.write
221
+ end
222
+ end
154
223
  end
155
224
 
156
225
  end
@@ -11,4 +11,5 @@ date: 2009-10-07T17:17:45+00:00
11
11
 
12
12
  <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>
13
13
 
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>
14
15
 
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title>{{ site.title }}</title>
6
+ <link rel="stylesheet" href="screen.css" type="text/css" />
7
+ </head>
8
+ <body>
9
+
10
+ <h2>A List of Categories</h2>
11
+ <ul>
12
+ {% for category in site.categories %}
13
+ <li>
14
+ {{ category.name }}
15
+ <ul>
16
+ {% for post in category.posts %}
17
+ <li>{{ post.title }} - {{ post.date }}</li>
18
+ {% endfor %}
19
+ </ul>
20
+ </li>
21
+ {% endfor %}
22
+ </ul>
23
+
24
+ <span>Copyright &copy; {{ site.author }}</span>
25
+ </body>
26
+ </html>
@@ -0,0 +1,20 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title>{{ site.title }}</title>
6
+ <link rel="stylesheet" href="screen.css" type="text/css" />
7
+ </head>
8
+ <body>
9
+
10
+ <h2>{{ category.name }}</h2>
11
+
12
+ <ul>
13
+ {% for post in category.posts %}
14
+ <li>{{ post.title }} - {{ post.date }}</li>
15
+ {% endfor %}
16
+ </ul>
17
+
18
+ <span>Copyright &copy; {{ site.author }}</span>
19
+ </body>
20
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title>{{ site.title }}</title>
6
+ <link rel="stylesheet" href="screen.css" type="text/css" />
7
+ </head>
8
+ <body>
9
+
10
+ <h2>A List of Tags</h2>
11
+ <ul>
12
+ {% for tag in site.tags %}
13
+ <li>
14
+ {{ tag.name }}
15
+ <ul>
16
+ {% for post in tag.posts %}
17
+ <li>{{ post.title }} - {{ post.date }}</li>
18
+ {% endfor %}
19
+ </ul>
20
+ </li>
21
+ {% endfor %}
22
+ </ul>
23
+
24
+ <span>Copyright &copy; {{ site.author }}</span>
25
+ </body>
26
+ </html>
@@ -0,0 +1,20 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title>{{ site.title }}</title>
6
+ <link rel="stylesheet" href="screen.css" type="text/css" />
7
+ </head>
8
+ <body>
9
+
10
+ <h2>{{ tag.name }}</h2>
11
+
12
+ <ul>
13
+ {% for post in tag.posts %}
14
+ <li>{{ post.title }} - {{ post.date }}</li>
15
+ {% endfor %}
16
+ </ul>
17
+
18
+ <span>Copyright &copy; {{ site.author }}</span>
19
+ </body>
20
+ </html>
@@ -2,10 +2,4 @@ require 'henshin/plugin'
2
2
 
3
3
  class TestPlugin < Henshin::StandardPlugin
4
4
 
5
- def initialize
6
- # p 'Test plugin loaded'
7
- @extensions = []
8
- @config = {}
9
- end
10
-
11
5
  end
@@ -14,6 +14,6 @@
14
14
 
15
15
  <p>I should be in the root folder! No templates or anything</p>
16
16
 
17
-
17
+ <p>init</p>
18
18
  </body>
19
19
  </html>
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
8
- - 3
9
- version: 0.1.3
7
+ - 2
8
+ - 0
9
+ version: 0.2.0
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-27 00:00:00 +01:00
17
+ date: 2010-05-30 00:00:00 +01:00
18
18
  default_executable: henshin
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -79,8 +79,12 @@ files:
79
79
  - test/site/_site/static.html
80
80
  - test/site/css/screen.css
81
81
  - test/site/index.html
82
+ - test/site/layouts/category_index.html
83
+ - test/site/layouts/category_page.html
82
84
  - test/site/layouts/main.html
83
85
  - test/site/layouts/post.html
86
+ - test/site/layouts/tag_index.html
87
+ - test/site/layouts/tag_page.html
84
88
  - test/site/options.yaml
85
89
  - test/site/plugins/test.rb
86
90
  - test/site/posts/Testing-Stuff.markdown