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

Returns a new instance of SitemapResource



10
11
12
# File 'lib/middleman-core/meta_pages/sitemap_resource.rb', line 10

def initialize(resource)
  @resource = resource
end

Instance Method Details

#css_classesObject



60
61
62
# File 'lib/middleman-core/meta_pages/sitemap_resource.rb', line 60

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

#ignored?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/middleman-core/meta_pages/sitemap_resource.rb', line 56

def ignored?
  @resource.ignored?
end

#renderObject



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

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



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

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