Class: Middleman::Extension
- Inherits:
-
Object
- Object
- Middleman::Extension
show all
- Defined in:
- lib/middleman-core/extensions.rb
Direct Known Subclasses
CoreExtensions::Compass, CoreExtensions::DefaultHelpers, CoreExtensions::FrontMatter, CoreExtensions::Internationalization, Middleman::Extensions::AssetHash, Middleman::Extensions::AssetHost, Middleman::Extensions::AutomaticAltTags, Middleman::Extensions::AutomaticImageSizes, Middleman::Extensions::CacheBuster, Middleman::Extensions::DirectoryIndexes, Middleman::Extensions::Gzip, Middleman::Extensions::Lorem, Middleman::Extensions::MinifyCss, Middleman::Extensions::MinifyJavascript, Middleman::Extensions::RelativeAssets, MyExtension
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_before_configuration
bind_after_configuration
bind_after_build
end
|
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app.
156
157
158
|
# File 'lib/middleman-core/extensions.rb', line 156
def app
@app
end
|
#options ⇒ Object
Returns the value of attribute options.
155
156
157
|
# File 'lib/middleman-core/extensions.rb', line 155
def options
@options
end
|
Class Method Details
.activate ⇒ Object
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_callbacks ⇒ Object
136
137
138
|
# File 'lib/middleman-core/extensions.rb', line 136
def clear_after_extension_callbacks
@_extension_activation_callbacks = {}
end
|
.extension_name ⇒ Object
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
|