class Middleman::Sitemap::Resource
Sitemap Resource class
def add_metadata(metadata={}, &block)
-
metadata
(Hash
) -- A metadata block like provides_metadata_for_path takes
def add_metadata(metadata={}, &block) metadata = metadata.dup if metadata.has_key?(:blocks) @local_metadata[:blocks] << metadata.delete(:blocks) end @local_metadata.deep_merge!(metadata) @local_metadata[:blocks] << block if block_given? end
def binary?
-
(Boolean)
-
def binary? ::Middleman::Util.binary?(source_file) end
def destination_path
-
(String)
-
def destination_path @destination_paths.last end
def destination_path=(path)
-
(void)
-
Parameters:
-
path
(String
) --
def destination_path=(path) @destination_paths << path end
def ext
-
(String)
-
def ext File.extname(path) end
def initialize(store, path, source_file=nil)
-
source_file
(String
) -- -
path
(String
) -- -
store
(Middleman::Sitemap::Store
) --
def initialize(store, path, source_file=nil) @store = store @app = @store.app @path = path @source_file = source_file @destination_paths = [@path] @local_metadata = { :options => {}, :locals => {}, :page => {}, :blocks => [] } end
def metadata
-
(Hash)
-
def metadata result = store.metadata_for_path(path).dup file_meta = store.metadata_for_file(source_file).dup if file_meta.has_key?(:blocks) result[:blocks] << file_meta.delete(:blocks) end result.deep_merge!(file_meta) local_meta = @local_metadata.dup if local_meta.has_key?(:blocks) result[:blocks] << local_meta.delete(:blocks) end result.deep_merge!(local_meta) result[:blocks] = result[:blocks].flatten.compact result end
def render(opts={}, locs={}, &block)
-
(String)
-
def render(opts={}, locs={}, &block) if !template? return app.template_data_for_file(source_file) end relative_source = Pathname(source_file).relative_path_from(Pathname(app.root)) instrument "render.resource", :path => relative_source do md = metadata.dup opts = md[:options].deep_merge(opts) # Pass "renderer_options" hash from frontmatter along to renderer if md[:page]["renderer_options"] opts[:renderer_options] = {} md[:page]["renderer_options"].each do |k, v| opts[:renderer_options][k.to_sym] = v end end locs = md[:locals].deep_merge(locs) # Forward remaining data to helpers if md.has_key?(:page) app.data.store("page", md[:page]) end blocks = Array(md[:blocks]).dup blocks << block if block_given? app.current_path ||= self.destination_path app.render_template(source_file, locs, opts, blocks) end end
def source_file
def source_file @source_file || get_source_file end
def template?
-
(Boolean)
-
def template? return false if source_file.nil? !::Tilt[source_file].nil? end
def url
-
(String)
-
def url url_path = destination_path if app.strip_index_file url_path = url_path.sub(/(^|\/)#{Regexp.escape(app.index_file)}$/, app.trailing_slash ? '/' : '') end File.join(app.respond_to?(:http_prefix) ? app.http_prefix : '/', url_path) end