Sha256: d4777d4ccf84614603f24824846fa2ec9446783d178c4d26edda5b1767d95995

Contents?: true

Size: 1.35 KB

Versions: 1

Compression:

Stored size: 1.35 KB

Contents

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
          content_tag :table do
            content = ""
            resource_properties.each do |label, value|
              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
        props = {
          'Path' => @resource.path,
          'Build Path' => @resource.destination_path,
          'URL' => content_tag(:a, @resource.url, :href => @resource.url),
          'Template' => @resource.source_file,
        }

        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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
middleman-core-3.1.0.beta.1 lib/middleman-core/meta_pages/sitemap_resource.rb