nanoc3 3.0.9 → 3.1.0a1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. data/LICENSE +1 -1
  2. data/NEWS.md +360 -0
  3. data/README.md +85 -0
  4. data/Rakefile +2 -2
  5. data/bin/nanoc3 +0 -4
  6. data/lib/nanoc3/base/code_snippet.rb +14 -6
  7. data/lib/nanoc3/base/compiler.rb +68 -49
  8. data/lib/nanoc3/base/compiler_dsl.rb +70 -29
  9. data/lib/nanoc3/base/context.rb +47 -0
  10. data/lib/nanoc3/base/core_ext/array.rb +4 -0
  11. data/lib/nanoc3/base/core_ext/hash.rb +5 -1
  12. data/lib/nanoc3/base/core_ext/string.rb +2 -0
  13. data/lib/nanoc3/base/data_source.rb +132 -96
  14. data/lib/nanoc3/base/dependency_tracker.rb +160 -185
  15. data/lib/nanoc3/base/directed_graph.rb +252 -0
  16. data/lib/nanoc3/base/errors.rb +52 -4
  17. data/lib/nanoc3/base/filter.rb +43 -28
  18. data/lib/nanoc3/base/item.rb +93 -25
  19. data/lib/nanoc3/base/item_rep.rb +166 -55
  20. data/lib/nanoc3/base/layout.rb +16 -13
  21. data/lib/nanoc3/base/notification_center.rb +28 -12
  22. data/lib/nanoc3/base/plugin_registry.rb +158 -0
  23. data/lib/nanoc3/base/rule.rb +27 -8
  24. data/lib/nanoc3/base/rule_context.rb +59 -46
  25. data/lib/nanoc3/base/site.rb +124 -77
  26. data/lib/nanoc3/base.rb +7 -2
  27. data/lib/nanoc3/cli/base.rb +4 -1
  28. data/lib/nanoc3/cli/commands/autocompile.rb +5 -4
  29. data/lib/nanoc3/cli/commands/compile.rb +28 -7
  30. data/lib/nanoc3/cli/commands/create_item.rb +1 -1
  31. data/lib/nanoc3/cli/commands/create_layout.rb +1 -1
  32. data/lib/nanoc3/cli/commands/create_site.rb +46 -22
  33. data/lib/nanoc3/cli/commands/debug.rb +100 -0
  34. data/lib/nanoc3/cli/commands/help.rb +1 -1
  35. data/lib/nanoc3/cli/commands/info.rb +1 -1
  36. data/lib/nanoc3/cli/commands/view.rb +85 -0
  37. data/lib/nanoc3/cli/commands.rb +2 -0
  38. data/lib/nanoc3/cli/logger.rb +7 -0
  39. data/lib/nanoc3/cli.rb +0 -3
  40. data/lib/nanoc3/data_sources/{delicious.rb → deprecated/delicious.rb} +1 -24
  41. data/lib/nanoc3/data_sources/{last_fm.rb → deprecated/last_fm.rb} +1 -27
  42. data/lib/nanoc3/data_sources/{twitter.rb → deprecated/twitter.rb} +1 -14
  43. data/lib/nanoc3/data_sources/filesystem.rb +188 -176
  44. data/lib/nanoc3/data_sources/filesystem_unified.rb +107 -0
  45. data/lib/nanoc3/data_sources/filesystem_verbose.rb +80 -0
  46. data/lib/nanoc3/data_sources.rb +18 -9
  47. data/lib/nanoc3/extra/core_ext/enumerable.rb +39 -0
  48. data/lib/nanoc3/extra/core_ext/time.rb +2 -2
  49. data/lib/nanoc3/extra/core_ext.rb +1 -0
  50. data/lib/nanoc3/extra/deployers/rsync.rb +49 -3
  51. data/lib/nanoc3/extra/file_proxy.rb +7 -0
  52. data/lib/nanoc3/extra/vcs.rb +25 -24
  53. data/lib/nanoc3/extra/vcses/bazaar.rb +4 -0
  54. data/lib/nanoc3/extra/vcses/dummy.rb +4 -0
  55. data/lib/nanoc3/extra/vcses/git.rb +4 -0
  56. data/lib/nanoc3/extra/vcses/mercurial.rb +4 -0
  57. data/lib/nanoc3/extra/vcses/subversion.rb +4 -0
  58. data/lib/nanoc3/extra.rb +4 -1
  59. data/lib/nanoc3/filters/erb.rb +1 -1
  60. data/lib/nanoc3/filters/erubis.rb +1 -1
  61. data/lib/nanoc3/filters/haml.rb +1 -1
  62. data/lib/nanoc3/filters/kramdown.rb +14 -0
  63. data/lib/nanoc3/filters/maruku.rb +1 -1
  64. data/lib/nanoc3/filters/rainpress.rb +1 -1
  65. data/lib/nanoc3/filters/rdiscount.rb +3 -1
  66. data/lib/nanoc3/filters.rb +2 -0
  67. data/lib/nanoc3/helpers/blogging.rb +91 -75
  68. data/lib/nanoc3/helpers/breadcrumbs.rb +18 -10
  69. data/lib/nanoc3/helpers/capturing.rb +24 -29
  70. data/lib/nanoc3/helpers/filtering.rb +20 -17
  71. data/lib/nanoc3/helpers/html_escape.rb +7 -4
  72. data/lib/nanoc3/helpers/link_to.rb +51 -41
  73. data/lib/nanoc3/helpers/rendering.rb +15 -8
  74. data/lib/nanoc3/helpers/tagging.rb +27 -21
  75. data/lib/nanoc3/helpers/text.rb +12 -8
  76. data/lib/nanoc3/helpers/xml_sitemap.rb +13 -15
  77. data/lib/nanoc3/tasks/deploy/rsync.rake +4 -1
  78. data/lib/nanoc3/tasks.rb +2 -1
  79. data/lib/nanoc3.rb +24 -1
  80. metadata +43 -87
  81. data/NEWS.rdoc +0 -328
  82. data/README.rdoc +0 -83
  83. data/lib/nanoc3/base/plugin.rb +0 -88
  84. data/lib/nanoc3/base/preprocessor_context.rb +0 -37
  85. data/lib/nanoc3/data_sources/filesystem_combined.rb +0 -214
  86. data/lib/nanoc3/data_sources/filesystem_common.rb +0 -22
  87. data/lib/nanoc3/data_sources/filesystem_compact.rb +0 -256
  88. data/lib/nanoc3/extra/context.rb +0 -24
  89. data/lib/nanoc3/package.rb +0 -107
  90. data/vendor/cri/ChangeLog +0 -0
  91. data/vendor/cri/LICENSE +0 -19
  92. data/vendor/cri/NEWS +0 -0
  93. data/vendor/cri/README +0 -4
  94. data/vendor/cri/Rakefile +0 -25
  95. data/vendor/cri/lib/cri/base.rb +0 -153
  96. data/vendor/cri/lib/cri/command.rb +0 -105
  97. data/vendor/cri/lib/cri/core_ext/string.rb +0 -41
  98. data/vendor/cri/lib/cri/core_ext.rb +0 -8
  99. data/vendor/cri/lib/cri/option_parser.rb +0 -186
  100. data/vendor/cri/lib/cri.rb +0 -12
  101. data/vendor/cri/test/test_base.rb +0 -6
  102. data/vendor/cri/test/test_command.rb +0 -6
  103. data/vendor/cri/test/test_core_ext.rb +0 -21
  104. data/vendor/cri/test/test_option_parser.rb +0 -279
