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.
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/middleman-core/extension.rb', line 72
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.
68
69
70
|
# File 'lib/middleman-core/extension.rb', line 68
def app
@app
end
|
#options ⇒ Object
Returns the value of attribute options.
67
68
69
|
# File 'lib/middleman-core/extension.rb', line 67
def options
@options
end
|
Class Method Details
.activate ⇒ Object
44
45
46
|
# File 'lib/middleman-core/extension.rb', line 44
def activate
new(::Middleman::Application)
end
|
.activated_extension(instance) ⇒ Object
58
59
60
61
62
63
64
|
# File 'lib/middleman-core/extension.rb', line 58
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
52
53
54
55
56
|
# File 'lib/middleman-core/extension.rb', line 52
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
48
49
50
|
# File 'lib/middleman-core/extension.rb', line 48
def clear_after_extension_callbacks
@_extension_activation_callbacks = {}
end
|
.extension_name ⇒ Object
36
37
38
|
# File 'lib/middleman-core/extension.rb', line 36
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.
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/middleman-core/extension.rb', line 24
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
16
17
18
|
# File 'lib/middleman-core/extension.rb', line 16
def option(key, default=nil, description=nil)
config.define_setting(key, default, description)
end
|
.register(n = extension_name) ⇒ Object
40
41
42
|
# File 'lib/middleman-core/extension.rb', line 40
def register(n=extension_name)
::Middleman::Extensions.register(n, self)
end
|