| Class | Webby::Resources::Resource |
| In: |
lib/webby/resources/resource.rb
|
| Parent: | Object |
Creates a new resource object given the filename.
# File lib/webby/resources/resource.rb, line 38 def initialize( fn ) @path = fn @dir = ::Webby::Resources.dirname(@path) @name = ::Webby::Resources.basename(@path) @ext = ::Webby::Resources.extname(@path) @mtime = ::File.mtime @path @_meta_data = {} self._reset end
Resource comparison operates on the full path of the resource objects and uses the standard String comparison operator. Returns nil if other is not a Resource instance.
# File lib/webby/resources/resource.rb, line 69 def <=>( other ) return unless other.kind_of? ::Webby::Resources::Resource self.destination <=> other.destination end
Returns the value associated with the given meta-data key. Key is converted into a string.
# File lib/webby/resources/resource.rb, line 80 def []( key ) _meta_data[key.to_s] end
Sets the given meta-data key to the value. Key is converted into a string.
# File lib/webby/resources/resource.rb, line 90 def []=( key, value ) _meta_data[key.to_s] = value end
Returns the path in the output directory where the resource will be generated. This path is used to determine if the resource is dirty and in need of generating.
# File lib/webby/resources/resource.rb, line 166 def destination return @destination unless @destination.nil? @destination = ::File.join(::Webby.site.output_dir, directory, filename) ext = extension unless ext.nil? or ext.empty? @destination << '.' << ext end @destination end
Returns true if this resource is newer than its corresponding output product. The resource needs to be rendered (if a page or layout) or copied (if a static file) to the output directory.
# File lib/webby/resources/resource.rb, line 113 def dirty? return _meta_data['dirty'] if _meta_data.has_key? 'dirty' # if the destination file does not exist, then we are dirty return true unless test(?e, destination) # if this file's mtime is larger than the destination file's # mtime, then we are dirty dirty = @mtime > ::File.mtime(destination) return dirty if dirty # check to see if the layout is dirty, and if it is then we # are dirty, too if _meta_data.has_key? 'layout' lyt = ::Webby::Resources.find_layout(_meta_data['layout']) unless lyt.nil? return true if lyt.dirty? end end # if we got here, then we are not dirty false end
Returns true if the path of this resource is equivalent to the path of the other resource. Returns false if this is not the case.
# File lib/webby/resources/resource.rb, line 55 def equal?( other ) return false unless other.kind_of? ::Webby::Resources::Resource (self.destination == other.destination) && (self.path == other.path) end
Invoked by Ruby when a message is sent to the resource that it cannot handle. The default behavior is to convert symbol to a string and search for that string in the resource‘s meta-data. If found, the meta-data item is returned; otherwise, nil is returned.
# File lib/webby/resources/resource.rb, line 102 def method_missing( name, *a, &b ) _meta_data[name.to_s] end