Class: Middleman::Sitemap::Extensions::Proxies::ProxyManager

Inherits:
Object
  • Object
show all
Defined in:
lib/middleman-core/sitemap/extensions/proxies.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) ⇒ ProxyManager

Returns a new instance of ProxyManager.



89
90
91
92
# File 'lib/middleman-core/sitemap/extensions/proxies.rb', line 89

def initialize(app)
  @app = app
  @proxy_configs = Set.new
end

Instance Method Details

#manipulate_resource_list(resources)

This method returns an undefined value.

Update the main sitemap resource list



115
116
117
118
119
120
121
122
123
124
125
# File 'lib/middleman-core/sitemap/extensions/proxies.rb', line 115

def manipulate_resource_list(resources)
  resources + @proxy_configs.map do |config|
    p = ::Middleman::Sitemap::Resource.new(
      @app.sitemap,
      config.path
    )
    p.proxy_to(config.target)
    p.(config.)
    p
  end
end

#proxy(path, target, opts = {}, &block)

This method returns an undefined value.

Setup a proxy from a path to a target

Parameters:

  • path (String)
  • target (String)
  • opts (Hash) (defaults to: {})

    options to apply to the proxy, including things like :locals, :ignore to hide the proxy target, :layout, and :directory_indexes.



100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/middleman-core/sitemap/extensions/proxies.rb', line 100

def proxy(path, target, opts={}, &block)
   = { options: {}, locals: {}, blocks: [] }
  [:blocks] << block if block_given?
  [:locals] = opts.delete(:locals) || {}

  @app.ignore(target) if opts.delete(:ignore)
  [:options] = opts

  @proxy_configs << ProxyConfiguration.new(path: path, target: target, metadata: )

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