ace 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +2 -23
- data/bin/ace +4 -1
- data/example/app/posts.rb +1 -1
- data/example/app/tags.rb +1 -1
- data/lib/ace.rb +36 -4
- data/lib/ace/filters/layout.rb +3 -19
- data/lib/ace/filters/template.rb +28 -12
- data/lib/ace/version.rb +1 -1
- metadata +2 -2
data/README.textile
CHANGED
@@ -2,27 +2,6 @@ h1. About
|
|
2
2
|
|
3
3
|
Ace is a static page generator like "Nanoc":http://nanoc.stoneship.org, "Jekyll":https://github.com/mojombo/jekyll or "Webby":http://webby.rubyforge.org/tutorial. How is it different? Well, it's better :) ! I really like Nanoc and I used it for quite a while, but it's not flexible enough. If you need to generate a lot of pages on the fly, it's a hassle. It provides helpers, but helpers are – let's face it – programming style we used to use years back when we yet believed that PHP is actually a really nice language.
|
4
4
|
|
5
|
-
Ace
|
5
|
+
Also, last but not least, Ace has a real template inheritance. Layouts are for kids, real men use template inheritance! What's the advantage? It's incredibly flexible.
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
Also, last but not least, Ace has a real template inheritance. Layouts are for kids, real men use template inheritance! What's the advantage? It's incredibly flexible. You can have
|
10
|
-
|
11
|
-
h1. Why you should be interested in ace?
|
12
|
-
|
13
|
-
In Ace, every page is an instance
|
14
|
-
Typically I want to define methods, like @post.excerpt
|
15
|
-
|
16
|
-
There are also *generators* available for easier generating items on the fly.
|
17
|
-
|
18
|
-
Ace has *template inheritance*. I love template inheritance, it's more flexible pattern than layouts.
|
19
|
-
|
20
|
-
Tasks for deployment are included.
|
21
|
-
|
22
|
-
h1. The boot process
|
23
|
-
|
24
|
-
# Load @boot.rb@ where the
|
25
|
-
# load the rules (controllers / globs mapping)
|
26
|
-
# load & instantiate the items: only the renderables (concrete post)
|
27
|
-
# run the filters, layoutin' ... actually this can be defined in the controller
|
28
|
-
# match the routes, write the files
|
7
|
+
Check "Ace: Static Sites Generator":http://blog.101ideas.cz/posts/ace-static-site-generator.html for more information or you can take a look at "sources":https://github.com/botanicus/blog.101ideas.cz of "my blog":http://blog.101ideas.cz to have something to play with!
|
data/bin/ace
CHANGED
@@ -38,12 +38,15 @@ else
|
|
38
38
|
end
|
39
39
|
|
40
40
|
rules.rules.each do |klass, files|
|
41
|
-
puts "#{klass} #{files.inspect}"
|
41
|
+
# puts "#{klass} #{files.inspect}"
|
42
42
|
files.each do |file|
|
43
43
|
if File.binread(file).match(/^-{3,5}\s*$/) # TODO: this should be a filter or lazy-loaded
|
44
|
+
puts "~ Read #{file} with parse"
|
44
45
|
raw_item = Ace::RawItem.new(file).tap(&:parse)
|
46
|
+
raw_item.check_metadata_created_at(file)
|
45
47
|
item = klass.create(raw_item.metadata, raw_item.content)
|
46
48
|
else
|
49
|
+
puts "~ Read #{file} without parse"
|
47
50
|
item = klass.create(Hash.new, File.read(file))
|
48
51
|
end
|
49
52
|
item.original_path = file
|
data/example/app/posts.rb
CHANGED
data/example/app/tags.rb
CHANGED
data/lib/ace.rb
CHANGED
@@ -10,6 +10,8 @@
|
|
10
10
|
require "yaml"
|
11
11
|
require "fileutils"
|
12
12
|
require "ace/filters/sass"
|
13
|
+
require "digest/sha1"
|
14
|
+
require "date"
|
13
15
|
|
14
16
|
module Ace
|
15
17
|
module Helpers
|
@@ -22,6 +24,13 @@ module Ace
|
|
22
24
|
@data = File.read(path)
|
23
25
|
end
|
24
26
|
|
27
|
+
def check_metadata_created_at(path)
|
28
|
+
if self.metadata[:title]
|
29
|
+
year, month, day = File.basename(path).slice(0,10).split('-')
|
30
|
+
self.metadata[:created_at] ||= Date.new(year.to_i, month.to_i, day.to_i)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
25
34
|
def parse
|
26
35
|
pieces = @data.split(/^-{3,5}\s*$/)
|
27
36
|
# if pieces.size < 3
|
@@ -32,6 +41,7 @@ module Ace
|
|
32
41
|
|
33
42
|
# Parse
|
34
43
|
self.metadata = YAML.load(pieces[1]).inject(Hash.new) { |metadata, pair| metadata.merge(pair[0].to_sym => pair[1]) } || Hash.new
|
44
|
+
# TODO: check metadata[:created_at] and supply it from filename
|
35
45
|
self.content = pieces[2..-1].join.strip
|
36
46
|
end
|
37
47
|
end
|
@@ -135,6 +145,16 @@ module Ace
|
|
135
145
|
"#{self.base_url}#{self.server_path}"
|
136
146
|
end
|
137
147
|
|
148
|
+
def digest(data)
|
149
|
+
Digest::SHA1.hexdigest(data)
|
150
|
+
end
|
151
|
+
|
152
|
+
def feeds
|
153
|
+
@feeds ||= begin
|
154
|
+
RSSFeed.subclasses.map(&:new)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
138
158
|
attr_writer :output_path
|
139
159
|
def output_path
|
140
160
|
@output_path ||= begin
|
@@ -145,12 +165,24 @@ module Ace
|
|
145
165
|
end
|
146
166
|
|
147
167
|
def save!
|
148
|
-
content = self.render # so filters can influence output_path
|
149
168
|
puts "~ [RENDER] #{self.output_path}"
|
169
|
+
content = self.render # so filters can influence output_path
|
150
170
|
|
151
|
-
|
152
|
-
|
153
|
-
|
171
|
+
begin
|
172
|
+
old_content = File.open(self.output_path, "rb") { |f| f.read }
|
173
|
+
rescue
|
174
|
+
old_content = ''
|
175
|
+
end
|
176
|
+
|
177
|
+
if self.digest(content) != self.digest(old_content)
|
178
|
+
warn "~ CRC isn't same, save new content into #{self.output_path}"
|
179
|
+
# puts old_content.inspect
|
180
|
+
# puts content.inspect
|
181
|
+
|
182
|
+
FileUtils.mkdir_p File.dirname(self.output_path)
|
183
|
+
File.open(self.output_path, "w") do |file|
|
184
|
+
file.puts(content)
|
185
|
+
end
|
154
186
|
end
|
155
187
|
end
|
156
188
|
end
|
data/lib/ace/filters/layout.rb
CHANGED
@@ -1,26 +1,10 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
|
4
|
-
require "template-inheritance"
|
3
|
+
require_relative "template"
|
5
4
|
|
6
|
-
|
7
|
-
unless TemplateInheritance::Template.paths.include?(layouts)
|
8
|
-
TemplateInheritance::Template.paths.unshift(layouts)
|
9
|
-
end
|
5
|
+
warn "~ TemplateFilter is deprecated, use TemplateFilter from now on."
|
10
6
|
|
11
7
|
module Ace
|
12
|
-
class
|
13
|
-
class Scope
|
14
|
-
include Ace::Helpers
|
15
|
-
end
|
16
|
-
|
17
|
-
def initialize(options)
|
18
|
-
@path = options[:layout]
|
19
|
-
end
|
20
|
-
|
21
|
-
def call(item, content)
|
22
|
-
template = TemplateInheritance::Template.new(@path, Scope.new)
|
23
|
-
return template.render(item: item)
|
24
|
-
end
|
8
|
+
class TemplateFilter < TemplateFilter
|
25
9
|
end
|
26
10
|
end
|
data/lib/ace/filters/template.rb
CHANGED
@@ -3,25 +3,41 @@
|
|
3
3
|
require "ace/filters"
|
4
4
|
require "template-inheritance"
|
5
5
|
|
6
|
-
layouts = File.join(Dir.pwd, "layouts")
|
7
|
-
unless TemplateInheritance::Template.paths.include?(layouts)
|
8
|
-
TemplateInheritance::Template.paths.unshift(layouts)
|
9
|
-
end
|
10
|
-
|
11
|
-
TemplateInheritance::Template.paths << File.join(Dir.pwd, "content")
|
12
|
-
|
13
6
|
module Ace
|
14
7
|
class TemplateFilter < Filter
|
15
|
-
|
8
|
+
class Scope
|
9
|
+
include Ace::Helpers
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.add_to_paths(directory)
|
13
|
+
unless TemplateInheritance::Template.paths.include?(directory)
|
14
|
+
TemplateInheritance::Template.paths.unshift(directory)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(options = Hash.new)
|
19
|
+
@path = options[:layout]
|
20
|
+
end
|
16
21
|
|
17
22
|
def call(item, content)
|
18
|
-
if
|
19
|
-
|
23
|
+
if @path.nil?
|
24
|
+
@path = item.original_path.sub("content/", "")
|
20
25
|
end
|
21
26
|
|
22
|
-
|
23
|
-
|
27
|
+
parts = item.output_path.split(".")
|
28
|
+
if parts.length == 2 # template.haml
|
29
|
+
item.output_path = "#{parts[0]}.html"
|
30
|
+
elsif parts.length == 3 # template.html.haml or template.xml.haml
|
31
|
+
item.output_path = "#{parts[0]}.#{parts[1]}"
|
32
|
+
else
|
33
|
+
raise "Template can be named either with one suffix as template.haml or with two of them as template.html.haml resp. template.xml.haml."
|
34
|
+
end
|
35
|
+
|
36
|
+
template = TemplateInheritance::Template.new(@path, Scope.new)
|
24
37
|
return template.render(item: item)
|
25
38
|
end
|
26
39
|
end
|
27
40
|
end
|
41
|
+
|
42
|
+
Ace::TemplateFilter.add_to_paths(File.join(Dir.pwd, "layouts"))
|
43
|
+
Ace::TemplateFilter.add_to_paths(File.join(Dir.pwd, "content"))
|
data/lib/ace/version.rb
CHANGED
metadata
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
name: ace
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.3.
|
5
|
+
version: 0.3.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- "Jakub \xC5\xA0\xC5\xA5astn\xC3\xBD aka Botanicus"
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain:
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-05-26 00:00:00 +02:00
|
13
13
|
default_executable: ace
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|