nanoc3 3.1.9 → 3.2.0a1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. data/LICENSE +1 -1
  2. data/NEWS.md +0 -50
  3. data/README.md +3 -15
  4. data/bin/nanoc3 +2 -0
  5. data/lib/nanoc3/base/checksummer.rb +40 -0
  6. data/lib/nanoc3/base/code_snippet.rb +30 -12
  7. data/lib/nanoc3/base/compiled_content_cache.rb +86 -0
  8. data/lib/nanoc3/base/compiler.rb +134 -95
  9. data/lib/nanoc3/base/compiler_dsl.rb +12 -11
  10. data/lib/nanoc3/base/core_ext/string.rb +2 -2
  11. data/lib/nanoc3/base/data_source.rb +17 -16
  12. data/lib/nanoc3/base/dependency_tracker.rb +102 -121
  13. data/lib/nanoc3/base/directed_graph.rb +65 -3
  14. data/lib/nanoc3/base/errors.rb +20 -16
  15. data/lib/nanoc3/base/item.rb +58 -50
  16. data/lib/nanoc3/base/item_rep.rb +177 -150
  17. data/lib/nanoc3/base/layout.rb +51 -18
  18. data/lib/nanoc3/base/notification_center.rb +8 -8
  19. data/lib/nanoc3/base/plugin_registry.rb +9 -9
  20. data/lib/nanoc3/base/rule.rb +18 -9
  21. data/lib/nanoc3/base/rule_context.rb +5 -5
  22. data/lib/nanoc3/base/site.rb +135 -47
  23. data/lib/nanoc3/base.rb +21 -19
  24. data/lib/nanoc3/cli/base.rb +51 -74
  25. data/lib/nanoc3/cli/commands/autocompile.rb +3 -0
  26. data/lib/nanoc3/cli/commands/compile.rb +35 -74
  27. data/lib/nanoc3/cli/commands/create_site.rb +17 -5
  28. data/lib/nanoc3/cli/commands/debug.rb +11 -4
  29. data/lib/nanoc3/cli/commands/view.rb +0 -1
  30. data/lib/nanoc3/cli/commands/watch.rb +148 -0
  31. data/lib/nanoc3/cli/commands.rb +1 -0
  32. data/lib/nanoc3/cli/logger.rb +15 -21
  33. data/lib/nanoc3/data_sources/deprecated/twitter.rb +0 -1
  34. data/lib/nanoc3/data_sources/filesystem.rb +11 -40
  35. data/lib/nanoc3/data_sources/filesystem_unified.rb +22 -22
  36. data/lib/nanoc3/extra/auto_compiler.rb +1 -1
  37. data/lib/nanoc3/extra/chick.rb +8 -8
  38. data/lib/nanoc3/extra/deployers/rsync.rb +2 -3
  39. data/lib/nanoc3/extra/validators/links.rb +32 -51
  40. data/lib/nanoc3/extra/validators/w3c.rb +2 -2
  41. data/lib/nanoc3/extra/vcs.rb +1 -1
  42. data/lib/nanoc3/filters/colorize_syntax.rb +15 -19
  43. data/lib/nanoc3/filters/erb.rb +1 -5
  44. data/lib/nanoc3/filters/erubis.rb +1 -5
  45. data/lib/nanoc3/filters/haml.rb +1 -2
  46. data/lib/nanoc3/filters/less.rb +2 -51
  47. data/lib/nanoc3/filters/mustache.rb +21 -0
  48. data/lib/nanoc3/filters/rdiscount.rb +1 -2
  49. data/lib/nanoc3/filters/relativize_paths.rb +3 -2
  50. data/lib/nanoc3/filters/sass.rb +50 -56
  51. data/lib/nanoc3/filters.rb +2 -0
  52. data/lib/nanoc3/helpers/blogging.rb +22 -29
  53. data/lib/nanoc3/helpers/breadcrumbs.rb +1 -1
  54. data/lib/nanoc3/helpers/capturing.rb +1 -1
  55. data/lib/nanoc3/helpers/filtering.rb +1 -1
  56. data/lib/nanoc3/helpers/link_to.rb +10 -21
  57. data/lib/nanoc3/helpers/rendering.rb +5 -24
  58. data/lib/nanoc3/helpers/tagging.rb +6 -6
  59. data/lib/nanoc3/helpers/text.rb +2 -2
  60. data/lib/nanoc3.rb +1 -1
  61. metadata +35 -93
  62. data/.gemtest +0 -0
  63. data/doc/yardoc_templates/default/layout/html/footer.erb +0 -10
  64. data/nanoc3.gemspec +0 -41
  65. data/tasks/clean.rake +0 -11
  66. data/tasks/doc.rake +0 -14
  67. data/tasks/gem.rake +0 -13
  68. data/tasks/test.rake +0 -38
  69. data/test/base/core_ext/array_spec.rb +0 -23
  70. data/test/base/core_ext/hash_spec.rb +0 -41
  71. data/test/base/core_ext/string_spec.rb +0 -27
  72. data/test/base/test_code_snippet.rb +0 -33
  73. data/test/base/test_compiler.rb +0 -410
  74. data/test/base/test_compiler_dsl.rb +0 -121
  75. data/test/base/test_context.rb +0 -33
  76. data/test/base/test_data_source.rb +0 -48
  77. data/test/base/test_dependency_tracker.rb +0 -510
  78. data/test/base/test_directed_graph.rb +0 -91
  79. data/test/base/test_filter.rb +0 -85
  80. data/test/base/test_item.rb +0 -141
  81. data/test/base/test_item_rep.rb +0 -953
  82. data/test/base/test_layout.rb +0 -44
  83. data/test/base/test_notification_center.rb +0 -36
  84. data/test/base/test_plugin.rb +0 -32
  85. data/test/base/test_rule.rb +0 -21
  86. data/test/base/test_rule_context.rb +0 -63
  87. data/test/base/test_site.rb +0 -366
  88. data/test/cli/commands/test_compile.rb +0 -12
  89. data/test/cli/commands/test_create_item.rb +0 -12
  90. data/test/cli/commands/test_create_layout.rb +0 -28
  91. data/test/cli/commands/test_create_site.rb +0 -24
  92. data/test/cli/commands/test_help.rb +0 -12
  93. data/test/cli/commands/test_info.rb +0 -12
  94. data/test/cli/commands/test_update.rb +0 -12
  95. data/test/cli/test_logger.rb +0 -12
  96. data/test/data_sources/test_filesystem.rb +0 -420
  97. data/test/data_sources/test_filesystem_unified.rb +0 -538
  98. data/test/data_sources/test_filesystem_verbose.rb +0 -359
  99. data/test/extra/core_ext/test_enumerable.rb +0 -32
  100. data/test/extra/core_ext/test_time.rb +0 -17
  101. data/test/extra/deployers/test_rsync.rb +0 -234
  102. data/test/extra/test_auto_compiler.rb +0 -482
  103. data/test/extra/test_file_proxy.rb +0 -21
  104. data/test/extra/test_vcs.rb +0 -24
  105. data/test/extra/validators/test_links.rb +0 -53
  106. data/test/extra/validators/test_w3c.rb +0 -49
  107. data/test/filters/test_bluecloth.rb +0 -20
  108. data/test/filters/test_coderay.rb +0 -46
  109. data/test/filters/test_colorize_syntax.rb +0 -84
  110. data/test/filters/test_erb.rb +0 -72
  111. data/test/filters/test_erubis.rb +0 -72
  112. data/test/filters/test_haml.rb +0 -98
  113. data/test/filters/test_kramdown.rb +0 -20
  114. data/test/filters/test_less.rb +0 -118
  115. data/test/filters/test_markaby.rb +0 -26
  116. data/test/filters/test_maruku.rb +0 -20
  117. data/test/filters/test_rainpress.rb +0 -31
  118. data/test/filters/test_rdiscount.rb +0 -33
  119. data/test/filters/test_rdoc.rb +0 -18
  120. data/test/filters/test_redcloth.rb +0 -20
  121. data/test/filters/test_relativize_paths.rb +0 -231
  122. data/test/filters/test_rubypants.rb +0 -20
  123. data/test/filters/test_sass.rb +0 -235
  124. data/test/gem_loader.rb +0 -11
  125. data/test/helper.rb +0 -99
  126. data/test/helpers/test_blogging.rb +0 -808
  127. data/test/helpers/test_breadcrumbs.rb +0 -83
  128. data/test/helpers/test_capturing.rb +0 -42
  129. data/test/helpers/test_filtering.rb +0 -108
  130. data/test/helpers/test_html_escape.rb +0 -18
  131. data/test/helpers/test_link_to.rb +0 -251
  132. data/test/helpers/test_rendering.rb +0 -109
  133. data/test/helpers/test_tagging.rb +0 -89
  134. data/test/helpers/test_text.rb +0 -26
  135. data/test/helpers/test_xml_sitemap.rb +0 -69
  136. data/test/tasks/test_clean.rb +0 -71
