Class: Middleman::Extension

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, options_hash = {}, &block) ⇒ Extension

Returns a new instance of Extension.



160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/middleman-core/extensions.rb', line 160

def initialize(klass, options_hash={}, &block)
  @_helpers = []
  @klass = klass

  setup_options(options_hash, &block)
  setup_app_reference_when_available

  # Bind app hooks to local methods
  bind_before_configuration
  bind_after_configuration
  bind_after_build
end

Instance Attribute Details

#appObject

Returns the value of attribute app.



156
157
158
# File 'lib/middleman-core/extensions.rb', line 156

def app
  @app
end

#optionsObject

Returns the value of attribute options.



155
156
157
# File 'lib/middleman-core/extensions.rb', line 155

def options
  @options
end

Class Method Details

.activateObject



132
133
134
# File 'lib/middleman-core/extensions.rb', line 132

def activate
  new(::Middleman::Application)
end

.activated_extension(instance) ⇒ Object



146
147
148
149
150
151
152
# File 'lib/middleman-core/extensions.rb', line 146

def activated_extension(instance)
  name = instance.class.extension_name
  return unless @_extension_activation_callbacks && @_extension_activation_callbacks[name]
  @_extension_activation_callbacks[name].each do |block|
    block.arity == 1 ? block.call(instance) : block.call()
  end
end

.after_extension_activated(name, &block) ⇒ Object



140
141
142
143
144
# File 'lib/middleman-core/extensions.rb', line 140

def after_extension_activated(name, &block)
  @_extension_activation_callbacks ||= {}
  @_extension_activation_callbacks[name] ||= []
  @_extension_activation_callbacks[name] << block if block_given?
end

.clear_after_extension_callbacksObject



136
137
138
# File 'lib/middleman-core/extensions.rb', line 136

def clear_after_extension_callbacks
  @_extension_activation_callbacks = {}
end

.configObject



108
109
110
# File 'lib/middleman-core/extensions.rb', line 108

def config
  @_config ||= ::Middleman::Configuration::ConfigurationManager.new
end

.extension_nameObject



124
125
126
# File 'lib/middleman-core/extensions.rb', line 124

def extension_name
  self.ext_name || self.name.underscore.split("/").last.to_sym
end

.helpers(&block) ⇒ Object



116
117
118
119
120
121
122
# File 'lib/middleman-core/extensions.rb', line 116

def helpers(&block)
  self.defined_helpers ||= []

  m = Module.new
  m.module_eval(&block)
  self.defined_helpers << m
end

.option(key, default = nil, description = nil) ⇒ Object



112
113
114
# File 'lib/middleman-core/extensions.rb', line 112

def option(key, default=nil, description=nil)
  config.define_setting(key, default, description)
end

.register(n = self.extension_name) ⇒ Object



128
129
130
# File 'lib/middleman-core/extensions.rb', line 128

def register(n=self.extension_name)
  ::Middleman::Extensions.register(n, self)
end