lib/nanoc3/base/source_data/item.rb in nanoc3-3.2.0a2 vs lib/nanoc3/base/source_data/item.rb in nanoc3-3.2.0a3
- old
+ new
@@ -21,13 +21,10 @@
# that it is the ancestor of all other items.
#
# @return [String] This item's identifier
attr_accessor :identifier
- # @return [Time] The time where this item was last modified
- attr_reader :mtime
-
# @return [Array<Nanoc3::ItemRep>] This item’s list of item reps
attr_reader :reps
# @return [String] This item's raw, uncompiled content of this item (only
# available for textual items)
@@ -58,23 +55,21 @@
# @param [Time, Hash] params Extra parameters. For backwards
# compatibility, this can be a Time instance indicating the time when
# this item was last modified (mtime).
#
# @option params [Time, nil] :mtime (nil) The time when this item was last
- # modified
+ # modified. Deprecated; pass the modification time as the `:mtime`
+ # attribute instead.
#
# @option params [Symbol, nil] :binary (true) Whether or not this item is
# binary
def initialize(raw_content_or_raw_filename, attributes, identifier, params=nil)
# Parse params
params ||= {}
params = { :mtime => params } if params.is_a?(Time)
params[:binary] = false unless params.has_key?(:binary)
- # Get mtime
- @mtime = params[:mtime]
-
# Get type and raw content or raw filename
@is_binary = params[:binary]
if @is_binary
@raw_filename = raw_content_or_raw_filename
else
@@ -83,10 +78,13 @@
# Get rest of params
@attributes = attributes.symbolize_keys
@identifier = identifier.cleaned_identifier
+ # Set mtime
+ @attributes.merge(:mtime => params[:mtime]) if params[:mtime]
+
@parent = nil
@children = []
@reps = []
end
@@ -161,10 +159,23 @@
# @return [Object] The value of the requested attribute
def [](key)
Nanoc3::NotificationCenter.post(:visit_started, self)
Nanoc3::NotificationCenter.post(:visit_ended, self)
+ # Get captured content (hax)
+ # TODO [in nanoc 4.0] remove me
+ if key.to_s =~ /^content_for_(.*)$/
+ # Include capturing helper if necessary
+ unless @_Nanoc3_Helpers_Capturing_included
+ self.class.send(:include, ::Nanoc3::Helpers::Capturing)
+ @_Nanoc3_Helpers_Capturing_included = true
+ end
+
+ # Get content
+ return content_for(self, $1.to_sym)
+ end
+
@attributes[key]
end
# Sets the attribute with the given key to the given value.
#
@@ -197,11 +208,22 @@
# @return [Object] An unique reference to this object
def reference
[ type, self.identifier ]
end
+ # Prevents all further modifications to itself, its items, its layouts etc.
+ #
+ # @return [void]
+ def freeze
+ attributes.freeze
+ end
def inspect
"<#{self.class}:0x#{self.object_id.to_s(16)} identifier=#{self.identifier} binary?=#{self.binary?}>"
+ end
+
+ # @deprecated Access the modification time using `item[:mtime]` instead.
+ def mtime
+ self[:mtime]
end
end
end