Class: Middleman::Extension
- Inherits:
-
Object
- Object
- Middleman::Extension
show all
- Defined in:
- lib/middleman-core/extension.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
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.
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/middleman-core/extension.rb', line 71
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_before_build
bind_after_build
end
|
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app.
67
68
69
|
# File 'lib/middleman-core/extension.rb', line 67
def app
@app
end
|
#options ⇒ Object
Returns the value of attribute options.
66
67
68
|
# File 'lib/middleman-core/extension.rb', line 66
def options
@options
end
|
Class Method Details
.activate ⇒ Object
43
44
45
|
# File 'lib/middleman-core/extension.rb', line 43
def activate
new(::Middleman::Application)
end
|
.activated_extension(instance) ⇒ Object
57
58
59
60
61
62
63
|
# File 'lib/middleman-core/extension.rb', line 57
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
51
52
53
54
55
|
# File 'lib/middleman-core/extension.rb', line 51
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
47
48
49
|
# File 'lib/middleman-core/extension.rb', line 47
def clear_after_extension_callbacks
@_extension_activation_callbacks = {}
end
|
.extension_name ⇒ Object
35
36
37
|
# File 'lib/middleman-core/extension.rb', line 35
def extension_name
ext_name || name.underscore.split('/').last.to_sym
end
|
.helpers(*m, &block) ⇒ Object
Add helpers to the global Middleman application. This accepts either a list of modules to add on behalf of this extension, or a block whose contents will all be used as helpers in a new module.
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/middleman-core/extension.rb', line 23
def helpers(*m, &block)
self.defined_helpers ||= []
if block_given?
mod = Module.new
mod.module_eval(&block)
m = [mod]
end
self.defined_helpers += m
end
|
.option(key, default = nil, description = nil) ⇒ Object
15
16
17
|
# File 'lib/middleman-core/extension.rb', line 15
def option(key, default=nil, description=nil)
config.define_setting(key, default, description)
end
|
.register(n = extension_name) ⇒ Object
39
40
41
|
# File 'lib/middleman-core/extension.rb', line 39
def register(n=extension_name)
::Middleman::Extensions.register(n, self)
end
|