@@ -14,7 +14,7 @@ module Nanoc3
14
14
  class UnknownDataSource < Generic
15
15
 
16
16
  # @param [String] data_source_name The data source name for which no
17
- # data source could be found
17
+ # data source could be found
18
18
  def initialize(data_source_name)
19
19
  super("The data source specified in the site’s configuration file, “#{data_source_name}”, does not exist.".make_compatible_with_env)
20
20
  end
@@ -26,7 +26,7 @@ module Nanoc3
26
26
  class UnknownLayout < Generic
27
27
 
28
28
  # @param [String] layout_identifier The layout identifier for which no
29
- # layout could be found
29
+ # layout could be found
30
30
  def initialize(layout_identifier)
31
31
  super("The site does not have a layout with identifier “#{layout_identifier}”.".make_compatible_with_env)
32
32
  end
@@ -38,7 +38,7 @@ module Nanoc3
38
38
  class UnknownFilter < Generic
39
39
 
40
40
  # @param [Symbol] filter_name The filter name for which no filter could
41
- # be found
41
+ # be found
42
42
  def initialize(filter_name)
43
43
  super("The requested filter, “#{filter_name}”, does not exist.".make_compatible_with_env)
44
44
  end
@@ -51,7 +51,7 @@ module Nanoc3
51
51
  class CannotDetermineFilter < Generic
