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

66 lines
1.9 KiB
Ruby
Raw Normal View History

2014-04-04 19:22:34 +02:00
require 'padrino-helpers'
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
classes = 'resource-details'
classes << ' ignored' if @resource.ignored?
2014-04-29 19:50:21 +02:00
content_tag :div, class: classes 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 = ''
2013-04-14 03:01:58 +02:00
row_content << content_tag(:th, label)
row_content << content_tag(:td, value)
row_content.html_safe
2013-04-14 03:01:58 +02:00
end
end
content.html_safe
end
end
end
# A hash of label to value for all the properties we want to display
def resource_properties
props = {}
props['Path'] = @resource.path
build_path = @resource.destination_path
build_path = 'Not built' if ignored?
props['Build Path'] = build_path if @resource.path != build_path
2014-04-29 19:50:21 +02:00
props['URL'] = content_tag(:a, @resource.url, href: @resource.url) unless ignored?
props['Source File'] = @resource.file_descriptor ? @resource.file_descriptor[:full_path].to_s.sub(/^#{Regexp.escape(ENV['MM_ROOT'] + '/')}/, '') : 'Dynamic'
2013-04-14 03:01:58 +02:00
data = @resource.data
2016-01-11 01:47:15 +01:00
props['Data'] = data.to_hash(symbolize_keys: true).inspect unless data.empty?
2014-05-31 08:32:48 +02:00
options = @resource.options
props['Options'] = options.inspect unless options.empty?
2013-04-14 03:01:58 +02:00
2014-05-31 08:32:48 +02:00
locals = @resource.locals.keys
props['Locals'] = locals.join(', ') unless locals.empty?
2013-04-14 03:01:58 +02:00
props
end
def ignored?
@resource.ignored?
end
def css_classes
['resource'].concat(ignored? ? ['ignored'] : [])
end
end
end
end