Sha256: 852c9ec4e1238d1063084f5a373a8749338ee14874b1e2094e57f4818ad39750

Contents?: true

Size: 1.93 KB

Versions: 25

Compression:

Stored size: 1.93 KB

Contents

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?
        content_tag :div, class: classes 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.html_safe
              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
        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'

        data = @resource.data
        props['Data'] = data.to_hash(symbolize_keys: true).inspect unless data.empty?

        options = @resource.options
        props['Options'] = options.inspect unless options.empty?

        locals = @resource.locals.keys
        props['Locals'] = locals.join(', ') unless locals.empty?

        props
      end

      def ignored?
        @resource.ignored?
      end

      def css_classes
        ['resource'].concat(ignored? ? ['ignored'] : [])
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 2 rubygems

Version Path
middleman-core-5.0.0.rc.1 lib/middleman-core/meta_pages/sitemap_resource.rb
middleman-core-4.3.0.rc.4 lib/middleman-core/meta_pages/sitemap_resource.rb
middleman-core-4.3.0.rc.3 lib/middleman-core/meta_pages/sitemap_resource.rb
middleman-core-4.3.0.rc.2 lib/middleman-core/meta_pages/sitemap_resource.rb
middleman-core-with-external-sources-watch-fix-4.1.10 lib/middleman-core/meta_pages/sitemap_resource.rb
middleman-core-with-external-sources-watch-fix-4.1.0 lib/middleman-core/meta_pages/sitemap_resource.rb
middleman-core-4.3.0.rc.1 lib/middleman-core/meta_pages/sitemap_resource.rb
middleman-core-4.2.1 lib/middleman-core/meta_pages/sitemap_resource.rb
middleman-core-4.2.0 lib/middleman-core/meta_pages/sitemap_resource.rb
middleman-core-4.1.14 lib/middleman-core/meta_pages/sitemap_resource.rb
middleman-core-4.1.13 lib/middleman-core/meta_pages/sitemap_resource.rb
middleman-core-4.1.12 lib/middleman-core/meta_pages/sitemap_resource.rb
middleman-core-4.1.11 lib/middleman-core/meta_pages/sitemap_resource.rb
middleman-core-4.1.10 lib/middleman-core/meta_pages/sitemap_resource.rb
middleman-core-4.1.9 lib/middleman-core/meta_pages/sitemap_resource.rb
middleman-core-4.1.8 lib/middleman-core/meta_pages/sitemap_resource.rb
middleman-core-4.1.7 lib/middleman-core/meta_pages/sitemap_resource.rb
middleman-core-4.1.6 lib/middleman-core/meta_pages/sitemap_resource.rb
middleman-core-4.1.5 lib/middleman-core/meta_pages/sitemap_resource.rb
middleman-core-4.1.3 lib/middleman-core/meta_pages/sitemap_resource.rb