52
52
 
53
53
  # @param [String] layout_identifier The identifier of the layout for
54
- # which the filter could not be determined
54
+ # which the filter could not be determined
55
55
  def initialize(layout_identifier)
56
56
  super("The filter to be used for the “#{layout_identifier}” layout could not be determined. Make sure the layout does have a filter.".make_compatible_with_env)
57
57
  end
@@ -63,12 +63,12 @@ module Nanoc3
63
63
  class DataNotYetAvailable < Generic
64
64
 
65
65
  # @param [String] type The name of the data type that is not yet
66
- # available. For example: `"site"`, `"items"`.
66
+ # available. For example: `"site"`, `"items"`.
67
67
  #
68
68
  # @param [Boolean] plural True if the given type is plural, false
69
- # otherwise. This only has an effect on the exception message. For
70
- # example, if the given type is `"site"`, plural would be `false`; if
71
- # the given type is `"items"`, plural would be `true`.
69
+ # otherwise. This only has an effect on the exception message. For
70
+ # example, if the given type is `"site"`, plural would be `false`; if
71
+ # the given type is `"items"`, plural would be `true`.
72
72
  def initialize(type, plural)
73
73
  super("#{type} #{plural ? 'are' : 'is'} not available yet. You may be missing a Nanoc3::Site#load_data call.".make_compatible_with_env)
