nanoc 1.4 → 1.5
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 +7 -0
- data/README +2 -24
- data/Rakefile +1 -1
- data/bin/nanoc +4 -4
- data/lib/nanoc.rb +13 -5
- data/lib/{compiler.rb → nanoc/compiler.rb} +80 -53
- data/lib/nanoc/core_ext.rb +1 -0
- data/lib/nanoc/core_ext/array.rb +17 -0
- data/lib/nanoc/core_ext/hash.rb +41 -0
- data/lib/nanoc/core_ext/string.rb +13 -0
- data/lib/nanoc/core_ext/yaml.rb +8 -0
- data/lib/{creator.rb → nanoc/creator.rb} +7 -7
- data/lib/nanoc/enhancements.rb +93 -0
- data/lib/nanoc/filters.rb +7 -0
- data/lib/nanoc/filters/eruby_filter.rb +44 -0
- data/lib/nanoc/filters/haml_filter.rb +24 -0
- data/lib/nanoc/filters/liquid_filter.rb +51 -0
- data/lib/nanoc/filters/markaby_filter.rb +25 -0
- data/lib/nanoc/filters/markdown_filter.rb +21 -0
- data/lib/nanoc/filters/rdoc_filter.rb +19 -0
- data/lib/nanoc/filters/sass_filter.rb +18 -0
- data/lib/nanoc/filters/smartypants_filter.rb +21 -0
- data/lib/nanoc/filters/textile_filter.rb +21 -0
- data/lib/nanoc/page.rb +147 -0
- metadata +25 -7
- data/lib/enhancements.rb +0 -277
- data/lib/page.rb +0 -91
metadata
CHANGED
@@ -3,13 +3,13 @@ rubygems_version: 0.9.2
|
|
3
3
|
specification_version: 1
|
4
4
|
name: nanoc
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: "1.
|
7
|
-
date: 2007-
|
6
|
+
version: "1.5"
|
7
|
+
date: 2007-09-10 00:00:00 +02:00
|
8
8
|
summary: a CMS that doesn't run on your server
|
9
9
|
require_paths:
|
10
10
|
- lib
|
11
11
|
email: denis.defreyne@stoneship.org
|
12
|
-
homepage: http://stoneship.org/
|
12
|
+
homepage: http://nanoc.stoneship.org/
|
13
13
|
rubyforge_project:
|
14
14
|
description: a CMS that doesn't run on your server
|
15
15
|
autorequire:
|
@@ -34,11 +34,29 @@ files:
|
|
34
34
|
- ChangeLog
|
35
35
|
- Rakefile
|
36
36
|
- bin/nanoc
|
37
|
-
- lib/
|
38
|
-
- lib/
|
39
|
-
- lib/
|
37
|
+
- lib/nanoc
|
38
|
+
- lib/nanoc/compiler.rb
|
39
|
+
- lib/nanoc/core_ext
|
40
|
+
- lib/nanoc/core_ext/array.rb
|
41
|
+
- lib/nanoc/core_ext/hash.rb
|
42
|
+
- lib/nanoc/core_ext/string.rb
|
43
|
+
- lib/nanoc/core_ext/yaml.rb
|
44
|
+
- lib/nanoc/core_ext.rb
|
45
|
+
- lib/nanoc/creator.rb
|
46
|
+
- lib/nanoc/enhancements.rb
|
47
|
+
- lib/nanoc/filters
|
48
|
+
- lib/nanoc/filters/eruby_filter.rb
|
49
|
+
- lib/nanoc/filters/haml_filter.rb
|
50
|
+
- lib/nanoc/filters/liquid_filter.rb
|
51
|
+
- lib/nanoc/filters/markaby_filter.rb
|
52
|
+
- lib/nanoc/filters/markdown_filter.rb
|
53
|
+
- lib/nanoc/filters/rdoc_filter.rb
|
54
|
+
- lib/nanoc/filters/sass_filter.rb
|
55
|
+
- lib/nanoc/filters/smartypants_filter.rb
|
56
|
+
- lib/nanoc/filters/textile_filter.rb
|
57
|
+
- lib/nanoc/filters.rb
|
58
|
+
- lib/nanoc/page.rb
|
40
59
|
- lib/nanoc.rb
|
41
|
-
- lib/page.rb
|
42
60
|
test_files: []
|
43
61
|
|
44
62
|
rdoc_options: []
|
data/lib/enhancements.rb
DELETED
@@ -1,277 +0,0 @@
|
|
1
|
-
def try_require(s) ; begin ; require s ; rescue LoadError ; end ; end
|
2
|
-
|
3
|
-
try_require 'rubygems'
|
4
|
-
|
5
|
-
require 'erb'
|
6
|
-
require 'fileutils'
|
7
|
-
require 'yaml'
|
8
|
-
|
9
|
-
try_require 'bluecloth'
|
10
|
-
try_require 'erubis'
|
11
|
-
try_require 'redcloth'
|
12
|
-
try_require 'rubypants'
|
13
|
-
try_require 'markaby'
|
14
|
-
try_require 'liquid'
|
15
|
-
try_require 'haml'
|
16
|
-
try_require 'rdoc/markup/simple_markup'
|
17
|
-
try_require 'rdoc/markup/simple_markup/to_html'
|
18
|
-
|
19
|
-
def handle_exception(exception, text)
|
20
|
-
unless $quiet or exception.class == SystemExit
|
21
|
-
$stderr.puts "ERROR: Exception occured while #{text}:\n"
|
22
|
-
$stderr.puts exception
|
23
|
-
$stderr.puts exception.backtrace.join("\n")
|
24
|
-
end
|
25
|
-
exit
|
26
|
-
end
|
27
|
-
|
28
|
-
class Array
|
29
|
-
# Ensures that the array contains only one element
|
30
|
-
def ensure_single(a_noun, a_context)
|
31
|
-
if self.size != 1
|
32
|
-
$stderr.puts "ERROR: expected 1 #{a_noun}, found #{self.size} (#{a_context})" unless $quiet
|
33
|
-
exit
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
module YAML
|
39
|
-
# Returns the contents of an entire file interpreted as YAML and cleaned
|
40
|
-
def self.load_file_and_clean(a_filename)
|
41
|
-
(YAML.load_file(a_filename) || {}).clean
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
class Hash
|
46
|
-
# Converts all keys to symbols, and converts *_at and *_on
|
47
|
-
# keys to Times and Dates, respectively
|
48
|
-
def clean
|
49
|
-
inject({}) do |hash, (key, value)|
|
50
|
-
if key =~ /_on$/
|
51
|
-
hash[key.to_sym] = Date.parse(value)
|
52
|
-
elsif key =~ /_at$/
|
53
|
-
hash[key.to_sym] = Time.parse(value)
|
54
|
-
elsif value == 'true'
|
55
|
-
hash[key.to_sym] = true
|
56
|
-
elsif value == 'false'
|
57
|
-
hash[key.to_sym] = false
|
58
|
-
elsif value == 'none'
|
59
|
-
hash[key.to_sym] = nil
|
60
|
-
else
|
61
|
-
hash[key.to_sym] = value
|
62
|
-
end
|
63
|
-
hash
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def symbolize_keys
|
68
|
-
inject({}) do |hash, (key, value)|
|
69
|
-
hash[key.intern] = value
|
70
|
-
hash
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def stringify_keys
|
75
|
-
inject({}) do |hash, (key, value)|
|
76
|
-
hash[key.to_s] = value
|
77
|
-
hash
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
class ERBContext
|
83
|
-
def initialize(hash)
|
84
|
-
hash.each_pair do |key, value|
|
85
|
-
instance_variable_set('@' + key.to_s, value)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
def get_binding
|
90
|
-
binding
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
class String
|
95
|
-
# Runs the string through the filters as given by the array of
|
96
|
-
# filter names. Available filters include 'markdown', 'smartypants' and 'eruby'.
|
97
|
-
def filter(a_filters, a_params={})
|
98
|
-
assigns = a_params[:assigns]
|
99
|
-
a_filters.inject(self) do |result, filter|
|
100
|
-
case filter
|
101
|
-
when 'eruby'
|
102
|
-
result.replace(result.eruby(:assigns => assigns))
|
103
|
-
when 'haml'
|
104
|
-
result.replace(result.haml(:assigns => assigns))
|
105
|
-
when 'liquid'
|
106
|
-
result.replace(result.liquid(:assigns => assigns))
|
107
|
-
when 'markaby'
|
108
|
-
result.replace(result.markaby(:assigns => assigns))
|
109
|
-
when 'markdown', 'bluecloth'
|
110
|
-
result.replace(result.markdown)
|
111
|
-
when 'rdoc'
|
112
|
-
result.replace(result.rdoc)
|
113
|
-
when 'sass'
|
114
|
-
result.replace(result.sass)
|
115
|
-
when 'smartypants', 'rubypants'
|
116
|
-
result.replace(result.smartypants)
|
117
|
-
when 'textile', 'redcloth'
|
118
|
-
result.replace(result.textile)
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
# Converts the string using eRuby
|
124
|
-
def eruby(a_params={})
|
125
|
-
erubis(a_params)
|
126
|
-
rescue NameError
|
127
|
-
erb(a_params)
|
128
|
-
end
|
129
|
-
|
130
|
-
# Converts the string using Erubis
|
131
|
-
def erubis(a_params={})
|
132
|
-
Erubis::Eruby.new(self).evaluate(a_params[:assigns] || {})
|
133
|
-
end
|
134
|
-
|
135
|
-
# Converts the string using ERB
|
136
|
-
def erb(a_params={})
|
137
|
-
ERB.new(self).result(ERBContext.new(a_params[:assigns] || {}).get_binding)
|
138
|
-
end
|
139
|
-
|
140
|
-
# Converts the string using Haml
|
141
|
-
def haml(a_params={})
|
142
|
-
options = (a_params[:haml_options] || {})
|
143
|
-
options[:locals] = a_params[:assigns] unless a_params[:assigns].nil?
|
144
|
-
Haml::Engine.new(self, options).to_html
|
145
|
-
rescue NameError
|
146
|
-
$stderr.puts 'ERROR: String#haml failed (Haml not installed?)' unless $quiet
|
147
|
-
exit
|
148
|
-
end
|
149
|
-
|
150
|
-
# Converts the string using Liquid
|
151
|
-
def liquid(a_params={})
|
152
|
-
Liquid::Template.parse(self).render((a_params[:assigns] || {}).stringify_keys)
|
153
|
-
rescue NameError
|
154
|
-
$stderr.puts 'ERROR: String#liquid failed (Liquid not installed?)' unless $quiet
|
155
|
-
exit
|
156
|
-
end
|
157
|
-
|
158
|
-
# Converts the string using Markaby
|
159
|
-
# TODO perhaps add support for helpers
|
160
|
-
def markaby(a_params={})
|
161
|
-
Markaby::Builder.new((a_params[:assigns] || {})).instance_eval(self).to_s
|
162
|
-
rescue NameError
|
163
|
-
$stderr.puts 'ERROR: String#markaby failed (Markaby not installed?)' unless $quiet
|
164
|
-
exit
|
165
|
-
end
|
166
|
-
|
167
|
-
# Converts the string to HTML using BlueCloth/Markdown.
|
168
|
-
def markdown
|
169
|
-
BlueCloth.new(self).to_html
|
170
|
-
rescue NameError
|
171
|
-
$stderr.puts 'ERROR: String#markdown failed: BlueCloth not installed' unless $quiet
|
172
|
-
exit
|
173
|
-
end
|
174
|
-
|
175
|
-
# Converts the string using RDoc
|
176
|
-
def rdoc
|
177
|
-
SM::SimpleMarkup.new.convert(self, SM::ToHtml.new)
|
178
|
-
end
|
179
|
-
|
180
|
-
# Converts the string using Sass
|
181
|
-
def sass
|
182
|
-
Sass::Engine.new(self).render
|
183
|
-
end
|
184
|
-
|
185
|
-
# Converts the string using RedCloth/Textile
|
186
|
-
def textile
|
187
|
-
RedCloth.new(self).to_html
|
188
|
-
rescue NameError
|
189
|
-
$stderr.puts 'ERROR: String#textile failed (RedCloth not installed?)' unless $quiet
|
190
|
-
exit
|
191
|
-
end
|
192
|
-
|
193
|
-
# Converts the string using RubyPants/SmartyPants
|
194
|
-
def smartypants
|
195
|
-
RubyPants.new(self).to_html
|
196
|
-
rescue NameError
|
197
|
-
$stderr.puts 'ERROR: String#smartypants failed (RubyPants not installed?)' unless $quiet
|
198
|
-
exit
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
class FileLogger
|
203
|
-
COLORS = {
|
204
|
-
:reset => "\e[0m",
|
205
|
-
|
206
|
-
:bold => "\e[1m",
|
207
|
-
|
208
|
-
:black => "\e[30m",
|
209
|
-
:red => "\e[31m",
|
210
|
-
:green => "\e[32m",
|
211
|
-
:yellow => "\e[33m",
|
212
|
-
:blue => "\e[34m",
|
213
|
-
:magenta => "\e[35m",
|
214
|
-
:cyan => "\e[36m",
|
215
|
-
:white => "\e[37m"
|
216
|
-
}
|
217
|
-
|
218
|
-
ACTION_COLORS = {
|
219
|
-
:create => COLORS[:bold] + COLORS[:green],
|
220
|
-
:update => COLORS[:bold] + COLORS[:yellow],
|
221
|
-
:move => COLORS[:bold] + COLORS[:blue],
|
222
|
-
:identical => COLORS[:bold]
|
223
|
-
}
|
224
|
-
|
225
|
-
attr_reader :out
|
226
|
-
|
227
|
-
def initialize(a_out = $stdout)
|
228
|
-
@out = a_out
|
229
|
-
end
|
230
|
-
|
231
|
-
def log(a_action, a_path)
|
232
|
-
@out.puts('%s%12s%s %s' % [ACTION_COLORS[a_action.to_sym], a_action, COLORS[:reset], a_path]) unless $quiet
|
233
|
-
end
|
234
|
-
|
235
|
-
private
|
236
|
-
|
237
|
-
def method_missing(a_method, *a_args)
|
238
|
-
log(a_method.to_s, a_args.first)
|
239
|
-
end
|
240
|
-
end
|
241
|
-
|
242
|
-
class FileManager
|
243
|
-
@@stack = []
|
244
|
-
@@logger = FileLogger.new
|
245
|
-
|
246
|
-
def self.create_dir(a_name)
|
247
|
-
@@stack.push(a_name)
|
248
|
-
path = File.join(@@stack)
|
249
|
-
unless File.directory?(path)
|
250
|
-
FileUtils.mkdir_p(path)
|
251
|
-
@@logger.create(path)
|
252
|
-
end
|
253
|
-
yield if block_given?
|
254
|
-
@@stack.pop
|
255
|
-
end
|
256
|
-
|
257
|
-
def self.create_file(a_name)
|
258
|
-
path = File.join(@@stack + [ a_name ])
|
259
|
-
FileManager.create_dir(path.sub(/\/[^\/]+$/, '')) if @@stack.empty?
|
260
|
-
content = block_given? ? yield : nil
|
261
|
-
if File.exist?(path)
|
262
|
-
if block_given? and File.read(path) == content
|
263
|
-
@@logger.identical(path)
|
264
|
-
else
|
265
|
-
@@logger.update(path)
|
266
|
-
end
|
267
|
-
else
|
268
|
-
@@logger.create(path)
|
269
|
-
end
|
270
|
-
open(path, 'w') { |io| io.write(content) unless content.nil? }
|
271
|
-
end
|
272
|
-
end
|
273
|
-
|
274
|
-
def render(a_name, a_context={})
|
275
|
-
assigns = a_context.merge({ :page => @page, :pages => @pages })
|
276
|
-
File.read('layouts/' + a_name.to_s + '.erb').eruby(:assigns => assigns)
|
277
|
-
end
|
data/lib/page.rb
DELETED
@@ -1,91 +0,0 @@
|
|
1
|
-
module Nanoc
|
2
|
-
class Page
|
3
|
-
|
4
|
-
@@compilation_stack = []
|
5
|
-
|
6
|
-
def initialize(hash={})
|
7
|
-
@attributes = hash
|
8
|
-
end
|
9
|
-
|
10
|
-
def merge(other)
|
11
|
-
@attributes.merge(other.to_hash)
|
12
|
-
self
|
13
|
-
end
|
14
|
-
|
15
|
-
def to_hash
|
16
|
-
@attributes
|
17
|
-
end
|
18
|
-
|
19
|
-
# Accessing data
|
20
|
-
|
21
|
-
def [](key)
|
22
|
-
@attributes[key]
|
23
|
-
end
|
24
|
-
|
25
|
-
def []=(key, value)
|
26
|
-
@attributes[key] = value
|
27
|
-
end
|
28
|
-
|
29
|
-
def method_missing(method, *args)
|
30
|
-
@attributes[method.to_sym]
|
31
|
-
end
|
32
|
-
|
33
|
-
def content
|
34
|
-
compile!
|
35
|
-
@attributes[:content]
|
36
|
-
end
|
37
|
-
|
38
|
-
# Compiling
|
39
|
-
|
40
|
-
def self.compile(pages)
|
41
|
-
@@pages = pages
|
42
|
-
|
43
|
-
# Compile all pages
|
44
|
-
pages.each do |page|
|
45
|
-
page.compile!
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def compile!
|
50
|
-
# Check for recursive call
|
51
|
-
if @@compilation_stack.include?(self)
|
52
|
-
# Print compilation stack
|
53
|
-
unless $quiet
|
54
|
-
$stderr.puts 'ERROR: Recursive call to page content. Page compilation stack:'
|
55
|
-
|
56
|
-
# Determine relevant part of compilation stack
|
57
|
-
stack_begin = @@compilation_stack.index(self)
|
58
|
-
stack_end = @@compilation_stack.size
|
59
|
-
relevant_stack_part = @@compilation_stack.last(stack_end - stack_begin)
|
60
|
-
|
61
|
-
# Print relevant part of compilation stack
|
62
|
-
relevant_stack_part.each_with_index do |page, i|
|
63
|
-
$stderr.puts "#{i} #{page._content_filename}"
|
64
|
-
end
|
65
|
-
end
|
66
|
-
exit
|
67
|
-
# Compile if not yet compiled
|
68
|
-
elsif self[:content].nil?
|
69
|
-
# Add to stack
|
70
|
-
@@compilation_stack.push(self)
|
71
|
-
|
72
|
-
# Read page
|
73
|
-
content = File.read(self._content_filename)
|
74
|
-
|
75
|
-
# Compile page
|
76
|
-
begin
|
77
|
-
assigns = { :page => self, :pages => @@pages }
|
78
|
-
# TODO set more custom options
|
79
|
-
params = { :assigns => assigns }
|
80
|
-
params[:haml_options] = (self[:haml_options] || {}).symbolize_keys
|
81
|
-
content = content.filter(self.filters, params)
|
82
|
-
rescue Exception => exception
|
83
|
-
handle_exception(exception, "compiling page '#{self[:_content_filename]}'")
|
84
|
-
end
|
85
|
-
@attributes[:content] = content
|
86
|
-
@@compilation_stack.pop
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
end
|
91
|
-
end
|