Class: Maglove::Engine::Scope
- Inherits:
-
Object
- Object
- Maglove::Engine::Scope
show all
- Defined in:
- lib/maglove/engine/scope.rb
Instance Method Summary
collapse
-
#asset(url) ⇒ Object
-
#asset_uri ⇒ Object
-
#block(identifier, variables = {}) ⇒ Object
-
#drop_container ⇒ Object
-
#font(font_face, &block) ⇒ Object
-
#initialize(variables = {}) ⇒ Scope
constructor
-
#link(href, target: nil, &block) ⇒ Object
-
#method_missing(name, *args, &block) ⇒ Object
-
#respond_to_missing?(name, include_private = false) ⇒ Boolean
-
#root_asset(url) ⇒ Object
-
#style(*args, &block) ⇒ Object
-
#style_string(options, *args, &block) ⇒ Object
-
#theme ⇒ Object
-
#var(key, default = nil) ⇒ Object
-
#variable(key, default = nil) ⇒ Object
-
#widget(identifier, options = {}, &block) ⇒ Object
Constructor Details
#initialize(variables = {}) ⇒ Scope
Returns a new instance of Scope.
4
5
6
|
# File 'lib/maglove/engine/scope.rb', line 4
def initialize(variables = {})
@variables = variables
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/maglove/engine/scope.rb', line 50
def method_missing(name, *args, &block)
if name.to_s.end_with?("_widget") and args.length <= 1
identifier = "legacy_#{name[0..-8]}".to_sym
widget(identifier, args.first || {}, &block)
elsif args.length == 0 and @variables.key?(name.to_sym)
@variables[name.to_sym]
else
super
end
end
|
Instance Method Details
#asset(url) ⇒ Object
16
17
18
|
# File 'lib/maglove/engine/scope.rb', line 16
def asset(url)
"#{asset_uri}/themes/#{theme}/#{url}"
end
|
#asset_uri ⇒ Object
12
13
14
|
# File 'lib/maglove/engine/scope.rb', line 12
def asset_uri
var(:asset_uri, Maglove::Engine.config.asset_uri)
end
|
#block(identifier, variables = {}) ⇒ Object
32
33
34
35
36
|
# File 'lib/maglove/engine/scope.rb', line 32
def block(identifier, variables = {})
variables = @variables.merge(variables)
haml = Maglove::Engine.config.block_resolver.call(identifier, variables)
Maglove::Engine.render(haml, variables)
end
|
#drop_container ⇒ Object
65
66
67
|
# File 'lib/maglove/engine/scope.rb', line 65
def drop_container
haml_tag :div, class: '_typeloft_widget_drop_container'
end
|
#font(font_face, &block) ⇒ Object
87
88
89
90
91
|
# File 'lib/maglove/engine/scope.rb', line 87
def font(font_face, &block)
haml_tag :font, face: font_face do
yield if block_given?
end
end
|
#link(href, target: nil, &block) ⇒ Object
81
82
83
84
85
|
# File 'lib/maglove/engine/scope.rb', line 81
def link(href, target: nil, &block)
haml_tag :a, href: href, target: target do
yield if block_given?
end
end
|
#respond_to_missing?(name, include_private = false) ⇒ Boolean
61
62
63
|
# File 'lib/maglove/engine/scope.rb', line 61
def respond_to_missing?(name, include_private = false)
name.to_s.end_with?("_widget") || super
end
|
#root_asset(url) ⇒ Object
20
21
22
|
# File 'lib/maglove/engine/scope.rb', line 20
def root_asset(url)
"#{asset_uri}/#{url}"
end
|
#style(*args, &block) ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/maglove/engine/scope.rb', line 69
def style(*args, &block)
style = nil
if args[-1].class.name == 'Hash'
style_options = args.pop
style = style_string(style_options, *style_options.keys)
end
classes = args.map { |a| "__#{a}" }
haml_tag :span, class: classes.join(' '), style: style do
yield if block_given?
end
end
|
#style_string(options, *args, &block) ⇒ Object
46
47
48
|
# File 'lib/maglove/engine/scope.rb', line 46
def style_string(options, *args, &block)
StyleBuilder.new(options, args).process(&block)
end
|
#theme ⇒ Object
8
9
10
|
# File 'lib/maglove/engine/scope.rb', line 8
def theme
@variables[:theme]
end
|
#var(key, default = nil) ⇒ Object
38
39
40
|
# File 'lib/maglove/engine/scope.rb', line 38
def var(key, default = nil)
@variables[key.to_sym] || default
end
|
#variable(key, default = nil) ⇒ Object
42
43
44
|
# File 'lib/maglove/engine/scope.rb', line 42
def variable(key, default = nil)
var(key, default)
end
|
24
25
26
27
28
29
30
|
# File 'lib/maglove/engine/scope.rb', line 24
def widget(identifier, options = {}, &block)
unless Maglove::Engine::Registry.instance.widgets.keys.include?(identifier.to_sym)
raise "Widget not found: #{identifier}"
end
widget = Maglove::Engine.widget(identifier, options, self)
widget.render(&block)
end
|