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.



95
96
97
98
# File 'lib/middleman-core/sitemap/extensions/request_endpoints.rb', line 95

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



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/middleman-core/sitemap/extensions/request_endpoints.rb', line 105

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



123
124
125
126
127
128
129
130
131
132
133
# File 'lib/middleman-core/sitemap/extensions/request_endpoints.rb', line 123

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