Class: Rbexy::Component
- Inherits:
-
ActionView::Base
- Object
- ActionView::Base
- Rbexy::Component
show all
- Defined in:
- lib/rbexy/component.rb,
lib/rbexy/component/backtrace_cleaner.rb
Defined Under Namespace
Classes: BacktraceCleaner, TemplatePath
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(view_context, **props) ⇒ Component
Returns a new instance of Component.
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/rbexy/component.rb', line 22
def initialize(view_context, **props)
super(
view_context.lookup_context,
view_context.assigns,
view_context.controller
)
@view_context = view_context
setup(**props)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
65
66
67
68
69
70
71
|
# File 'lib/rbexy/component.rb', line 65
def method_missing(meth, *args, &block)
if view_context.respond_to?(meth)
view_context.send(meth, *args, &block)
else
super
end
end
|
Class Method Details
.component_name ⇒ Object
14
15
16
|
# File 'lib/rbexy/component.rb', line 14
def self.component_name
name.underscore
end
|
Instance Method Details
#call ⇒ Object
44
45
46
47
48
49
50
51
|
# File 'lib/rbexy/component.rb', line 44
def call
path = TemplatePath.new(component_name)
template = view_context.lookup_context.find(path)
template.render(self, {})
rescue ActionView::Template::Error => error
error.set_backtrace clean_template_backtrace(error.backtrace)
raise error
end
|
#compiled_method_container ⇒ Object
57
58
59
|
# File 'lib/rbexy/component.rb', line 57
def compiled_method_container
Rbexy::Component
end
|
#component_name ⇒ Object
18
19
20
|
# File 'lib/rbexy/component.rb', line 18
def component_name
self.class.component_name
end
|
#content ⇒ Object
53
54
55
|
# File 'lib/rbexy/component.rb', line 53
def content
content_block ? content_block.call : ""
end
|
#render(&block) ⇒ Object
39
40
41
42
|
# File 'lib/rbexy/component.rb', line 39
def render(&block)
@content_block = block_given? ? block : nil
call
end
|
#setup(**props) ⇒ Object
Override in your subclass to handle props, setup your component, etc.
You can also implement initialize but you just need to remember to
call super(view_context).
37
|
# File 'lib/rbexy/component.rb', line 37
def setup(**props); end
|