lib/nanoc3/base/source_data/layout.rb in nanoc3-3.2.0a3 vs lib/nanoc3/base/source_data/layout.rb in nanoc3-3.2.0a4
- old
+ new
@@ -4,10 +4,12 @@
# Represents a layout in a nanoc site. It has content, attributes, an
# identifier and a modification time (to speed up compilation).
class Layout
+ extend Nanoc3::Memoization
+
# @return [String] The raw content of this layout
attr_reader :raw_content
# @return [Hash] This layout's attributes
attr_reader :attributes
@@ -32,11 +34,11 @@
# last modified. Deprecated; pass the modification time as the `:mtime`
# attribute instead.
def initialize(raw_content, attributes, identifier, params=nil)
@raw_content = raw_content
@attributes = attributes.symbolize_keys
- @identifier = identifier.cleaned_identifier
+ @identifier = identifier.cleaned_identifier.freeze
# Set mtime
params ||= {}
params = { :mtime => params } if params.is_a?(Time)
@attributes.merge(:mtime => params[:mtime]) if params[:mtime]
@@ -59,10 +61,19 @@
# @return [Symbol] :layout
def type
:layout
end
+ # Prevents all further modifications to the layout.
+ #
+ # @return [void]
+ def freeze
+ attributes.freeze_recursively
+ identifier.freeze
+ raw_content.freeze
+ end
+
# Returns an object that can be used for uniquely identifying objects.
#
# @api private
#
# @return [Object] An unique reference to this object
@@ -71,9 +82,17 @@
end
def inspect
"<#{self.class}:0x#{self.object_id.to_s(16)} identifier=#{self.identifier}>"
end
+
+ # TODO document
+ def checksum
+ attributes = @attributes.dup
+ attributes.delete(:file)
+ @raw_content.checksum + ',' + attributes.checksum
+ end
+ memoize :checksum
# @deprecated Access the modification time using `layout[:mtime]` instead.
def mtime
self[:mtime]
end