74
74
  end
@@ -80,7 +80,7 @@ module Nanoc3
80
80
  class RecursiveCompilation < Generic
81
81
 
82
82
  # @param [Array<Nanoc3::ItemRep>] reps A list of item representations
83
- # that mutually depend on each other
83
+ # that mutually depend on each other
84
84
  def initialize(reps)
85
85
  super("The site cannot be compiled because the following items mutually depend on each other: #{reps.inspect}.".make_compatible_with_env)
86
86
  end
@@ -102,7 +102,7 @@ module Nanoc3
102
102
  class NoMatchingCompilationRuleFound < Generic
103
103
 
104
104
  # @param [Nanoc3::Item] item The item for which no compilation rule
105
- # could be found
105
+ # could be found
106
106
  def initialize(item)
107
107
  super("No compilation rules were found for the “#{item.identifier}” item.".make_compatible_with_env)
108
108
  end
@@ -114,7 +114,7 @@ module Nanoc3
114
114
  class NoMatchingRoutingRuleFound < Generic
115
115
 
116
116
  # @param [Nanoc3::Item] item The item for which no routing rule could be
117
- # found
117
+ # found
118
118
  def initialize(rep)
119
119
  super("No routing rules were found for the “#{rep.item.identifier}” item (rep “#{rep.name}”).".make_compatible_with_env)
120
120
  end
@@ -126,11 +126,11 @@ module Nanoc3
126
126
  class UnmetDependency < Generic
127
127
 
128
128
  # @return [Nanoc3::ItemRep] The item representation that cannot yet be
129
- # compiled
129
+ # compiled
130
130
  attr_reader :rep
131
131
 
132
132
  # @param [Nanoc3::ItemRep] The item representation that cannot yet be
133
- # compiled
133
+ # compiled
134
134
  def initialize(rep)
135
135
  @rep = rep
136
136
  super("The current item cannot be compiled yet because of an unmet dependency on the “#{rep.item.identifier}” item (rep “#{rep.name}”).".make_compatible_with_env)
@@ -142,7 +142,7 @@ module Nanoc3
142
142
  class CannotLayoutBinaryItem < Generic
143
143
 
144
144
  # @param [Nanoc3::ItemRep] The item representation that was attempted to
145
- # be laid out
145
+ # be laid out
146
146
  def initialize(rep)
147
147
  super("The “{rep.item.identifier}” item (rep “#{rep.name}”) cannot be laid out because it is a binary item. If you are getting this error for an item that should be textual instead of binary, make sure that its extension is included in the text_extensions array in the site configuration.".make_compatible_with_env)
148
148
  end
@@ -154,7 +154,7 @@ module Nanoc3
154
154
  class CannotUseTextualFilter < Generic
155
155
 
156
156
  # @param [Nanoc3::ItemRep] rep The item representation that was
157
- # attempted to be filtered
157
+ # attempted to be filtered
158
158
  #
159
159
  # @param [Class] filter_class The filter class that was used
160
160
  def initialize(rep, filter_class)
@@ -168,7 +168,7 @@ module Nanoc3
168
168
  class CannotUseBinaryFilter < Generic
169
169
 
170
170
  # @param [Nanoc3::ItemRep] rep The item representation that was
171
- # attempted to be filtered
171
+ # attempted to be filtered
172
172
  #
173
173
  # @param [Class] filter_class The filter class that was used
174
174
  def initialize(rep, filter_class)
@@ -177,6 +177,10 @@ module Nanoc3
177
177
 
178
178
  end
179
179
 
180
+ # Error that is raised when an internal consistency error is detected.
181
+ class InternalConsistency < Generic
182
+ end
183
+
180
184
  end
181
185
 
182
186
  end
@@ -13,78 +13,71 @@ module Nanoc3
13
13
  # @return [Hash] This item's attributes
