Class: BootstrapHamlHelpers::Component::Base
- Inherits:
-
Object
- Object
- BootstrapHamlHelpers::Component::Base
show all
- Includes:
- InheritableTraits
- Defined in:
- app/models/bootstrap_haml_helpers/component/base.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
included
Constructor Details
#initialize(*args, &block) ⇒ Base
Returns a new instance of Base.
11
12
13
14
15
16
17
|
# File 'app/models/bootstrap_haml_helpers/component/base.rb', line 11
def initialize(*args, &block)
self.component_options = args..symbolize_keys
self.attributes = component_options.delete(:html).try(:symbolize_keys) || {}
add_attribute(:class, default_css_class) if default_css_class
self.content_block = block
self.content_string = args.first
end
|
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
8
9
10
|
# File 'app/models/bootstrap_haml_helpers/component/base.rb', line 8
def attributes
@attributes
end
|
#component_options ⇒ Object
Returns the value of attribute component_options.
8
9
10
|
# File 'app/models/bootstrap_haml_helpers/component/base.rb', line 8
def component_options
@component_options
end
|
#content ⇒ Object
Returns the value of attribute content.
8
9
10
|
# File 'app/models/bootstrap_haml_helpers/component/base.rb', line 8
def content
@content
end
|
#content_block ⇒ Object
Returns the value of attribute content_block.
8
9
10
|
# File 'app/models/bootstrap_haml_helpers/component/base.rb', line 8
def content_block
@content_block
end
|
#content_string ⇒ Object
Returns the value of attribute content_string.
8
9
10
|
# File 'app/models/bootstrap_haml_helpers/component/base.rb', line 8
def content_string
@content_string
end
|
#controller ⇒ Object
Returns the value of attribute controller.
8
9
10
|
# File 'app/models/bootstrap_haml_helpers/component/base.rb', line 8
def controller
@controller
end
|
#output_buffer ⇒ Object
Returns the value of attribute output_buffer.
8
9
10
|
# File 'app/models/bootstrap_haml_helpers/component/base.rb', line 8
def output_buffer
@output_buffer
end
|
Class Method Details
.build(*args, &block) ⇒ Object
20
21
22
|
# File 'app/models/bootstrap_haml_helpers/component/base.rb', line 20
def build(*args, &block)
new(*args, &block).build
end
|
.init_context(view_context) ⇒ Object
24
25
26
27
28
|
# File 'app/models/bootstrap_haml_helpers/component/base.rb', line 24
def init_context(view_context)
self.view_context = view_context
self.view_context.extend(Haml::Helpers)
self.view_context.init_haml_helpers
end
|
.teardown_context ⇒ Object
30
31
32
|
# File 'app/models/bootstrap_haml_helpers/component/base.rb', line 30
def teardown_context
self.view_context = nil
end
|
.view_context ⇒ Object
34
35
36
|
# File 'app/models/bootstrap_haml_helpers/component/base.rb', line 34
def view_context
Thread.current[:view_context]
end
|
.view_context=(view_context) ⇒ Object
38
39
40
|
# File 'app/models/bootstrap_haml_helpers/component/base.rb', line 38
def view_context=(view_context)
Thread.current[:view_context] = view_context
end
|
Instance Method Details
#add_attribute(name, value) ⇒ Object
55
56
57
58
59
60
|
# File 'app/models/bootstrap_haml_helpers/component/base.rb', line 55
def add_attribute(name, value)
self.attributes[name] ||= ''
self.attributes[name] += " #{value}"
self.attributes[name].squish!
self
end
|
#add_attributes(attrs = {}) ⇒ Object
62
63
64
65
|
# File 'app/models/bootstrap_haml_helpers/component/base.rb', line 62
def add_attributes(attrs = {})
attrs.each { |k,v| add_attribute(k.to_sym, v) }
self
end
|
#block_or_string_content ⇒ Object
Useful when building a component with a partial that encapsulates the block/string content
73
74
75
|
# File 'app/models/bootstrap_haml_helpers/component/base.rb', line 73
def block_or_string_content
content_block ? view_context.capture(self, &content_block) : content_string
end
|
#build ⇒ Object
67
68
69
70
|
# File 'app/models/bootstrap_haml_helpers/component/base.rb', line 67
def build
resolve_content
view_context.content_tag(tag_name, content, attributes)
end
|
#content_type ⇒ Object
51
52
53
|
# File 'app/models/bootstrap_haml_helpers/component/base.rb', line 51
def content_type
:html
end
|
#view_context ⇒ Object
43
44
45
|
# File 'app/models/bootstrap_haml_helpers/component/base.rb', line 43
def view_context
self.class.view_context
end
|
#view_context=(view_context) ⇒ Object
47
48
49
|
# File 'app/models/bootstrap_haml_helpers/component/base.rb', line 47
def view_context=(view_context)
self.class.view_context = view_context
end
|