ace 0.1 → 0.3
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/CHANGELOG +11 -1
- data/LICENSE +1 -1
- data/README.textile +12 -2
- data/bin/ace +8 -9
- data/lib/ace.rb +32 -11
- data/lib/ace/filters/layout.rb +5 -1
- data/lib/ace/filters/pygments.rb +21 -0
- data/lib/ace/filters/sass.rb +24 -0
- data/lib/ace/filters/template.rb +3 -1
- data/lib/ace/mixins/lazy.rb +31 -0
- data/lib/ace/static.rb +19 -0
- data/lib/ace/version.rb +1 -1
- metadata +9 -21
data/CHANGELOG
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
-
= Version 0.
|
1
|
+
= Version 0.3
|
2
|
+
* Added LazyRendering mixin.
|
3
|
+
* Added SassFilter.
|
4
|
+
* Added PygmentsFilter for syntax highlighting.
|
5
|
+
* Added Static class for copying static files.
|
6
|
+
|
7
|
+
= Version 0.2
|
8
|
+
* Filters inheritance.
|
9
|
+
* Item#permalink and Item#server_path.
|
10
|
+
|
11
|
+
= Version 0.1
|
2
12
|
* Items
|
3
13
|
* Generators
|
data/LICENSE
CHANGED
data/README.textile
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
h1. About
|
2
|
+
|
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
|
+
|
5
|
+
Ace chose an OOP approach
|
6
|
+
|
7
|
+
Another common proble of these generators is, that they are way too opinionated. Thanks Webby, but I don't give a damn about your Sitemap, thank you very much!
|
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
|
+
|
1
11
|
h1. Why you should be interested in ace?
|
2
12
|
|
3
13
|
In Ace, every page is an instance
|
@@ -7,11 +17,11 @@ There are also *generators* available for easier generating items on the fly.
|
|
7
17
|
|
8
18
|
Ace has *template inheritance*. I love template inheritance, it's more flexible pattern than layouts.
|
9
19
|
|
10
|
-
Tasks for deployment included.
|
20
|
+
Tasks for deployment are included.
|
11
21
|
|
12
22
|
h1. The boot process
|
13
23
|
|
14
|
-
#
|
24
|
+
# Load @boot.rb@ where the
|
15
25
|
# load the rules (controllers / globs mapping)
|
16
26
|
# load & instantiate the items: only the renderables (concrete post)
|
17
27
|
# run the filters, layoutin' ... actually this can be defined in the controller
|
data/bin/ace
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
# encoding: utf-8
|
3
3
|
|
4
4
|
if RUBY_VERSION < "1.9.1"
|
5
|
-
abort "Ace requires Ruby 1.9
|
5
|
+
abort "Ace requires Ruby 1.9"
|
6
6
|
end
|
7
7
|
|
8
8
|
base = File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__
|
@@ -40,7 +40,7 @@ end
|
|
40
40
|
rules.rules.each do |klass, files|
|
41
41
|
puts "#{klass} #{files.inspect}"
|
42
42
|
files.each do |file|
|
43
|
-
if File.binread(file).match(/^-{3,5}\s*$/)
|
43
|
+
if File.binread(file).match(/^-{3,5}\s*$/) # TODO: this should be a filter or lazy-loaded
|
44
44
|
raw_item = Ace::RawItem.new(file).tap(&:parse)
|
45
45
|
item = klass.create(raw_item.metadata, raw_item.content)
|
46
46
|
else
|
@@ -52,14 +52,14 @@ end
|
|
52
52
|
|
53
53
|
puts
|
54
54
|
|
55
|
-
|
56
|
-
|
57
|
-
generator
|
55
|
+
# Generator is anything what provides #generate method.
|
56
|
+
rules.generators.each do |generator|
|
57
|
+
puts "~ Running generator #{generator}"
|
58
58
|
begin
|
59
|
-
if generator.respond_to?(:
|
60
|
-
generator.
|
59
|
+
if generator.respond_to?(:generate)
|
60
|
+
generator.generate
|
61
61
|
else
|
62
|
-
abort "Generator #{generator.inspect} doesn't respond to the #
|
62
|
+
abort "Generator #{generator.inspect} doesn't respond to the #generate method!"
|
63
63
|
end
|
64
64
|
rescue Exception => exception
|
65
65
|
puts "Error in generator #{generator.inspect}: #{exception.message}"
|
@@ -71,6 +71,5 @@ end
|
|
71
71
|
puts
|
72
72
|
|
73
73
|
Ace::Item.all_instances.each do |item|
|
74
|
-
puts "~ Generating #{item.output_path}"
|
75
74
|
item.save!
|
76
75
|
end
|
data/lib/ace.rb
CHANGED
@@ -9,8 +9,13 @@
|
|
9
9
|
|
10
10
|
require "yaml"
|
11
11
|
require "fileutils"
|
12
|
+
require "ace/filters/sass"
|
12
13
|
|
13
14
|
module Ace
|
15
|
+
module Helpers
|
16
|
+
# include your helpers here
|
17
|
+
end
|
18
|
+
|
14
19
|
class RawItem
|
15
20
|
attr_accessor :path, :metadata, :content
|
16
21
|
def initialize(path)
|
@@ -19,11 +24,11 @@ module Ace
|
|
19
24
|
|
20
25
|
def parse
|
21
26
|
pieces = @data.split(/^-{3,5}\s*$/)
|
22
|
-
if pieces.size < 3
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
27
|
+
# if pieces.size < 3
|
28
|
+
# raise RuntimeError.new(
|
29
|
+
# "The file '#{path}' appears to start with a metadata section (three or five dashes at the top) but it does not seem to be in the correct format."
|
30
|
+
# )
|
31
|
+
# end
|
27
32
|
|
28
33
|
# Parse
|
29
34
|
self.metadata = YAML.load(pieces[1]).inject(Hash.new) { |metadata, pair| metadata.merge(pair[0].to_sym => pair[1]) } || Hash.new
|
@@ -36,10 +41,12 @@ module Ace
|
|
36
41
|
class Item
|
37
42
|
def self.inherited(subclass)
|
38
43
|
self.subclasses << subclass
|
44
|
+
subclass.before_filters.push(*self.before_filters)
|
45
|
+
subclass.after_filters.push(*self.after_filters)
|
39
46
|
end
|
40
47
|
|
41
48
|
def self.subclasses
|
42
|
-
@subclasses ||=
|
49
|
+
@subclasses ||= [self]
|
43
50
|
end
|
44
51
|
|
45
52
|
def self.instances
|
@@ -111,6 +118,23 @@ module Ace
|
|
111
118
|
end
|
112
119
|
end
|
113
120
|
|
121
|
+
def server_path
|
122
|
+
absolute = self.output_path.sub(/^output\//, "")
|
123
|
+
"/#{absolute}"
|
124
|
+
end
|
125
|
+
|
126
|
+
def base_url
|
127
|
+
self.config[:base_url]
|
128
|
+
end
|
129
|
+
|
130
|
+
def permalink
|
131
|
+
if self.config[:base_url].nil?
|
132
|
+
raise "You have to add :base_url into config.yml or redefine #base_url method!"
|
133
|
+
end
|
134
|
+
|
135
|
+
"#{self.base_url}#{self.server_path}"
|
136
|
+
end
|
137
|
+
|
114
138
|
attr_writer :output_path
|
115
139
|
def output_path
|
116
140
|
@output_path ||= begin
|
@@ -122,6 +146,7 @@ module Ace
|
|
122
146
|
|
123
147
|
def save!
|
124
148
|
content = self.render # so filters can influence output_path
|
149
|
+
puts "~ [RENDER] #{self.output_path}"
|
125
150
|
|
126
151
|
FileUtils.mkdir_p File.dirname(self.output_path)
|
127
152
|
File.open(self.output_path, "w") do |file|
|
@@ -131,10 +156,6 @@ module Ace
|
|
131
156
|
end
|
132
157
|
|
133
158
|
class Asset < Item
|
134
|
-
|
135
|
-
|
136
|
-
module Helpers
|
137
|
-
def link_to(anchor, path_or_item, options = nil)
|
138
|
-
end
|
159
|
+
before Ace::SassFilter
|
139
160
|
end
|
140
161
|
end
|
data/lib/ace/filters/layout.rb
CHANGED
@@ -10,12 +10,16 @@ end
|
|
10
10
|
|
11
11
|
module Ace
|
12
12
|
class LayoutFilter < Filter
|
13
|
+
class Scope
|
14
|
+
include Ace::Helpers
|
15
|
+
end
|
16
|
+
|
13
17
|
def initialize(options)
|
14
18
|
@path = options[:layout]
|
15
19
|
end
|
16
20
|
|
17
21
|
def call(item, content)
|
18
|
-
template = TemplateInheritance::Template.new(@path)
|
22
|
+
template = TemplateInheritance::Template.new(@path, Scope.new)
|
19
23
|
return template.render(item: item)
|
20
24
|
end
|
21
25
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "ace/filters"
|
4
|
+
require "nokogiri"
|
5
|
+
require "albino"
|
6
|
+
|
7
|
+
module Ace
|
8
|
+
class PygmentsFilter < Filter
|
9
|
+
def call(item, content)
|
10
|
+
doc = Nokogiri::HTML(content)
|
11
|
+
doc.css("pre[lang]").each do |pre|
|
12
|
+
unless pre['lang'].nil? || pre['lang'].empty?
|
13
|
+
# Set $VERBOSE to nil if you don't want to see this message.
|
14
|
+
warn "~ Syntax highlight in '#{item.original_path}' using '#{pre['lang']}' lexer."
|
15
|
+
pre.replace Albino.colorize(pre.content, pre['lang'])
|
16
|
+
end
|
17
|
+
end
|
18
|
+
doc.to_s
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "sass"
|
4
|
+
require "ace/filters"
|
5
|
+
|
6
|
+
module Ace
|
7
|
+
class SassFilter < Filter
|
8
|
+
def call(item, content)
|
9
|
+
if item.output_path && item.output_path.end_with?(".scss")
|
10
|
+
item.output_path.sub!(/scss$/, "css")
|
11
|
+
begin
|
12
|
+
engine = Sass::Engine.new(content, {:syntax => :scss})
|
13
|
+
output = engine.render
|
14
|
+
rescue Exception => e
|
15
|
+
warn "~~ SassFilter exception: #{e}"
|
16
|
+
abort
|
17
|
+
end
|
18
|
+
return output
|
19
|
+
else
|
20
|
+
return content
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/ace/filters/template.rb
CHANGED
@@ -12,8 +12,10 @@ TemplateInheritance::Template.paths << File.join(Dir.pwd, "content")
|
|
12
12
|
|
13
13
|
module Ace
|
14
14
|
class TemplateFilter < Filter
|
15
|
+
TEMPLATE_EXTS_PATTERN = /\.(haml|erb|erubis)$/i
|
16
|
+
|
15
17
|
def call(item, content)
|
16
|
-
if item.output_path
|
18
|
+
if item.output_path.match(TEMPLATE_EXTS_PATTERN)
|
17
19
|
item.output_path = item.output_path.split(".")[0..-2].join(".")
|
18
20
|
end
|
19
21
|
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# Sometimes rendering is taking too long, so you want to skip
|
4
|
+
# it in case that nothing changed in the files which influence
|
5
|
+
# the output. For example syntax highlighting via Pygments takes
|
6
|
+
# a while, so it's better to include this mixin and redefine
|
7
|
+
# #source_files to include every file which influence the output.
|
8
|
+
module Ace
|
9
|
+
module LazyRendering
|
10
|
+
def compare_mtime(one, others)
|
11
|
+
File.exist?(one) && File.mtime(one) > others.map { |post| File.mtime(post) }.max
|
12
|
+
end
|
13
|
+
|
14
|
+
# @api public
|
15
|
+
def source_files
|
16
|
+
[self.original_path]
|
17
|
+
end
|
18
|
+
|
19
|
+
def fresh?
|
20
|
+
@fresh ||= compare_mtime(self.output_path, self.source_files)
|
21
|
+
end
|
22
|
+
|
23
|
+
def save!
|
24
|
+
if self.fresh?
|
25
|
+
puts "~ [IGNORE] #{self.output_path}"
|
26
|
+
else
|
27
|
+
super
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/ace/static.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "ace/filters/template"
|
4
|
+
|
5
|
+
# rule Ace::Static, "about.html.haml"
|
6
|
+
# rule Ace::Static("output/index.html"), "index.html.haml"
|
7
|
+
module Ace
|
8
|
+
def self.Static(output_path)
|
9
|
+
Class.new(Static) do
|
10
|
+
define_method(:output_path) do
|
11
|
+
output_path
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class Static < Item
|
17
|
+
before Ace::TemplateFilter
|
18
|
+
end
|
19
|
+
end
|
data/lib/ace/version.rb
CHANGED
metadata
CHANGED
@@ -1,18 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ace
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 1
|
8
|
-
version: "0.1"
|
4
|
+
prerelease:
|
5
|
+
version: "0.3"
|
9
6
|
platform: ruby
|
10
7
|
authors:
|
11
8
|
- "Jakub \xC5\xA0\xC5\xA5astn\xC3\xBD aka Botanicus"
|
12
9
|
autorequire:
|
13
10
|
bindir: bin
|
14
11
|
cert_chain:
|
15
|
-
date: 2011-
|
12
|
+
date: 2011-03-17 00:00:00 +00:00
|
16
13
|
default_executable: ace
|
17
14
|
dependencies:
|
18
15
|
- !ruby/object:Gem::Dependency
|
@@ -23,8 +20,6 @@ dependencies:
|
|
23
20
|
requirements:
|
24
21
|
- - ">="
|
25
22
|
- !ruby/object:Gem::Version
|
26
|
-
segments:
|
27
|
-
- 0
|
28
23
|
version: "0"
|
29
24
|
type: :runtime
|
30
25
|
version_requirements: *id001
|
@@ -36,11 +31,6 @@ dependencies:
|
|
36
31
|
requirements:
|
37
32
|
- - ">="
|
38
33
|
- !ruby/object:Gem::Version
|
39
|
-
segments:
|
40
|
-
- 0
|
41
|
-
- 0
|
42
|
-
- 1
|
43
|
-
- 2
|
44
34
|
version: 0.0.1.2
|
45
35
|
type: :development
|
46
36
|
version_requirements: *id002
|
@@ -93,7 +83,11 @@ files:
|
|
93
83
|
- lib/ace/filters.rb
|
94
84
|
- lib/ace/filters/haml.rb
|
95
85
|
- lib/ace/filters/layout.rb
|
86
|
+
- lib/ace/filters/pygments.rb
|
87
|
+
- lib/ace/filters/sass.rb
|
96
88
|
- lib/ace/filters/template.rb
|
89
|
+
- lib/ace/mixins/lazy.rb
|
90
|
+
- lib/ace/static.rb
|
97
91
|
- lib/ace/version.rb
|
98
92
|
- project_generator/metadata.yml
|
99
93
|
- project_generator/postprocess.rb
|
@@ -103,8 +97,7 @@ has_rdoc: true
|
|
103
97
|
homepage: http://github.com/botanicus/ace
|
104
98
|
licenses: []
|
105
99
|
|
106
|
-
post_install_message:
|
107
|
-
[\e[32mVersion 0.0.1\e[0m] Generators\n"
|
100
|
+
post_install_message:
|
108
101
|
rdoc_options: []
|
109
102
|
|
110
103
|
require_paths:
|
@@ -114,22 +107,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
114
107
|
requirements:
|
115
108
|
- - ~>
|
116
109
|
- !ruby/object:Gem::Version
|
117
|
-
segments:
|
118
|
-
- 1
|
119
|
-
- 9
|
120
110
|
version: "1.9"
|
121
111
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
112
|
none: false
|
123
113
|
requirements:
|
124
114
|
- - ">="
|
125
115
|
- !ruby/object:Gem::Version
|
126
|
-
segments:
|
127
|
-
- 0
|
128
116
|
version: "0"
|
129
117
|
requirements: []
|
130
118
|
|
131
119
|
rubyforge_project: ace
|
132
|
-
rubygems_version: 1.3
|
120
|
+
rubygems_version: 1.5.3
|
133
121
|
signing_key:
|
134
122
|
specification_version: 3
|
135
123
|
summary: Ace is highly flexible static pages generator with template inheritance.
|