Class: Middleman::Api::Sitemap

Inherits:
Object
  • Object
show all
Defined in:
lib/middleman-api/sitemap.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Sitemap

Returns a new instance of Sitemap.


5
6
7
# File 'lib/middleman-api/sitemap.rb', line 5

def initialize(app)
  @app = app
end

Instance Method Details

#manipulate_resource_list(resources) ⇒ void

This method returns an undefined value.

Update the main sitemap resource list


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/middleman-api/sitemap.rb', line 11

def manipulate_resource_list(resources)
  proxies = []
  resources.each do |resource|
    ext = resource.ext.gsub('.','').to_sym
    if resource.template? && !resource.ignored? && !(@app.api_formats.include?(ext))
      @app.api_formats.each do |format|
        path = "#{resource.destination_path.split('.').first}.#{format}"
        proxy = ::Middleman::Sitemap::Resource.new(@app.sitemap, path)
        proxy.proxy_to "api.#{format}"
        proxy. locals: template_data(resource, format)
        proxy. options: { layout: false }
        proxies << proxy
      end
    end
  end
  proxies + resources
end

#template_data(resource, format) ⇒ Hash

Resource data hash

Returns:

  • (Hash)

    resource data to be parsed into json


31
32
33
34
35
36
37
# File 'lib/middleman-api/sitemap.rb', line 31

def template_data(resource, format)
  data = {}
  data[:meta] = resource.data
  data[:path] = resource.url
  data[:content] = resource.render
  { data: data.send("to_#{format}") }
end