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

Inherits:
Extension
  • 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

Constant Summary

Constants included from Contracts

Contracts::PATH_MATCHER

Instance Attribute Summary

Attributes inherited from Extension

#app, #options

Instance Method Summary collapse

Methods inherited from Extension

activated_extension, #add_exposed_to_context, #after_build, after_extension_activated, #after_extension_activated, #before_build, #before_configuration, clear_after_extension_callbacks, config, expose_to_application, expose_to_config, expose_to_template, helpers, option, #ready, resources

Methods included from Contracts

#Contract

Constructor Details

#initialize(app, config = {}, &block) ⇒ Proxies

Returns a new instance of Proxies.



18
19
20
21
22
23
# File 'lib/middleman-core/sitemap/extensions/proxies.rb', line 18

def initialize(app, config={}, &block)
  super

  @proxy_configs = Set.new
  @post_config = false
end

Instance Method Details

#after_configurationObject



25
26
27
28
29
# File 'lib/middleman-core/sitemap/extensions/proxies.rb', line 25

def after_configuration
  @post_config = true

  ::Middleman::CoreExtensions::Collections::StepContext.add_to_context(:proxy, &method(:create_anonymous_proxy))
end

#create_anonymous_proxy(path, target, options = {})

This method returns an undefined value.

Setup a proxy from a path to a target

Parameters:

  • path (String)

    The new, proxied path to create

  • target (String)

    The existing path that should be proxied to. This must be a real resource, not another proxy.

  • opts (Hash)

    a customizable set of options



58
59
60
61
62
63
64
# File 'lib/middleman-core/sitemap/extensions/proxies.rb', line 58

def create_anonymous_proxy(path, target, options={})
  ProxyDescriptor.new(
    ::Middleman::Util.normalize_path(path),
    ::Middleman::Util.normalize_path(target),
    options
  )
end

#create_proxy(path, target, opts = {}) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/middleman-core/sitemap/extensions/proxies.rb', line 41

def create_proxy(path, target, opts={})
  options = opts.dup
  @app.ignore(target) if options.delete(:ignore)

  @proxy_configs << create_anonymous_proxy(path, target, options)
  @app.sitemap.rebuild_resource_list!(:added_proxy)
end

#manipulate_resource_list(resources) ⇒ Object



69
70
71
# File 'lib/middleman-core/sitemap/extensions/proxies.rb', line 69

def manipulate_resource_list(resources)
  resources + @proxy_configs.map { |c| c.to_resource(@app) }
end

#String

This method returns an undefined value.

Setup a proxy from a path to a target

Parameters:

  • path (String)

    The new, proxied path to create

  • target (String)

    The existing path that should be proxied to. This must be a real resource, not another proxy.



40
# File 'lib/middleman-core/sitemap/extensions/proxies.rb', line 40

Contract String, String, Maybe[Hash] => Any