Class: Middleman::Sitemap::AppResource

Inherits:
Resource
  • Object
show all
Defined in:
lib/middleman/sitemap/app_resource.rb

Overview

Base app resource that inherits from Sitemap Resource.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_by_klass(klass, app) ⇒ Object



6
7
8
9
10
# File 'lib/middleman/sitemap/app_resource.rb', line 6

def self.find_by_klass(klass, app)
  app.sitemap.resources.detect do |res|
    res.is_a?(self) && res.locals[:klass].name == klass.name
  end
end

.find_by_path(path, app) ⇒ Object



12
13
14
15
16
# File 'lib/middleman/sitemap/app_resource.rb', line 12

def self.find_by_path(path, app)
  app.sitemap.resources.detect do |res|
    res.is_a?(self) && res.source_file.to_s == path.to_s
  end
end

Instance Method Details

#descriptionObject



30
31
32
33
# File 'lib/middleman/sitemap/app_resource.rb', line 30

def description
  str = locals[:description].to_s
  locals[:description] = str.gsub(/^#{str.scan(/^[ \t]+(?=\S)/).min}/, '')
end

#html_descriptionObject



43
44
45
46
47
# File 'lib/middleman/sitemap/app_resource.rb', line 43

def html_description
  return locals[:html_description] if locals[:html_description]
  html = Tilt['markdown'].new { description }.render(self)
  locals[:html_description] = html
end

#klassClass

Get class for this child app.

Returns:

  • (Class)

    class for the child app



22
23
24
# File 'lib/middleman/sitemap/app_resource.rb', line 22

def klass
  locals[:klass]
end

#render(opts = {}, locs = {}) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'lib/middleman/sitemap/app_resource.rb', line 49

def render(opts = {}, locs = {})
  md   = 
  locs = md[:locals].deep_merge(locs)
  opts = md[:options].deep_merge(opts)
  locs[:current_path] ||= destination_path

  layout  = "layouts/#{opts.delete(:layout)}"
  context = @app.template_context_class.new(@app, locs, opts)
  context.render :middleman, layout, opts.merge(locals: locs)
end

#routesObject



39
40
41
# File 'lib/middleman/sitemap/app_resource.rb', line 39

def routes
  locals[:routes] || []
end

#titleObject



26
27
28
# File 'lib/middleman/sitemap/app_resource.rb', line 26

def title
  locals[:title] || path.to_s.titleize
end

#update_locals(key, val) ⇒ Object



35
36
37
# File 'lib/middleman/sitemap/app_resource.rb', line 35

def update_locals(key, val)
  locals[key.to_sym] = val
end