Class: Middleman::Sitemap::Extensions::RequestEndpoints::EndpointManager

Inherits:
Object
  • Object
show all
Defined in:
lib/middleman-core/sitemap/extensions/request_endpoints.rb

Overview

Manages the list of proxy configurations and manipulates the sitemap to include new resources based on those configurations

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ EndpointManager

Returns a new instance of EndpointManager.



34
35
36
37
# File 'lib/middleman-core/sitemap/extensions/request_endpoints.rb', line 34

def initialize(app)
  @app = app
  @endpoints = {}
end

Instance Method Details

#create_endpoint(path, opts = {}, &block) ⇒ void

This method returns an undefined value.

Setup a proxy from a path to a target differs from the output path

Parameters:

  • path (String)
  • The (Hash)

    :path value gives a request path if it



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/middleman-core/sitemap/extensions/request_endpoints.rb', line 44

def create_endpoint(path, opts={}, &block)
  endpoint = {
    :request_path => path
  }

  if block_given?
    endpoint[:output] = block
  else
    endpoint[:request_path] = opts[:path] if opts.has_key?(:path)
  end

  @endpoints[path] = endpoint

  @app.sitemap.rebuild_resource_list!(:added_endpoint)
end

#manipulate_resource_list(resources) ⇒ void

This method returns an undefined value.

Update the main sitemap resource list



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/middleman-core/sitemap/extensions/request_endpoints.rb', line 62

def manipulate_resource_list(resources)
  resources + @endpoints.map do |path, config|
    r = EndpointResource.new(
      @app.sitemap,
      path,
      config[:request_path]
    )
    r.output = config[:output] if config.has_key?(:output)
    r
  end
end