nanoc3 3.1.0a2 → 3.1.0a3
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +1 -1
- data/NEWS.md +12 -2
- data/README.md +2 -0
- data/lib/nanoc3/base/code_snippet.rb +6 -2
- data/lib/nanoc3/base/compiler.rb +9 -6
- data/lib/nanoc3/base/compiler_dsl.rb +15 -9
- data/lib/nanoc3/base/data_source.rb +14 -14
- data/lib/nanoc3/base/dependency_tracker.rb +9 -9
- data/lib/nanoc3/base/directed_graph.rb +6 -7
- data/lib/nanoc3/base/errors.rb +48 -13
- data/lib/nanoc3/base/filter.rb +62 -16
- data/lib/nanoc3/base/item.rb +63 -20
- data/lib/nanoc3/base/item_rep.rb +117 -48
- data/lib/nanoc3/base/layout.rb +18 -5
- data/lib/nanoc3/base/notification_center.rb +8 -8
- data/lib/nanoc3/base/plugin_registry.rb +9 -9
- data/lib/nanoc3/base/rule.rb +8 -8
- data/lib/nanoc3/base/rule_context.rb +5 -5
- data/lib/nanoc3/base/site.rb +33 -29
- data/lib/nanoc3/cli/base.rb +1 -1
- data/lib/nanoc3/cli/commands/create_site.rb +12 -14
- data/lib/nanoc3/cli.rb +0 -1
- data/lib/nanoc3/data_sources/filesystem.rb +12 -2
- data/lib/nanoc3/data_sources/filesystem_unified.rb +22 -19
- data/lib/nanoc3/extra/auto_compiler.rb +12 -3
- data/lib/nanoc3/extra/chick.rb +12 -6
- data/lib/nanoc3/extra/deployers/rsync.rb +30 -27
- data/lib/nanoc3/extra/deployers.rb +0 -1
- data/lib/nanoc3/extra/file_proxy.rb +2 -15
- data/lib/nanoc3/extra/validators/links.rb +242 -0
- data/lib/nanoc3/extra/validators/w3c.rb +49 -25
- data/lib/nanoc3/extra/validators.rb +2 -2
- data/lib/nanoc3/extra/vcs.rb +1 -1
- data/lib/nanoc3/extra.rb +4 -1
- data/lib/nanoc3/helpers/blogging.rb +57 -29
- data/lib/nanoc3/helpers/breadcrumbs.rb +1 -1
- data/lib/nanoc3/helpers/capturing.rb +4 -2
- data/lib/nanoc3/helpers/filtering.rb +2 -1
- data/lib/nanoc3/helpers/link_to.rb +13 -6
- data/lib/nanoc3/helpers/rendering.rb +4 -3
- data/lib/nanoc3/helpers/tagging.rb +7 -6
- data/lib/nanoc3/helpers/text.rb +2 -2
- data/lib/nanoc3/tasks/validate.rake +62 -5
- data/lib/nanoc3.rb +2 -2
- metadata +23 -11
- data/lib/nanoc3/base/core_ext/enumerable.rb +0 -41
data/lib/nanoc3/base/item.rb
CHANGED
@@ -22,33 +22,71 @@ module Nanoc3
|
|
22
22
|
# @return [Array<Nanoc3::ItemRep>] This item’s list of item reps
|
23
23
|
attr_reader :reps
|
24
24
|
|
25
|
-
# @return [String] This item's raw, uncompiled content
|
25
|
+
# @return [String] This item's raw, uncompiled content of this item (only
|
26
|
+
# available for textual items)
|
26
27
|
attr_reader :raw_content
|
27
28
|
|
29
|
+
# @return [String] The filename pointing to the file containing this
|
30
|
+
# item’s content (only available for binary items)
|
31
|
+
attr_reader :raw_filename
|
32
|
+
|
28
33
|
# @return [Nanoc3::Item, nil] The parent item of this item. This can be
|
29
|
-
#
|
34
|
+
# nil even for non-root items.
|
30
35
|
attr_accessor :parent
|
31
36
|
|
32
37
|
# @return [Array<Nanoc3::Item>] The child items of this item
|
33
38
|
attr_accessor :children
|
34
39
|
|
35
40
|
# @return [Boolean] Whether or not this item is outdated because of its
|
36
|
-
#
|
41
|
+
# dependencies are outdated
|
37
42
|
attr_accessor :outdated_due_to_dependencies
|
38
43
|
alias_method :outdated_due_to_dependencies?, :outdated_due_to_dependencies
|
39
44
|
|
40
|
-
#
|
45
|
+
# Creates a new item with the given content or filename, attributes and
|
46
|
+
# identifier.
|
47
|
+
#
|
48
|
+
# Note that the API in 3.1 has changed a bit since 3.0; the API remains
|
49
|
+
# backwards compatible, however. Passing the modification time as the 4th
|
50
|
+
# parameter is deprecated; pass it as the `:mtime` method option instead.
|
51
|
+
#
|
52
|
+
# @param [String] raw_content_or_raw_filename The uncompiled item content
|
53
|
+
# (if it is a textual item) or the path to the filename containing the
|
54
|
+
# content (if it is a binary item).
|
41
55
|
#
|
42
56
|
# @param [Hash] attributes A hash containing this item's attributes.
|
43
57
|
#
|
44
58
|
# @param [String] identifier This item's identifier.
|
45
59
|
#
|
46
|
-
# @param [
|
47
|
-
|
48
|
-
|
60
|
+
# @param [Time, Hash, nil] params_or_mtime Extra parameters for the item,
|
61
|
+
# or the time when this item was last modified (deprecated).
|
62
|
+
#
|
63
|
+
# @option params_or_mtime [Time, nil] :mtime (nil) The time when this item
|
64
|
+
# was last modified
|
65
|
+
#
|
66
|
+
# @option params_or_mtime [Symbol, nil] :binary (true) Whether or not this
|
67
|
+
# item is binary
|
68
|
+
def initialize(raw_content_or_raw_filename, attributes, identifier, params_or_mtime=nil)
|
69
|
+
# Get params and mtime
|
70
|
+
# TODO [in nanoc 4.0] clean this up
|
71
|
+
if params_or_mtime.nil? || params_or_mtime.is_a?(Time)
|
72
|
+
params = {}
|
73
|
+
@mtime = params_or_mtime
|
74
|
+
elsif params_or_mtime.is_a?(Hash)
|
75
|
+
params = params_or_mtime
|
76
|
+
@mtime = params[:mtime]
|
77
|
+
end
|
78
|
+
|
79
|
+
# Get type and raw content or raw filename
|
80
|
+
@is_binary = params.has_key?(:binary) ? params[:binary] : true
|
81
|
+
if @is_binary
|
82
|
+
@raw_filename = raw_content_or_raw_filename
|
83
|
+
else
|
84
|
+
@raw_content = raw_content_or_raw_filename
|
85
|
+
end
|
86
|
+
|
87
|
+
# Get rest of params
|
49
88
|
@attributes = attributes.symbolize_keys
|
50
89
|
@identifier = identifier.cleaned_identifier
|
51
|
-
@mtime = mtime
|
52
90
|
|
53
91
|
@parent = nil
|
54
92
|
@children = []
|
@@ -61,7 +99,7 @@ module Nanoc3
|
|
61
99
|
# @param [Symbol] rep_name The name of the representation to return
|
62
100
|
#
|
63
101
|
# @return [Nanoc3::ItemRep] The representation with the given name
|
64
|
-
def
|
102
|
+
def rep_named(rep_name)
|
65
103
|
@reps.find { |r| r.name == rep_name }
|
66
104
|
end
|
67
105
|
|
@@ -70,17 +108,17 @@ module Nanoc3
|
|
70
108
|
# content easier.
|
71
109
|
#
|
72
110
|
# @option params [String] :rep (:default) The name of the representation
|
73
|
-
#
|
74
|
-
#
|
111
|
+
# from which the compiled content should be fetched. By default, the
|
112
|
+
# compiled content will be fetched from the default representation.
|
75
113
|
#
|
76
114
|
# @option params [String] :snapshot (:last) The name of the snapshot from
|
77
|
-
#
|
78
|
-
#
|
79
|
-
#
|
115
|
+
# which to fetch the compiled content. By default, the fully compiled
|
116
|
+
# content will be fetched, with all filters and layouts applied--not the
|
117
|
+
# pre-layout content.
|
80
118
|
#
|
81
119
|
# @return [String] The compiled content of the given rep (or the default
|
82
|
-
#
|
83
|
-
#
|
120
|
+
# rep if no rep is specified) at the given snapshot (or the default
|
121
|
+
# snapshot if no snapshot is specified)
|
84
122
|
def compiled_content(params={})
|
85
123
|
# Get rep
|
86
124
|
rep_name = params[:rep] || :default
|
@@ -98,11 +136,11 @@ module Nanoc3
|
|
98
136
|
# method that makes fetching the path of a rep easier.
|
99
137
|
#
|
100
138
|
# @option params [String] :rep (:default) The name of the representation
|
101
|
-
#
|
102
|
-
#
|
139
|
+
# from which the path should be fetched. By default, the path will be
|
140
|
+
# fetched from the default representation.
|
103
141
|
#
|
104
142
|
# @return [String] The path of the given rep ( or the default rep if no
|
105
|
-
#
|
143
|
+
# rep is specified)
|
106
144
|
def path(params={})
|
107
145
|
rep_name = params[:rep] || :default
|
108
146
|
|
@@ -138,6 +176,11 @@ module Nanoc3
|
|
138
176
|
@attributes[key] = value
|
139
177
|
end
|
140
178
|
|
179
|
+
# @return [Boolean] True if the item is binary; false if it is not
|
180
|
+
def binary?
|
181
|
+
!!@is_binary
|
182
|
+
end
|
183
|
+
|
141
184
|
# Determines whether this item (or rather, its reps) is outdated and
|
142
185
|
# should be recompiled (or rather, its reps should be recompiled).
|
143
186
|
#
|
@@ -147,7 +190,7 @@ module Nanoc3
|
|
147
190
|
end
|
148
191
|
|
149
192
|
def inspect
|
150
|
-
"<#{self.class}:0x#{self.object_id.to_s(16)} identifier=#{self.identifier}>"
|
193
|
+
"<#{self.class}:0x#{self.object_id.to_s(16)} identifier=#{self.identifier} binary?=#{self.binary?}>"
|
151
194
|
end
|
152
195
|
|
153
196
|
end
|
data/lib/nanoc3/base/item_rep.rb
CHANGED
@@ -27,46 +27,45 @@ module Nanoc3
|
|
27
27
|
attr_reader :name
|
28
28
|
|
29
29
|
# @return [Boolean] true if this rep is forced to be dirty (e.g. because
|
30
|
-
#
|
30
|
+
# of the `--force` commandline option); false otherwise
|
31
31
|
attr_accessor :force_outdated
|
32
32
|
|
33
33
|
# @return [Boolean] true if this rep’s output file has changed since the
|
34
|
-
#
|
34
|
+
# last time it was compiled; false otherwise
|
35
35
|
attr_accessor :modified
|
36
36
|
alias_method :modified?, :modified
|
37
37
|
|
38
38
|
# @return [Boolean] true if this rep’s output file was created during the
|
39
|
-
#
|
39
|
+
# current or last compilation session; false otherwise
|
40
40
|
attr_accessor :created
|
41
41
|
alias_method :created?, :created
|
42
42
|
|
43
|
-
# @return [Boolean] true if this representation has already been
|
44
|
-
#
|
45
|
-
# otherwise
|
43
|
+
# @return [Boolean] true if this representation has already been compiled
|
44
|
+
# during the current or last compilation session; false otherwise
|
46
45
|
attr_accessor :compiled
|
47
46
|
alias_method :compiled?, :compiled
|
48
47
|
|
49
48
|
# @return [Boolean] true if this representation’s compiled content has
|
50
|
-
#
|
51
|
-
#
|
49
|
+
# been written during the current or last compilation session; false
|
50
|
+
# otherwise
|
52
51
|
attr_reader :written
|
53
52
|
alias_method :written?, :written
|
54
53
|
|
55
54
|
# @return [String] The item rep's path, as used when being linked to. It
|
56
|
-
#
|
57
|
-
#
|
58
|
-
#
|
55
|
+
# starts with a slash and it is relative to the output directory. It does
|
56
|
+
# not include the path to the output directory. It will not include the
|
57
|
+
# filename if the filename is an index filename.
|
59
58
|
attr_accessor :path
|
60
59
|
|
61
60
|
# @return [String] The item rep's raw path. It is relative to the current
|
62
|
-
#
|
63
|
-
#
|
61
|
+
# working directory and includes the path to the output directory. It also
|
62
|
+
# includes the filename, even if it is an index filename.
|
64
63
|
attr_accessor :raw_path
|
65
64
|
|
66
65
|
# Creates a new item representation for the given item.
|
67
66
|
#
|
68
67
|
# @param [Nanoc3::Item] item The item to which the new representation will
|
69
|
-
#
|
68
|
+
# belong.
|
70
69
|
#
|
71
70
|
# @param [Symbol] name The unique name for the new item representation.
|
72
71
|
def initialize(item, name)
|
@@ -74,12 +73,19 @@ module Nanoc3
|
|
74
73
|
@item = item
|
75
74
|
@name = name
|
76
75
|
|
77
|
-
# Initialize content
|
78
|
-
@
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
76
|
+
# Initialize content and filenames
|
77
|
+
if @item.binary?
|
78
|
+
@filenames = {
|
79
|
+
:raw => @item.raw_filename,
|
80
|
+
:last => @item.raw_filename
|
81
|
+
}
|
82
|
+
else
|
83
|
+
@content = {
|
84
|
+
:raw => @item.raw_content,
|
85
|
+
:last => @item.raw_content,
|
86
|
+
:pre => @item.raw_content
|
87
|
+
}
|
88
|
+
end
|
83
89
|
@old_content = nil
|
84
90
|
|
85
91
|
# Reset flags
|
@@ -91,7 +97,7 @@ module Nanoc3
|
|
91
97
|
end
|
92
98
|
|
93
99
|
# @return [Boolean] true if this item rep's output file is outdated and
|
94
|
-
#
|
100
|
+
# must be regenerated, false otherwise
|
95
101
|
def outdated?
|
96
102
|
# Outdated if we don't know
|
97
103
|
return true if @item.mtime.nil?
|
@@ -131,26 +137,40 @@ module Nanoc3
|
|
131
137
|
end
|
132
138
|
|
133
139
|
# @return [Hash] The assignments that should be available when compiling
|
134
|
-
#
|
140
|
+
# the content.
|
135
141
|
def assigns
|
136
|
-
|
137
|
-
:
|
142
|
+
if item.binary?
|
143
|
+
content_or_filename_assigns = { :filename => @filenames[:last] }
|
144
|
+
else
|
145
|
+
content_or_filename_assigns = { :content => @content[:last] }
|
146
|
+
end
|
147
|
+
|
148
|
+
content_or_filename_assigns.merge({
|
138
149
|
:item => self.item,
|
139
150
|
:item_rep => self,
|
140
151
|
:items => self.item.site.items,
|
141
152
|
:layouts => self.item.site.layouts,
|
142
153
|
:config => self.item.site.config,
|
143
154
|
:site => self.item.site
|
144
|
-
}
|
155
|
+
})
|
145
156
|
end
|
146
157
|
|
147
158
|
# Returns the compiled content from a given snapshot.
|
148
159
|
#
|
149
|
-
# @option params [String] :snapshot The name of the snapshot from
|
150
|
-
#
|
151
|
-
#
|
152
|
-
#
|
160
|
+
# @option params [String] :snapshot The name of the snapshot from which to
|
161
|
+
# fetch the compiled content. By default, the returned compiled content
|
162
|
+
# will be the content compiled right before the first layout call (if
|
163
|
+
# any).
|
164
|
+
#
|
165
|
+
# @return [String] The compiled content at the given snapshot (or the
|
166
|
+
# default snapshot if no snapshot is specified)
|
153
167
|
def compiled_content(params={})
|
168
|
+
# Check whether content can be fetched
|
169
|
+
# TODO get proper exception
|
170
|
+
if @item.binary?
|
171
|
+
raise RuntimeError, "attempted to fetch compiled content from a binary item"
|
172
|
+
end
|
173
|
+
|
154
174
|
# Notify
|
155
175
|
Nanoc3::NotificationCenter.post(:visit_started, self.item)
|
156
176
|
Nanoc3::NotificationCenter.post(:visit_ended, self.item)
|
@@ -186,10 +206,10 @@ module Nanoc3
|
|
186
206
|
# (see {Nanoc3::CompilerDSL#compile}).
|
187
207
|
#
|
188
208
|
# @param [Symbol] filter_name The name of the filter to run the item
|
189
|
-
#
|
209
|
+
# representations' content through
|
190
210
|
#
|
191
211
|
# @param [Hash] filter_args The filter arguments that should be passed to
|
192
|
-
#
|
212
|
+
# the filter's #run method
|
193
213
|
#
|
194
214
|
# @return [void]
|
195
215
|
def filter(filter_name, filter_args={})
|
@@ -198,13 +218,25 @@ module Nanoc3
|
|
198
218
|
raise Nanoc3::Errors::UnknownFilter.new(filter_name) if klass.nil?
|
199
219
|
filter = klass.new(assigns)
|
200
220
|
|
221
|
+
# Check whether filter can be applied
|
222
|
+
if klass.binary? && !item.binary?
|
223
|
+
raise Nanoc3::Errors::CannotUseBinaryFilter.new(self, klass)
|
224
|
+
elsif !klass.binary? && item.binary?
|
225
|
+
raise Nanoc3::Errors::CannotUseTextualFilter.new(self, klass)
|
226
|
+
end
|
227
|
+
|
201
228
|
# Run filter
|
202
229
|
Nanoc3::NotificationCenter.post(:filtering_started, self, filter_name)
|
203
|
-
|
230
|
+
if item.binary?
|
231
|
+
filter.run(@filenames[:last], filter_args)
|
232
|
+
@filenames[:last] = filter.output_filename
|
233
|
+
else
|
234
|
+
@content[:last] = filter.run(@content[:last], filter_args)
|
235
|
+
end
|
204
236
|
Nanoc3::NotificationCenter.post(:filtering_ended, self, filter_name)
|
205
237
|
|
206
238
|
# Create snapshot
|
207
|
-
snapshot(@content[:post] ? :post : :pre)
|
239
|
+
snapshot(@content[:post] ? :post : :pre) unless item.binary?
|
208
240
|
end
|
209
241
|
|
210
242
|
# Lays out the item using the given layout. This method will replace the
|
@@ -214,11 +246,14 @@ module Nanoc3
|
|
214
246
|
# This method is supposed to be called only in a compilation rule block
|
215
247
|
# (see {Nanoc3::CompilerDSL#compile}).
|
216
248
|
#
|
217
|
-
# @param [String] layout_identifier The identifier of the layout the
|
218
|
-
#
|
249
|
+
# @param [String] layout_identifier The identifier of the layout the item
|
250
|
+
# should be laid out with
|
219
251
|
#
|
220
252
|
# @return [void]
|
221
253
|
def layout(layout_identifier)
|
254
|
+
# Check whether item can be laid out
|
255
|
+
raise Nanoc3::Errors::CannotLayoutBinaryItem.new(self) if item.binary?
|
256
|
+
|
222
257
|
# Create "pre" snapshot
|
223
258
|
snapshot(:pre) unless @content[:pre]
|
224
259
|
|
@@ -243,7 +278,8 @@ module Nanoc3
|
|
243
278
|
#
|
244
279
|
# @return [void]
|
245
280
|
def snapshot(snapshot_name)
|
246
|
-
|
281
|
+
target = @item.binary? ? @filenames : @content
|
282
|
+
target[snapshot_name] = target[:last]
|
247
283
|
end
|
248
284
|
|
249
285
|
# Writes the item rep's compiled content to the rep's output file.
|
@@ -259,17 +295,34 @@ module Nanoc3
|
|
259
295
|
# Check if file will be created
|
260
296
|
@created = !File.file?(self.raw_path)
|
261
297
|
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
298
|
+
if @item.binary?
|
299
|
+
# Calculate hash of old content
|
300
|
+
if File.file?(self.raw_path)
|
301
|
+
hash_old = hash(self.raw_path)
|
302
|
+
size_old = File.size(self.raw_path)
|
303
|
+
end
|
304
|
+
|
305
|
+
# Copy
|
306
|
+
FileUtils.cp(@filenames[:last], self.raw_path)
|
307
|
+
@written = true
|
308
|
+
|
309
|
+
# Check if file was modified
|
310
|
+
size_new = File.size(self.raw_path)
|
311
|
+
hash_new = hash(self.raw_path) if size_old == size_new
|
312
|
+
@modified = (size_old != size_new || hash_old != hash_new)
|
313
|
+
else
|
314
|
+
# Remember old content
|
315
|
+
if File.file?(self.raw_path)
|
316
|
+
@old_content = File.read(self.raw_path)
|
317
|
+
end
|
266
318
|
|
267
|
-
|
268
|
-
|
269
|
-
|
319
|
+
# Write
|
320
|
+
File.open(self.raw_path, 'w') { |io| io.write(@content[:last]) }
|
321
|
+
@written = true
|
270
322
|
|
271
|
-
|
272
|
-
|
323
|
+
# Check if file was modified
|
324
|
+
@modified = File.read(self.raw_path) != @old_content
|
325
|
+
end
|
273
326
|
end
|
274
327
|
|
275
328
|
# Creates and returns a diff between the compiled content before the
|
@@ -277,9 +330,13 @@ module Nanoc3
|
|
277
330
|
# compilation session.
|
278
331
|
#
|
279
332
|
# @return [String, nil] The difference between the old and new compiled
|
280
|
-
#
|
281
|
-
#
|
333
|
+
# content in `diff(1)` format, or nil if there is no previous compiled
|
334
|
+
# content
|
282
335
|
def diff
|
336
|
+
# Check if content can be diffed
|
337
|
+
# TODO allow binary diffs
|
338
|
+
return nil if @item.binary?
|
339
|
+
|
283
340
|
# Check if old content exists
|
284
341
|
if @old_content.nil? or self.raw_path.nil?
|
285
342
|
nil
|
@@ -289,7 +346,7 @@ module Nanoc3
|
|
289
346
|
end
|
290
347
|
|
291
348
|
def inspect
|
292
|
-
"<#{self.class}:0x#{self.object_id.to_s(16)} name=#{self.name} item.identifier=#{self.item.identifier}>"
|
349
|
+
"<#{self.class}:0x#{self.object_id.to_s(16)} name=#{self.name} item.identifier=#{self.item.identifier} item.binary?=#{@item.binary?}>"
|
293
350
|
end
|
294
351
|
|
295
352
|
private
|
@@ -342,6 +399,18 @@ module Nanoc3
|
|
342
399
|
nil
|
343
400
|
end
|
344
401
|
|
402
|
+
# Returns a hash of the given filename
|
403
|
+
def hash(filename)
|
404
|
+
digest = Digest::SHA1.new
|
405
|
+
File.open(filename, 'r') do |io|
|
406
|
+
until io.eof
|
407
|
+
data = io.readpartial(2**10)
|
408
|
+
digest.update(data)
|
409
|
+
end
|
410
|
+
end
|
411
|
+
digest.hexdigest
|
412
|
+
end
|
413
|
+
|
345
414
|
end
|
346
415
|
|
347
416
|
end
|
data/lib/nanoc3/base/layout.rb
CHANGED
@@ -16,7 +16,7 @@ module Nanoc3
|
|
16
16
|
attr_reader :attributes
|
17
17
|
|
18
18
|
# @return [String] This layout's identifier, starting and ending with a
|
19
|
-
#
|
19
|
+
# slash
|
20
20
|
attr_accessor :identifier
|
21
21
|
|
22
22
|
# @return [Time] The time when this layout was last modified
|
@@ -24,18 +24,31 @@ module Nanoc3
|
|
24
24
|
|
25
25
|
# Creates a new layout.
|
26
26
|
#
|
27
|
-
# @param [String]
|
27
|
+
# @param [String] raw_content The raw content of this layout.
|
28
28
|
#
|
29
29
|
# @param [Hash] attributes A hash containing this layout's attributes.
|
30
30
|
#
|
31
31
|
# @param [String] identifier This layout's identifier.
|
32
32
|
#
|
33
|
-
# @param [Time, nil]
|
34
|
-
|
33
|
+
# @param [Time, Hash, nil] params_or_mtime Extra parameters for the
|
34
|
+
# layout, or the time when this layout was last modified (deprecated).
|
35
|
+
#
|
36
|
+
# @option params_or_mtime [Time, nil] :mtime (nil) The time when this
|
37
|
+
# layout was last modified
|
38
|
+
def initialize(raw_content, attributes, identifier, params_or_mtime=nil)
|
39
|
+
# Get params and mtime
|
40
|
+
# TODO [in nanoc 4.0] clean this up
|
41
|
+
if params_or_mtime.nil? || params_or_mtime.is_a?(Time)
|
42
|
+
params = {}
|
43
|
+
@mtime = params_or_mtime
|
44
|
+
elsif params_or_mtime.is_a?(Hash)
|
45
|
+
params = params_or_mtime
|
46
|
+
@mtime = params[:mtime]
|
47
|
+
end
|
48
|
+
|
35
49
|
@raw_content = raw_content
|
36
50
|
@attributes = attributes.symbolize_keys
|
37
51
|
@identifier = identifier.cleaned_identifier
|
38
|
-
@mtime = mtime
|
39
52
|
end
|
40
53
|
|
41
54
|
# Requests the attribute with the given key.
|
@@ -17,12 +17,12 @@ module Nanoc3
|
|
17
17
|
# the notification with the given name is received.
|
18
18
|
#
|
19
19
|
# @param [String, Symbol] name The name of the notification that will
|
20
|
-
#
|
20
|
+
# cause the given block to be called.
|
21
21
|
#
|
22
22
|
# @param [String, Symbol, nil] id An identifier for the block. This is
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
23
|
+
# only used to be able to remove the block (using the remove method)
|
24
|
+
# later. Can be nil, but this is not recommended because it prevents
|
25
|
+
# the given notification block from being unregistered.
|
26
26
|
#
|
27
27
|
# @yield [*args] Will be executed with the arguments passed to {.post}
|
28
28
|
#
|
@@ -37,10 +37,10 @@ module Nanoc3
|
|
37
37
|
# Posts a notification with the given name and the given arguments.
|
38
38
|
#
|
39
39
|
# @param [String, Symbol] name The name of the notification that should
|
40
|
-
#
|
40
|
+
# be posted.
|
41
41
|
#
|
42
42
|
# @param args Arguments that wil be passed to the blocks handling the
|
43
|
-
#
|
43
|
+
# notification.
|
44
44
|
#
|
45
45
|
# @return [void]
|
46
46
|
def post(name, *args)
|
@@ -57,10 +57,10 @@ module Nanoc3
|
|
57
57
|
# posted.
|
58
58
|
#
|
59
59
|
# @param [String, Symbol] name The name of the notification that should
|
60
|
-
#
|
60
|
+
# no longer be registered.
|
61
61
|
#
|
62
62
|
# @param [String, Symbol] id The identifier of the block that should be
|
63
|
-
#
|
63
|
+
# removed.
|
64
64
|
#
|
65
65
|
# @return [void]
|
66
66
|
def remove(name, id)
|
@@ -15,7 +15,7 @@ module Nanoc3
|
|
15
15
|
# Sets the identifiers for this plugin.
|
16
16
|
#
|
17
17
|
# @param [Array<Symbol>] identifier A list of identifiers to assign to
|
18
|
-
#
|
18
|
+
# this plugin.
|
19
19
|
#
|
20
20
|
# @return [void]
|
21
21
|
def identifiers(*identifiers)
|
@@ -34,10 +34,10 @@ module Nanoc3
|
|
34
34
|
# Registers the given class as a plugin with the given identifier.
|
35
35
|
#
|
36
36
|
# @param [Class, String] class_or_name The class to register, or a
|
37
|
-
#
|
37
|
+
# string containing the class name to register.
|
38
38
|
#
|
39
39
|
# @param [Array<Symbol>] identifiers A list of identifiers to assign to
|
40
|
-
#
|
40
|
+
# this plugin.
|
41
41
|
#
|
42
42
|
# @return [void]
|
43
43
|
def register(class_or_name, *identifiers)
|
@@ -79,15 +79,15 @@ module Nanoc3
|
|
79
79
|
# Registers the given class as a plugin.
|
80
80
|
#
|
81
81
|
# @param [Class] superclass The superclass of the plugin. For example:
|
82
|
-
#
|
82
|
+
# {Nanoc3::Filter}, {Nanoc3::Extra::VCS}.
|
83
83
|
#
|
84
84
|
# @param [Class, String] class_or_name The class to register. This can be
|
85
|
-
#
|
86
|
-
#
|
87
|
-
#
|
85
|
+
# a string, in which case it will be automatically converted to a proper
|
86
|
+
# class at lookup. For example: `Nanoc3::Filters::ERB`,
|
87
|
+
# `"Nanoc3::Filters::Haml"`.
|
88
88
|
#
|
89
89
|
# @param [Symbol] identifiers One or more symbols identifying the class.
|
90
|
-
#
|
90
|
+
# For example: `:haml`, :`erb`.
|
91
91
|
#
|
92
92
|
# @return [void]
|
93
93
|
def register(superclass, class_or_name, *identifiers)
|
@@ -122,7 +122,7 @@ module Nanoc3
|
|
122
122
|
# Returns a list of all plugins. The returned list of plugins is an array
|
123
123
|
# with array elements in the following format:
|
124
124
|
#
|
125
|
-
#
|
125
|
+
# { :class => ..., :superclass => ..., :identifiers => ... }
|
126
126
|
#
|
127
127
|
# @return [Array<Hash>] A list of all plugins in the format described
|
128
128
|
def all
|
data/lib/nanoc3/base/rule.rb
CHANGED
@@ -6,12 +6,12 @@ module Nanoc3
|
|
6
6
|
class Rule
|
7
7
|
|
8
8
|
# @return [Regexp] The regex that determines which items this rule can be
|
9
|
-
#
|
10
|
-
#
|
9
|
+
# applied to. This rule can be applied to items with a identifier matching
|
10
|
+
# this regex.
|
11
11
|
attr_reader :identifier_regex
|
12
12
|
|
13
13
|
# @return [Symbol] The name of the representation that will be compiled
|
14
|
-
#
|
14
|
+
# using this rule
|
15
15
|
attr_reader :rep_name
|
16
16
|
|
17
17
|
# Creates a new item compilation rule with the given identifier regex,
|
@@ -19,13 +19,13 @@ module Nanoc3
|
|
19
19
|
# item rep as its argument.
|
20
20
|
#
|
21
21
|
# @param [Regexp] identifier_regex A regular expression that will be used
|
22
|
-
#
|
22
|
+
# to determine whether this rule is applicable to certain items.
|
23
23
|
#
|
24
24
|
# @param [String, Symbol] rep_name The name of the item representation
|
25
|
-
#
|
25
|
+
# where this rule can be applied to
|
26
26
|
#
|
27
27
|
# @param [Proc] block A block that will be called when matching items are
|
28
|
-
#
|
28
|
+
# compiled
|
29
29
|
def initialize(identifier_regex, rep_name, block)
|
30
30
|
@identifier_regex = identifier_regex
|
31
31
|
@rep_name = rep_name.to_sym
|
@@ -36,7 +36,7 @@ module Nanoc3
|
|
36
36
|
# @param [Nanoc3::Item] item The item to check
|
37
37
|
#
|
38
38
|
# @return [Boolean] true if this rule can be applied to the given item
|
39
|
-
#
|
39
|
+
# rep, false otherwise
|
40
40
|
def applicable_to?(item)
|
41
41
|
item.identifier =~ @identifier_regex
|
42
42
|
end
|
@@ -44,7 +44,7 @@ module Nanoc3
|
|
44
44
|
# Applies this rule to the given item rep.
|
45
45
|
#
|
46
46
|
# @param [Nanoc3::ItemRep] rep The item representation where this rule
|
47
|
-
#
|
47
|
+
# should be applied to
|
48
48
|
#
|
49
49
|
# @return [void]
|
50
50
|
def apply_to(rep)
|
@@ -17,7 +17,7 @@ module Nanoc3
|
|
17
17
|
# Creates a new rule context for the given iterm representation.
|
18
18
|
#
|
19
19
|
# @param [Nanoc3::ItemRep] rep The item representation for which to create
|
20
|
-
#
|
20
|
+
# a new rule context.
|
21
21
|
def initialize(rep)
|
22
22
|
item = rep.item
|
23
23
|
site = item.site
|
@@ -41,10 +41,10 @@ module Nanoc3
|
|
41
41
|
# @see Nanoc3::ItemRep#filter
|
42
42
|
#
|
43
43
|
# @param [Symbol] filter_name The name of the filter to run the item
|
44
|
-
#
|
44
|
+
# representations' content through
|
45
45
|
#
|
46
46
|
# @param [Hash] filter_args The filter arguments that should be passed to
|
47
|
-
#
|
47
|
+
# the filter's #run method
|
48
48
|
#
|
49
49
|
# @return [void]
|
50
50
|
def filter(filter_name, filter_args={})
|
@@ -56,8 +56,8 @@ module Nanoc3
|
|
56
56
|
#
|
57
57
|
# @see Nanoc3::ItemRep#layout
|
58
58
|
#
|
59
|
-
# @param [String] layout_identifier The identifier of the layout the
|
60
|
-
#
|
59
|
+
# @param [String] layout_identifier The identifier of the layout the item
|
60
|
+
# should be laid out with
|
61
61
|
#
|
62
62
|
# @return [void]
|
63
63
|
def layout(layout_identifier)
|