Class: Middleman::CoreExtensions::InlineURLRewriter

Inherits:
Extension
  • Object
show all
Includes:
Contracts
Defined in:
lib/middleman-core/core_extensions/inline_url_rewriter.rb

Defined Under Namespace

Classes: Rack

Constant Summary collapse

IGNORE_DESCRIPTOR =
Or[Regexp, RespondTo[:call], String]
REWRITER_DESCRIPTOR =
{
  id: Symbol,
  proc: Or[Proc, Method],
  url_extensions: ArrayOf[String],
  source_extensions: ArrayOf[String],
  ignore: ArrayOf[IGNORE_DESCRIPTOR],
  after: Maybe[Symbol]
}.freeze

Constants included from Contracts

Contracts::PATH_MATCHER

Instance Attribute Summary

Attributes inherited from Extension

#app, #options

Instance Method Summary collapse

Methods included from Contracts

#Contract

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, define_setting, expose_to_application, expose_to_config, expose_to_template, global_config, helpers, #manipulate_resource_list, option, #ready, resources

Constructor Details

#initialize(app, options_hash = {}, &block) ⇒ InlineURLRewriter

Returns a new instance of InlineURLRewriter.



24
25
26
27
28
# File 'lib/middleman-core/core_extensions/inline_url_rewriter.rb', line 24

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

  @rewriters = {}
end

Instance Method Details

#add(options) ⇒ Object



31
32
33
# File 'lib/middleman-core/core_extensions/inline_url_rewriter.rb', line 31

def add(options)
  @rewriters[options] = options
end

#after_configurationObject



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/middleman-core/core_extensions/inline_url_rewriter.rb', line 35

def after_configuration
  rewriters = @rewriters.values.sort do |a, b|
    if b[:after] && b[:after] == a[:id]
      1
    else
      0
    end
  end

  app.use Rack, rewriters: rewriters, middleman_app: @app
end