14
14
  attr_accessor :attributes
15
15
 
16
- # A string that uniquely identifies an item in a site.
17
- #
18
- # Identifiers start and end with a slash. They are comparable to paths on
19
- # the filesystem, with the difference that file system paths usually do
20
- # not have a trailing slash. The item hierarchy (parent and children of
21
- # items) is determined by the item identifier.
22
- #
23
- # The root page (the home page) has the identifier “/”, which means
24
- # that it is the ancestor of all other items.
25
- #
26
16
  # @return [String] This item's identifier
27
17
  attr_accessor :identifier
28
18
 
29
- # @return [Time] The time when this item was last modified
19
+ # @return [Time] The time where this item was last modified
30
20
  attr_reader :mtime
31
21
 
22
+ # @return [String] The checksum of this item that was in effect during the
23
+ # previous site compilation
24
+ attr_accessor :old_checksum
25
+
26
+ # @return [String] The current, up-to-date checksum of this item
27
+ attr_reader :new_checksum
28
+
32
29
  # @return [Array<Nanoc3::ItemRep>] This item’s list of item reps
33
30
  attr_reader :reps
34
31
 
35
32
  # @return [String] This item's raw, uncompiled content of this item (only
36
- # available for textual items)
33
+ # available for textual items)
37
34
  attr_reader :raw_content
38
35
 
39
36
  # @return [String] The filename pointing to the file containing this
40
- # item’s content (only available for binary items)
37
+ # item’s content (only available for binary items)
41
38
  attr_reader :raw_filename
42
39
 
43
40
  # @return [Nanoc3::Item, nil] The parent item of this item. This can be
44
- # nil even for non-root items.
41
+ # nil even for non-root items.
45
42
  attr_accessor :parent
46
43
 
47
44
  # @return [Array<Nanoc3::Item>] The child items of this item
48
45
  attr_accessor :children
49
46
 
50
47
  # @return [Boolean] Whether or not this item is outdated because of its
51
- # dependencies are outdated
48
+ # dependencies are outdated
52
49
  attr_accessor :outdated_due_to_dependencies
53
50
  alias_method :outdated_due_to_dependencies?, :outdated_due_to_dependencies
54
51
 
55
52
  # Creates a new item with the given content or filename, attributes and
56
53
  # identifier.
57
54
  #
58
- # Note that the API in 3.1 has changed a bit since 3.0; the API remains
59
- # backwards compatible, however. Passing the modification time as the 4th
60
- # parameter is deprecated; pass it as the `:mtime` method option instead.
61
- #
62
55
  # @param [String] raw_content_or_raw_filename The uncompiled item content
63
- # (if it is a textual item) or the path to the filename containing the
64
- # content (if it is a binary item).
56
+ # (if it is a textual item) or the path to the filename containing the
57
+ # content (if it is a binary item).
65
58
  #
66
59
  # @param [Hash] attributes A hash containing this item's attributes.
67
60
  #
68
61
  # @param [String] identifier This item's identifier.
69
62
  #
70
- # @param [Time, Hash, nil] params_or_mtime Extra parameters for the item,
71
- # or the time when this item was last modified (deprecated).
72
- #
73
- # @option params_or_mtime [Time, nil] :mtime (nil) The time when this item
74
- # was last modified
75
- #
76
- # @option params_or_mtime [Symbol, nil] :binary (true) Whether or not this
77
- # item is binary
78
- def initialize(raw_content_or_raw_filename, attributes, identifier, params_or_mtime=nil)
79
- # Get params and mtime
80
- # TODO [in nanoc 4.0] clean this up
81
- if params_or_mtime.nil? || params_or_mtime.is_a?(Time)
82
- params = {}
83
- @mtime = params_or_mtime
84
- elsif params_or_mtime.is_a?(Hash)
85
- params = params_or_mtime
86
- @mtime = params[:mtime]
87
- end
63
+ # @param [Time, Hash] params Extra parameters. For backwards
64
+ # compatibility, this can be a Time instance indicating the time when
65
+ # this item was last modified (mtime).
66
+ #
67
+ # @option params [Time, nil] :mtime (nil) The time when this item was last
68
+ # modified
69
+ #
70
+ # @option params [Symbol, nil] :binary (true) Whether or not this item is
71
+ # binary
72
+ #
73
+ # @option params [String, nil] :checksum (nil) The current, up-to-date
74
+ # checksum of this item
75
+ def initialize(raw_content_or_raw_filename, attributes, identifier, params=nil)
76
+ # Get mtime and checksum
77
+ params ||= {}
78
+ params = { :mtime => params } if params.is_a?(Time)
79
+ @new_checksum = params[:checksum]
80
+ @mtime = params[:mtime]
88
81
 
