Class: Middleman::ConfigExtension

Inherits:
Extension
  • Object
show all
Defined in:
middleman-core/lib/middleman-core/extension.rb

Constant Summary

Constants included from Contracts

Contracts::ImmutableSetOf, Contracts::ImmutableSortedSetOf, Contracts::OldResourceList, Contracts::PATH_MATCHER, Contracts::ResourceList, Contracts::VectorOf

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

Methods included from Contracts

#Contract

Constructor Details

#initialize(app, _options_hash = ::Middleman::EMPTY_HASH, &block) ⇒ ConfigExtension



492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
# File 'middleman-core/lib/middleman-core/extension.rb', line 492

def initialize(app, _options_hash = ::Middleman::EMPTY_HASH, &block)
  @descriptors = {}
  @ready = false

  self.class.exposed_to_config.each do |k, v|
    @descriptors[k] = []

    define_singleton_method(:"__original_#{v}", &method(v))
    define_singleton_method(v) do |*args, &b|
      proxy_method_call(k, v, args, &b)
    end
  end

  super
end

Instance Method Details

#after_configurationObject



508
509
510
511
512
513
514
515
516
517
# File 'middleman-core/lib/middleman-core/extension.rb', line 508

def after_configuration
  context = self

  self.class.exposed_to_config.each do |k, v|
    ::Middleman::CoreExtensions::Collections::StepContext.add_to_context(k) do |*args, &b|
      r = context.method(:"__original_#{v}").call(*args, &b)
      descriptors << r if r.respond_to?(:execute_descriptor)
    end
  end
end

#manipulate_resource_list_container!(resource_list) ⇒ Object



529
530
531
532
533
# File 'middleman-core/lib/middleman-core/extension.rb', line 529

def manipulate_resource_list_container!(resource_list)
  @descriptors.values.flatten.each do |c|
    c.execute_descriptor(app, resource_list)
  end
end

#proxy_method_call(k, v, args, &b) ⇒ Object



536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
# File 'middleman-core/lib/middleman-core/extension.rb', line 536

def proxy_method_call(k, v, args, &b)
  if @ready
    ctx = ::Middleman::CoreExtensions::Collections::StepContext.current
    r = method(:"__original_#{v}").call(*args, &b)

    if r.respond_to?(:execute_descriptor)
      if ctx
        ctx.descriptors << r
      else
        @descriptors[k] << r
        @app.sitemap.rebuild_resource_list!(:"first_run_change_#{v}")
      end
    end
  else
    @descriptors[k] << method(:"__original_#{v}").call(*args, &b)
    @app.sitemap.rebuild_resource_list!(:"first_run_change_#{v}")
  end
end

#readyObject



519
520
521
522
523
524
525
# File 'middleman-core/lib/middleman-core/extension.rb', line 519

def ready
  @ready = true

  # @descriptors.each do |k, v|
  #   @descriptors[k] = []
  # end
end