class Middleman::Sitemap::Resource
Constants
- METADATA_HASH
Attributes
The output path in the build directory for this resource @return [String]
The source path of this resource (relative to the source directory, without template extensions) @return [String]
The output path in the build directory for this resource @return [String]
Public Class Methods
Source
# File lib/middleman-core/sitemap/resource.rb, line 48 def initialize(store, path, source=nil) @store = store @app = @store.app @path = path @ignored = false source = Pathname(source) if source && source.is_a?(String) @file_descriptor = if source && source.is_a?(Pathname) ::Middleman::SourceFile.new(source.relative_path_from(@app.source_dir), source, @app.source_dir, Set.new([:source]), 0) else source end @destination_path = @path # Options are generally rendering/sitemap options # Locals are local variables for rendering this resource's template # Page are data that is exposed through this resource's data member. # Note: It is named 'page' for backwards compatibility with older MM. @metadata = { options: {}, locals: {}, page: {} } @page_data = nil end
Public Instance Methods
Source
# File lib/middleman-core/sitemap/resource.rb, line 100 def add_metadata(meta={}, reverse=false) @page_data = nil @metadata = if reverse meta.deep_merge(@metadata) else @metadata.deep_merge(meta) end end
Source
# File lib/middleman-core/sitemap/resource.rb, line 174 def binary? !file_descriptor.nil? && (file_descriptor[:types].include?(:binary) || ::Middleman::Util.binary?(file_descriptor[:full_path].to_s)) end
Source
# File lib/middleman-core/sitemap/resource.rb, line 196 def content_type options[:content_type] || ::Rack::Mime.mime_type(ext, nil) end
Source
# File lib/middleman-core/sitemap/resource.rb, line 113 def data @page_data ||= ::Middleman::Util.recursively_enhance(metadata[:page]) end
Source
# File lib/middleman-core/sitemap/resource.rb, line 135 def ext File.extname(path) end
Source
# File lib/middleman-core/sitemap/resource.rb, line 182 def ignore! @ignored = true end
Source
# File lib/middleman-core/sitemap/resource.rb, line 189 def ignored? @ignored end
Source
# File lib/middleman-core/sitemap/resource.rb, line 128 def locals metadata[:locals] end
Source
# File lib/middleman-core/sitemap/resource.rb, line 203 def normalized_path @normalized_path ||= ::Middleman::Util.normalize_path @path end
The normalized source path of this resource (relative to the source directory, without template extensions) @return [String]
Source
# File lib/middleman-core/sitemap/resource.rb, line 121 def options metadata[:options] end
Source
# File lib/middleman-core/sitemap/resource.rb, line 89 def page_id metadata[:page][:id] || make_implicit_page_id(destination_path) end
Source
# File lib/middleman-core/sitemap/extensions/proxies.rb, line 60 def proxy_to(_path) throw 'Resource#proxy_to has been removed. Use ProxyResource class instead.' end
Source
# File lib/middleman-core/sitemap/resource.rb, line 142 def render(opts={}, locs={}) return ::Middleman::FileRenderer.new(@app, file_descriptor[:full_path].to_s).template_data_for_file unless template? md = metadata opts = md[:options].deep_merge(opts) locs = md[:locals].deep_merge(locs) locs[:current_path] ||= destination_path # Certain output file types don't use layouts opts[:layout] = false if !opts.key?(:layout) && !@app.config.extensions_with_layout.include?(ext) renderer = ::Middleman::TemplateRenderer.new(@app, file_descriptor[:full_path].to_s) renderer.render(locs, opts) end
Source
# File lib/middleman-core/sitemap/resource.rb, line 84 def source_file file_descriptor && file_descriptor[:full_path].to_s end
Source
# File lib/middleman-core/sitemap/resource.rb, line 76 def template? return false if file_descriptor.nil? !::Middleman::Util.tilt_class(file_descriptor[:full_path].to_s).nil? end
Source
# File lib/middleman-core/sitemap/resource.rb, line 207 def to_s "#<#{self.class} path=#{@path}>" end
Also aliased as: inspect
Source
# File lib/middleman-core/sitemap/resource.rb, line 161 def url url_path = destination_path if @app.config[:strip_index_file] url_path = url_path.sub(/(^|\/)#{Regexp.escape(@app.config[:index_file])}$/, @app.config[:trailing_slash] ? '/' : '') end File.join(@app.config[:http_prefix], url_path) end
Protected Instance Methods
Source
# File lib/middleman-core/sitemap/resource.rb, line 219 def make_implicit_page_id(path) @id ||= begin if prok = @app.config[:page_id_generator] return prok.call(path) end basename = if ext == '.html' File.basename(path, ext) else File.basename(path) end # Remove leading dot or slash if present File.join(File.dirname(path), basename).gsub(/^\.?\//, '') end end