89
82
  # Get type and raw content or raw filename
90
83
  @is_binary = params.has_key?(:binary) ? params[:binary] : false
@@ -96,7 +89,7 @@ module Nanoc3
96
89
 
97
90
  # Get rest of params
98
91
  @attributes = attributes.symbolize_keys
99
- @identifier = identifier.cleaned_identifier.freeze
92
+ @identifier = identifier.cleaned_identifier
100
93
 
101
94
  @parent = nil
102
95
  @children = []
@@ -118,17 +111,17 @@ module Nanoc3
118
111
  # content easier.
119
112
  #
120
113
  # @option params [String] :rep (:default) The name of the representation
121
- # from which the compiled content should be fetched. By default, the
122
- # compiled content will be fetched from the default representation.
114
+ # from which the compiled content should be fetched. By default, the
115
+ # compiled content will be fetched from the default representation.
123
116
  #
124
117
  # @option params [String] :snapshot The name of the snapshot from which to
125
- # fetch the compiled content. By default, the returned compiled content
126
- # will be the content compiled right before the first layout call (if
127
- # any).
118
+ # fetch the compiled content. By default, the returned compiled content
119
+ # will be the content compiled right before the first layout call (if
120
+ # any).
128
121
  #
129
122
  # @return [String] The compiled content of the given rep (or the default
130
- # rep if no rep is specified) at the given snapshot (or the default
131
- # snapshot if no snapshot is specified)
123
+ # rep if no rep is specified) at the given snapshot (or the default
124
+ # snapshot if no snapshot is specified)
132
125
  #
133
126
  # @see ItemRep#compiled_content
134
127
  def compiled_content(params={})
@@ -148,11 +141,11 @@ module Nanoc3
148
141
  # method that makes fetching the path of a rep easier.
149
142
  #
150
143
  # @option params [String] :rep (:default) The name of the representation
151
- # from which the path should be fetched. By default, the path will be
152
- # fetched from the default representation.
144
+ # from which the path should be fetched. By default, the path will be
145
+ # fetched from the default representation.
153
146
  #
154
147
  # @return [String] The path of the given rep ( or the default rep if no
155
- # rep is specified)
148
+ # rep is specified)
156
149
  def path(params={})
157
150
  rep_name = params[:rep] || :default
158
151
 
@@ -201,6 +194,21 @@ module Nanoc3
201
194
  @reps.any? { |r| r.outdated? }
202
195
  end
203
196
 
197
+ # Returns the type of this object. Will always return `:item`, because
198
+ # this is an item. For layouts, this method returns `:layout`.
199
+ #
200
+ # @return [Symbol] :item
201
+ def type
202
+ :item
203
+ end
204
+
205
+ # Returns an object that can be used for uniquely identifying objects.
206
+ #
207
+ # @return [Object] An unique reference to this object
208
+ def reference
209
+ [ type, self.identifier ]
210
+ end
211
+
204
212
  def inspect
205
213
  "<#{self.class}:0x#{self.object_id.to_s(16)} identifier=#{self.identifier} binary?=#{self.binary?}>"
206
214
  end