middleman/middleman-core/lib/middleman-core/meta_pages/sitemap_resource.rb

58 lines
1.6 KiB
Ruby
Raw Normal View History

2013-06-04 18:56:33 +02:00
if !defined?(::Padrino::Helpers)
require 'vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/support_lite'
require 'vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers'
2013-06-04 18:48:01 +02:00
end
module Middleman
module MetaPages
# View class for a sitemap resource
class SitemapResource
include Padrino::Helpers::OutputHelpers
include Padrino::Helpers::TagHelpers
def initialize(resource)
@resource = resource
end
def render
content_tag :div, :class => 'resource-details' do
2013-04-14 03:01:58 +02:00
content_tag :table do
content = ""
resource_properties.each do |label, value|
2013-04-14 03:01:58 +02:00
content << content_tag(:tr) do
row_content = ""
row_content << content_tag(:th, label)
row_content << content_tag(:td, value)
row_content
end
end
content
end
end
end
# A hash of label to value for all the properties we want to display
def resource_properties
2013-04-14 03:01:58 +02:00
props = {
'Path' => @resource.path,
2013-04-14 03:01:58 +02:00
'Build Path' => @resource.destination_path,
'URL' => content_tag(:a, @resource.url, :href => @resource.url),
'Source File' => @resource.source_file,
}
2013-04-14 03:01:58 +02:00
data = @resource.data
props['Data'] = data unless data.empty?
options = @resource.metadata[:options]
props['Options'] = options unless options.empty?
props
end
def css_classes
['resource']
end
end
end
end