Class: Middleman::MetaPages::SitemapResource

Inherits:
Object
  • Object
show all
Includes:
Padrino::Helpers::OutputHelpers, Padrino::Helpers::TagHelpers
Defined in:
lib/middleman-core/meta_pages/sitemap_resource.rb

Overview

View class for a sitemap resource

Instance Method Summary collapse

Constructor Details

#initialize(resource) ⇒ SitemapResource


12
13
14
# File 'lib/middleman-core/meta_pages/sitemap_resource.rb', line 12

def initialize(resource)
  @resource = resource
end

Instance Method Details

#css_classesObject


62
63
64
# File 'lib/middleman-core/meta_pages/sitemap_resource.rb', line 62

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

#ignored?Boolean


58
59
60
# File 'lib/middleman-core/meta_pages/sitemap_resource.rb', line 58

def ignored?
  @resource.ignored?
end

#renderObject


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/middleman-core/meta_pages/sitemap_resource.rb', line 16

def render
  classes = 'resource-details'
  classes << ' ignored' if @resource.ignored?
   :div, class: classes do
     :table do
      content = ''
      resource_properties.each do |label, value|
        content << (:tr) do
          row_content = ''
          row_content << (:th, label)
          row_content << (:td, value)
          row_content.html_safe
        end
      end
      content.html_safe
    end
  end
end

#resource_propertiesObject

A hash of label to value for all the properties we want to display


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/middleman-core/meta_pages/sitemap_resource.rb', line 36

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'] = (: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