Class: Middleman::CoreExtensions::InlineURLRewriter

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

Defined Under Namespace

Classes: Rack

Constant Summary

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

Constants included from Contracts

Contracts::PATH_MATCHER, Contracts::ResourceList, Contracts::VectorOf

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



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

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

  @rewriters = {}
end

Instance Method Details

#add(options) ⇒ Object



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

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

#after_configurationObject



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

def after_configuration
  return if @rewriters.empty?

  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