nanoc3 3.0.9 → 3.1.0a1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +1 -1
- data/NEWS.md +360 -0
- data/README.md +85 -0
- data/Rakefile +2 -2
- data/bin/nanoc3 +0 -4
- data/lib/nanoc3/base/code_snippet.rb +14 -6
- data/lib/nanoc3/base/compiler.rb +68 -49
- data/lib/nanoc3/base/compiler_dsl.rb +70 -29
- data/lib/nanoc3/base/context.rb +47 -0
- data/lib/nanoc3/base/core_ext/array.rb +4 -0
- data/lib/nanoc3/base/core_ext/hash.rb +5 -1
- data/lib/nanoc3/base/core_ext/string.rb +2 -0
- data/lib/nanoc3/base/data_source.rb +132 -96
- data/lib/nanoc3/base/dependency_tracker.rb +160 -185
- data/lib/nanoc3/base/directed_graph.rb +252 -0
- data/lib/nanoc3/base/errors.rb +52 -4
- data/lib/nanoc3/base/filter.rb +43 -28
- data/lib/nanoc3/base/item.rb +93 -25
- data/lib/nanoc3/base/item_rep.rb +166 -55
- data/lib/nanoc3/base/layout.rb +16 -13
- data/lib/nanoc3/base/notification_center.rb +28 -12
- data/lib/nanoc3/base/plugin_registry.rb +158 -0
- data/lib/nanoc3/base/rule.rb +27 -8
- data/lib/nanoc3/base/rule_context.rb +59 -46
- data/lib/nanoc3/base/site.rb +124 -77
- data/lib/nanoc3/base.rb +7 -2
- data/lib/nanoc3/cli/base.rb +4 -1
- data/lib/nanoc3/cli/commands/autocompile.rb +5 -4
- data/lib/nanoc3/cli/commands/compile.rb +28 -7
- data/lib/nanoc3/cli/commands/create_item.rb +1 -1
- data/lib/nanoc3/cli/commands/create_layout.rb +1 -1
- data/lib/nanoc3/cli/commands/create_site.rb +46 -22
- data/lib/nanoc3/cli/commands/debug.rb +100 -0
- data/lib/nanoc3/cli/commands/help.rb +1 -1
- data/lib/nanoc3/cli/commands/info.rb +1 -1
- data/lib/nanoc3/cli/commands/view.rb +85 -0
- data/lib/nanoc3/cli/commands.rb +2 -0
- data/lib/nanoc3/cli/logger.rb +7 -0
- data/lib/nanoc3/cli.rb +0 -3
- data/lib/nanoc3/data_sources/{delicious.rb → deprecated/delicious.rb} +1 -24
- data/lib/nanoc3/data_sources/{last_fm.rb → deprecated/last_fm.rb} +1 -27
- data/lib/nanoc3/data_sources/{twitter.rb → deprecated/twitter.rb} +1 -14
- data/lib/nanoc3/data_sources/filesystem.rb +188 -176
- data/lib/nanoc3/data_sources/filesystem_unified.rb +107 -0
- data/lib/nanoc3/data_sources/filesystem_verbose.rb +80 -0
- data/lib/nanoc3/data_sources.rb +18 -9
- data/lib/nanoc3/extra/core_ext/enumerable.rb +39 -0
- data/lib/nanoc3/extra/core_ext/time.rb +2 -2
- data/lib/nanoc3/extra/core_ext.rb +1 -0
- data/lib/nanoc3/extra/deployers/rsync.rb +49 -3
- data/lib/nanoc3/extra/file_proxy.rb +7 -0
- data/lib/nanoc3/extra/vcs.rb +25 -24
- data/lib/nanoc3/extra/vcses/bazaar.rb +4 -0
- data/lib/nanoc3/extra/vcses/dummy.rb +4 -0
- data/lib/nanoc3/extra/vcses/git.rb +4 -0
- data/lib/nanoc3/extra/vcses/mercurial.rb +4 -0
- data/lib/nanoc3/extra/vcses/subversion.rb +4 -0
- data/lib/nanoc3/extra.rb +4 -1
- data/lib/nanoc3/filters/erb.rb +1 -1
- data/lib/nanoc3/filters/erubis.rb +1 -1
- data/lib/nanoc3/filters/haml.rb +1 -1
- data/lib/nanoc3/filters/kramdown.rb +14 -0
- data/lib/nanoc3/filters/maruku.rb +1 -1
- data/lib/nanoc3/filters/rainpress.rb +1 -1
- data/lib/nanoc3/filters/rdiscount.rb +3 -1
- data/lib/nanoc3/filters.rb +2 -0
- data/lib/nanoc3/helpers/blogging.rb +91 -75
- data/lib/nanoc3/helpers/breadcrumbs.rb +18 -10
- data/lib/nanoc3/helpers/capturing.rb +24 -29
- data/lib/nanoc3/helpers/filtering.rb +20 -17
- data/lib/nanoc3/helpers/html_escape.rb +7 -4
- data/lib/nanoc3/helpers/link_to.rb +51 -41
- data/lib/nanoc3/helpers/rendering.rb +15 -8
- data/lib/nanoc3/helpers/tagging.rb +27 -21
- data/lib/nanoc3/helpers/text.rb +12 -8
- data/lib/nanoc3/helpers/xml_sitemap.rb +13 -15
- data/lib/nanoc3/tasks/deploy/rsync.rake +4 -1
- data/lib/nanoc3/tasks.rb +2 -1
- data/lib/nanoc3.rb +24 -1
- metadata +43 -87
- data/NEWS.rdoc +0 -328
- data/README.rdoc +0 -83
- data/lib/nanoc3/base/plugin.rb +0 -88
- data/lib/nanoc3/base/preprocessor_context.rb +0 -37
- data/lib/nanoc3/data_sources/filesystem_combined.rb +0 -214
- data/lib/nanoc3/data_sources/filesystem_common.rb +0 -22
- data/lib/nanoc3/data_sources/filesystem_compact.rb +0 -256
- data/lib/nanoc3/extra/context.rb +0 -24
- data/lib/nanoc3/package.rb +0 -107
- data/vendor/cri/ChangeLog +0 -0
- data/vendor/cri/LICENSE +0 -19
- data/vendor/cri/NEWS +0 -0
- data/vendor/cri/README +0 -4
- data/vendor/cri/Rakefile +0 -25
- data/vendor/cri/lib/cri/base.rb +0 -153
- data/vendor/cri/lib/cri/command.rb +0 -105
- data/vendor/cri/lib/cri/core_ext/string.rb +0 -41
- data/vendor/cri/lib/cri/core_ext.rb +0 -8
- data/vendor/cri/lib/cri/option_parser.rb +0 -186
- data/vendor/cri/lib/cri.rb +0 -12
- data/vendor/cri/test/test_base.rb +0 -6
- data/vendor/cri/test/test_command.rb +0 -6
- data/vendor/cri/test/test_core_ext.rb +0 -21
- data/vendor/cri/test/test_option_parser.rb +0 -279
@@ -2,42 +2,57 @@
|
|
2
2
|
|
3
3
|
module Nanoc3
|
4
4
|
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
5
|
+
# Responsible for loading site data. It is the (abstract) superclass for all
|
6
|
+
# data sources. Subclasses must at least implement the data reading methods
|
7
|
+
# ({#items} and {#layouts}); all other methods involving data manipulation
|
8
|
+
# are optional.
|
9
9
|
#
|
10
|
-
# Apart from the methods for loading and storing data, there are the
|
11
|
-
# and
|
12
|
-
# data source. These should be overridden in subclasses. The
|
13
|
-
# method wraps
|
10
|
+
# Apart from the methods for loading and storing data, there are the {#up}
|
11
|
+
# and {#down} methods for bringing up and tearing down the connection to the
|
12
|
+
# data source. These should be overridden in subclasses. The {#loading}
|
13
|
+
# method wraps {#up} and {#down}. {#loading} is a convenience method for the
|
14
|
+
# more low-level methods {#use} and {#unuse}, which respectively increment
|
15
|
+
# and decrement the reference count; when the reference count goes from 0 to
|
16
|
+
# 1, the data source will be loaded ({#up} will be called) and when the
|
17
|
+
# reference count goes from 1 to 0, the data source will be unloaded
|
18
|
+
# ({#down} will be called).
|
14
19
|
#
|
15
|
-
# The
|
16
|
-
# first time.
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
20
|
+
# The {#setup} method is used for setting up a site's data source for the
|
21
|
+
# first time.
|
22
|
+
#
|
23
|
+
# @abstract Subclasses should at least implement {#items} and {#layouts}. If
|
24
|
+
# the data source should support creating items and layouts using the
|
25
|
+
# `create_item` and `create_layout` CLI commands, the {#setup},
|
26
|
+
# {#create_item} and {#create_layout} methods should be implemented as well.
|
27
|
+
class DataSource
|
28
|
+
|
29
|
+
# @return [String] The root path where items returned by this data source
|
30
|
+
# should be mounted.
|
21
31
|
attr_reader :items_root
|
22
32
|
|
23
|
-
#
|
24
|
-
# should be mounted.
|
33
|
+
# @return [String] The root path where layouts returned by this data
|
34
|
+
# source should be mounted.
|
25
35
|
attr_reader :layouts_root
|
26
36
|
|
27
|
-
#
|
28
|
-
#
|
37
|
+
# @return [Hash] The configuration for this data source. For example,
|
38
|
+
# online data sources could contain authentication details.
|
29
39
|
attr_reader :config
|
30
40
|
|
41
|
+
extend Nanoc3::PluginRegistry::PluginMethods
|
42
|
+
|
31
43
|
# Creates a new data source for the given site.
|
32
44
|
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
#
|
45
|
+
# @param [Nanoc3::Site] site The site this data source belongs to.
|
46
|
+
#
|
47
|
+
# @param [String] items_root The prefix that should be given to all items
|
48
|
+
# returned by the #items method (comparable to mount points for
|
49
|
+
# filesystems in Unix-ish OSes).
|
50
|
+
#
|
51
|
+
# @param [String] layouts_root The prefix that should be given to all
|
52
|
+
# layouts returned by the #layouts method (comparable to mount points
|
53
|
+
# for filesystems in Unix-ish OSes).
|
54
|
+
#
|
55
|
+
# @param [Hash] config The configuration for this data source.
|
41
56
|
def initialize(site, items_root, layouts_root, config)
|
42
57
|
@site = site
|
43
58
|
@items_root = items_root
|
@@ -47,27 +62,14 @@ module Nanoc3
|
|
47
62
|
@references = 0
|
48
63
|
end
|
49
64
|
|
50
|
-
#
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
#
|
56
|
-
|
57
|
-
|
58
|
-
end
|
59
|
-
|
60
|
-
# Registers the given class as a data source with the given identifier.
|
61
|
-
def self.register(class_or_name, *identifiers)
|
62
|
-
Nanoc3::Plugin.register(Nanoc3::DataSource, class_or_name, *identifiers)
|
63
|
-
end
|
64
|
-
|
65
|
-
# Loads the data source when necessary (calling +up+), yields, and unloads
|
66
|
-
# the data source when it is not being used elsewhere. All data source
|
67
|
-
# queries and data manipulations should be wrapped in a +loading+ block;
|
68
|
-
# it ensures that the data source is loaded when necessary and makes sure
|
69
|
-
# the data source does not get unloaded while it is still being used
|
70
|
-
# elsewhere.
|
65
|
+
# Loads the data source when necessary (calling {#up}), yields, and
|
66
|
+
# unloads (using {#down}) the data source when it is not being used
|
67
|
+
# elsewhere. All data source queries and data manipulations should be
|
68
|
+
# wrapped in a {#loading} block; it ensures that the data source is loaded
|
69
|
+
# when necessary and makes sure the data source does not get unloaded
|
70
|
+
# while it is still being used elsewhere.
|
71
|
+
#
|
72
|
+
# @return [void]
|
71
73
|
def loading
|
72
74
|
use
|
73
75
|
yield
|
@@ -78,10 +80,10 @@ module Nanoc3
|
|
78
80
|
# Marks the data source as used by the caller.
|
79
81
|
#
|
80
82
|
# Calling this method increases the internal reference count. When the
|
81
|
-
# data source is used for the first time (first #use call), the data
|
82
|
-
# source will be loaded (#up will be called).
|
83
|
-
#
|
84
|
-
#
|
83
|
+
# data source is used for the first time (first {#use} call), the data
|
84
|
+
# source will be loaded ({#up} will be called).
|
85
|
+
#
|
86
|
+
# @return [void]
|
85
87
|
def use
|
86
88
|
up if @references == 0
|
87
89
|
@references += 1
|
@@ -89,44 +91,47 @@ module Nanoc3
|
|
89
91
|
|
90
92
|
# Marks the data source as unused by the caller.
|
91
93
|
#
|
92
|
-
# Calling this method
|
93
|
-
#
|
94
|
-
#
|
95
|
-
#
|
96
|
-
#
|
94
|
+
# Calling this method decreases the internal reference count. When the
|
95
|
+
# reference count reaches zero, i.e. when the data source is not used any
|
96
|
+
# more, the data soruce will be unloaded ({#down} will be called).
|
97
|
+
#
|
98
|
+
# @return [void]
|
97
99
|
def unuse
|
98
100
|
@references -= 1
|
99
101
|
down if @references == 0
|
100
102
|
end
|
101
103
|
|
102
|
-
|
103
|
-
|
104
|
-
#
|
105
|
-
#
|
106
|
-
# may
|
107
|
-
#
|
104
|
+
# Brings up the connection to the data. Depending on the way data is
|
105
|
+
# stored, this may not be necessary. This is the ideal place to connect to
|
106
|
+
# the database, for example.
|
107
|
+
#
|
108
|
+
# Subclasses may override this method, but are not required to do so; the
|
109
|
+
# default implementation simply does nothing.
|
108
110
|
#
|
109
|
-
#
|
111
|
+
# @return [void]
|
110
112
|
def up
|
111
113
|
end
|
112
114
|
|
113
|
-
# Brings down the connection to the data. This
|
114
|
-
#
|
115
|
-
#
|
115
|
+
# Brings down the connection to the data. This method should undo the
|
116
|
+
# effects of the {#up} method. For example, a database connection
|
117
|
+
# established in {#up} should be closed in this method.
|
116
118
|
#
|
117
|
-
# Subclasses may
|
119
|
+
# Subclasses may override this method, but are not required to do so; the
|
120
|
+
# default implementation simply does nothing.
|
121
|
+
#
|
122
|
+
# @return [void]
|
118
123
|
def down
|
119
124
|
end
|
120
125
|
|
121
|
-
########## Creating/updating
|
122
|
-
|
123
126
|
# Creates the bare minimum essentials for this data source to work. This
|
124
127
|
# action will likely be destructive. This method should not create sample
|
125
|
-
# data such as a default home page, a default layout, etc. For example,
|
126
|
-
#
|
128
|
+
# data such as a default home page, a default layout, etc. For example,
|
129
|
+
# when using a database, this is where you should create the necessary
|
127
130
|
# tables for the data source to function properly.
|
128
131
|
#
|
129
|
-
#
|
132
|
+
# @abstract
|
133
|
+
#
|
134
|
+
# @return [void]
|
130
135
|
def setup
|
131
136
|
not_implemented('setup')
|
132
137
|
end
|
@@ -135,53 +140,84 @@ module Nanoc3
|
|
135
140
|
# version of a data source may store content in a different format, and
|
136
141
|
# this method will update the stored content to this newer format.
|
137
142
|
#
|
138
|
-
# Subclasses may
|
143
|
+
# Subclasses may override this method, but are not required to do so; the
|
144
|
+
# default implementation simply does nothing.
|
145
|
+
#
|
146
|
+
# @return [void]
|
139
147
|
def update
|
140
148
|
end
|
141
149
|
|
142
|
-
|
143
|
-
|
144
|
-
# Returns the list of items (represented by Nanoc3::Item) in this site.
|
150
|
+
# Returns the list of items (represented by {Nanoc3::Item}) in this site.
|
145
151
|
# The default implementation simply returns an empty array.
|
146
152
|
#
|
147
|
-
# Subclasses should not prepend items_root to the item's identifiers, as
|
153
|
+
# Subclasses should not prepend `items_root` to the item's identifiers, as
|
148
154
|
# this will be done automatically.
|
149
155
|
#
|
150
|
-
# Subclasses may
|
156
|
+
# Subclasses may override this method, but are not required to do so; the
|
157
|
+
# default implementation simply does nothing.
|
158
|
+
#
|
159
|
+
# @return [Array<Nanoc3::Item>] A list of items
|
151
160
|
def items
|
152
161
|
[]
|
153
162
|
end
|
154
163
|
|
155
|
-
# Returns the list of layouts (represented by Nanoc3::Layout) in this
|
164
|
+
# Returns the list of layouts (represented by {Nanoc3::Layout}) in this
|
156
165
|
# site. The default implementation simply returns an empty array.
|
157
166
|
#
|
158
|
-
# Subclasses should prepend layout_root to the layout's identifiers,
|
159
|
-
# this is not done automatically.
|
167
|
+
# Subclasses should prepend `layout_root` to the layout's identifiers,
|
168
|
+
# since this is not done automatically.
|
169
|
+
#
|
170
|
+
# Subclasses may override this method, but are not required to do so; the
|
171
|
+
# default implementation simply does nothing.
|
160
172
|
#
|
161
|
-
#
|
173
|
+
# @return [Array<Nanoc3::Layout>] A list of layouts
|
162
174
|
def layouts
|
163
175
|
[]
|
164
176
|
end
|
165
177
|
|
166
|
-
#
|
167
|
-
#
|
168
|
-
#
|
169
|
-
#
|
178
|
+
# Creates a new item with the given content, attributes and identifier. No
|
179
|
+
# instance of {Nanoc3::Item} will be created; this method creates the item
|
180
|
+
# in the data source so that it can be loaded and turned into a
|
181
|
+
# {Nanoc3::Item} instance by the {#items} method.
|
170
182
|
#
|
171
|
-
#
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
#
|
179
|
-
|
183
|
+
# @abstract
|
184
|
+
#
|
185
|
+
# @param [String] content
|
186
|
+
#
|
187
|
+
# @param [Hash] attributes
|
188
|
+
#
|
189
|
+
# @param [String] identifier
|
190
|
+
#
|
191
|
+
# @param [Hash] params Extra parameters to give to the data source. This
|
192
|
+
# can be used to influence the way items are stored. For example,
|
193
|
+
# filesystem data sources could use this to pass the extension of the
|
194
|
+
# files that should be generated.
|
195
|
+
#
|
196
|
+
# @return [void]
|
197
|
+
def create_item(content, attributes, identifier, params={})
|
180
198
|
not_implemented('create_item')
|
181
199
|
end
|
182
200
|
|
183
201
|
# Creates a new layout with the given content, attributes and identifier.
|
184
|
-
|
202
|
+
# No instance of {Nanoc3::Layout} will be created; this method creates the
|
203
|
+
# layout in the data source so that it can be loaded and turned into a
|
204
|
+
# {Nanoc3::Layout} instance by the {#layouts} method.
|
205
|
+
#
|
206
|
+
# @abstract
|
207
|
+
#
|
208
|
+
# @param [String] content
|
209
|
+
#
|
210
|
+
# @param [Hash] attributes
|
211
|
+
#
|
212
|
+
# @param [String] identifier
|
213
|
+
#
|
214
|
+
# @param [Hash] params Extra parameters to give to the data source. This
|
215
|
+
# can be used to influence the way items are stored. For example,
|
216
|
+
# filesystem data sources could use this to pass the extension of the
|
217
|
+
# files that should be generated.
|
218
|
+
#
|
219
|
+
# @return [void]
|
220
|
+
def create_layout(content, attributes, identifier, params={})
|
185
221
|
not_implemented('create_layout')
|
186
222
|
end
|
187
223
|
|