@@ -2,42 +2,57 @@
2
2
 
3
3
  module Nanoc3
4
4
 
5
- # Nanoc3::DataSource is responsible for loading data. It is the (abstract)
6
- # superclass for all data sources. Subclasses must at least implement the
7
- # data reading methods (+items+, +layouts+, and +code_snippets+); all other
8
- # methods involving data manipulation are optional.
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 +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+.
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 +setup+ method is used for setting up a site's data source for the
16
- # first time. This method should be overridden in subclasses.
17
- class DataSource < Plugin
18
-
19
- # A string containing the root where items returned by this data source
20
- # should be mounted.
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
- # A string containing the root where layouts returned by this data source
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
- # A hash containing the configuration for this data source. For example,
28
- # online data sources could contain authentication details.
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
- # +site+:: The site this data source belongs to.
34
- # +items_root+:: The prefix that should be given to all items returned by
35
- # the #items method (comparable to mount points for
36
- # filesystems in Unix-ish OSes).
37
- # +layouts_root+:: The prefix that should be given to all layouts returned
38
- # by the #layouts method (comparable to mount points for
39
- # filesystems in Unix-ish OSes).
40
- # +config+:: The configuration for this data source.
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
- # Sets the identifiers for this data source.
51
- def self.identifiers(*identifiers)
52
- Nanoc3::DataSource.register(self, *identifiers)
53
- end
54
-
55
- # Sets the identifier for this data source.
56
- def self.identifier(identifier)
57
- Nanoc3::DataSource.register(self, identifier)
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). Similarly, when the
83
- # reference count reaches zero, the data source will be unloaded (#down
84
- # will be called).
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 increases the internal reference count. When the
93
- # data source is used for the first time (first #use call), the data
94
- # source will be loaded (#up will be called). Similarly, when the
95
- # reference count reaches zero, the data source will be unloaded (#down
96
- # will be called).
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
- ########## Loading and unloading
103
-
104
- # Brings up the connection to the data. This is an abstract method
105
- # implemented by the subclass. Depending on the way data is stored, this
106
- # may not be necessary. This is the ideal place to connect to the
107
- # database, for example.
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
- # Subclasses may implement this method.
111
+ # @return [void]
110
112
  def up
111
113
  end
112
114
 
113
- # Brings down the connection to the data. This is an abstract method
114
- # implemented by the subclass. This method should undo the effects of
115
- # +up+.
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 implement this method.
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, if
126
- # you're using a database, this is where you should create the necessary
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
- # Subclasses must implement this method.
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 implement this method.
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
- ########## Loading data
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 implement this method.
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, since
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
- # Subclasses may implement this method.
173
+ # @return [Array<Nanoc3::Layout>] A list of layouts
162
174
  def layouts
163
175
  []
164
176
  end
165
177
 
166
- # Returns the custom code snippets (represented by Nanoc3::CodeSnippet)
167
- # for this site. The default implementation simply returns an empty array.
168
- # This can be code for custom filters and more, but pretty much any code
169
- # can be put in there (global helper functions are very useful).
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
- # Subclasses may implement this method.
172
- def code_snippets
173
- []
174
- end
175
-
176
- ########## Creating data
177
-
178
- # Creates a new item with the given content, attributes and identifier.
179
- def create_item(content, attributes, identifier)
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
- def create_layout(content, attributes, identifier)
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