Class: Lite::Component::Base
- Inherits:
-
Object
- Object
- Lite::Component::Base
- Includes:
- ActionView::Context, ActionView::Helpers
- Defined in:
- lib/lite/component/base.rb
Instance Attribute Summary collapse
-
#components ⇒ Object
Returns the value of attribute components.
-
#context ⇒ Object
(also: #helpers, #c)
readonly
Returns the value of attribute context.
- #iteration ⇒ Object (also: #i)
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
- .build(name) ⇒ Object
- .component_name ⇒ Object
- .component_path ⇒ Object
- .render(context, options = {}, &block) ⇒ Object
Instance Method Summary collapse
- #add(name, options = {}, &block) ⇒ Object
-
#initialize(context, options = {}) {|_self| ... } ⇒ Base
constructor
rubocop:disable Lint/UnusedMethodArgument.
- #locals ⇒ Object (also: #l)
- #render ⇒ Object
- #render? ⇒ Boolean
- #render_content ⇒ Object
- #to_partial_path ⇒ Object
- #yield ⇒ Object
Constructor Details
#initialize(context, options = {}) {|_self| ... } ⇒ Base
rubocop:disable Lint/UnusedMethodArgument
15 16 17 18 19 20 21 22 |
# File 'lib/lite/component/base.rb', line 15 def initialize(context, = {}, &block) @context = context = .deep_merge() @components = [] yield(self) if block_given? end |
Instance Attribute Details
#components ⇒ Object
Returns the value of attribute components.
10 11 12 |
# File 'lib/lite/component/base.rb', line 10 def components @components end |
#context ⇒ Object (readonly) Also known as: helpers, c
Returns the value of attribute context.
11 12 13 |
# File 'lib/lite/component/base.rb', line 11 def context @context end |
#iteration ⇒ Object Also known as: i
56 57 58 |
# File 'lib/lite/component/base.rb', line 56 def iteration @iteration ||= Lite::Component::Iteration.new(1, 0) end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
11 12 13 |
# File 'lib/lite/component/base.rb', line 11 def end |
Class Method Details
.build(name) ⇒ Object
31 32 33 34 35 |
# File 'lib/lite/component/base.rb', line 31 def build(name) return name if name.respond_to?(:component_path) "#{name}_component".classify.constantize end |
.component_name ⇒ Object
37 38 39 |
# File 'lib/lite/component/base.rb', line 37 def component_name component_path.split('/').last end |
.component_path ⇒ Object
41 42 43 |
# File 'lib/lite/component/base.rb', line 41 def component_path name.underscore.sub('_component', '') end |
.render(context, options = {}, &block) ⇒ Object
45 46 47 48 |
# File 'lib/lite/component/base.rb', line 45 def render(context, = {}, &block) klass = new(context, , &block) klass.render end |
Instance Method Details
#add(name, options = {}, &block) ⇒ Object
52 53 54 |
# File 'lib/lite/component/base.rb', line 52 def add(name, = {}, &block) components << [name, , block] end |
#locals ⇒ Object Also known as: l
62 63 64 |
# File 'lib/lite/component/base.rb', line 62 def locals @locals ||= Lite::Component::Locals.new([:locals]) end |
#render ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/lite/component/base.rb', line 68 def render return unless render? collection = .delete(:collection) return render_content if collection.nil? || !collection.respond_to?(:each) Lite::Component::Collection.render( collection, component: self, spacer_template: .delete(:spacer_template) ) end |
#render? ⇒ Boolean
81 82 83 |
# File 'lib/lite/component/base.rb', line 81 def render? true end |
#render_content ⇒ Object
85 86 87 |
# File 'lib/lite/component/base.rb', line 85 def render_content context.render() end |
#to_partial_path ⇒ Object
89 90 91 |
# File 'lib/lite/component/base.rb', line 89 def to_partial_path "components/#{self.class.component_path}" end |
#yield ⇒ Object
93 94 95 |
# File 'lib/lite/component/base.rb', line 93 def yield context.safe_join(yield_content) end |