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)
readonly
Returns the value of attribute iteration.
-
#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 Layout/LineLength.
- #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 Layout/LineLength
14 15 16 17 18 19 20 21 22 |
# File 'lib/lite/component/base.rb', line 14 def initialize(context, = {}, &block) @components = [] @iteration = ([:locals] || {}).delete(:iteration) || Lite::Component::Iteration.new(1, 0) @context = context @options = .deep_merge() yield(self) if block 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 (readonly) Also known as: i
Returns the value of attribute iteration.
11 12 13 |
# File 'lib/lite/component/base.rb', line 11 def iteration @iteration end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
11 12 13 |
# File 'lib/lite/component/base.rb', line 11 def @options end |
Class Method Details
.build(name) ⇒ Object
32 33 34 35 36 |
# File 'lib/lite/component/base.rb', line 32 def build(name) return name if name.respond_to?(:component_path) "#{name}_component".classify.constantize end |
.component_name ⇒ Object
38 39 40 |
# File 'lib/lite/component/base.rb', line 38 def component_name component_path.split('/').last end |
.component_path ⇒ Object
42 43 44 |
# File 'lib/lite/component/base.rb', line 42 def component_path name.underscore.sub('_component', '') end |
.render(context, options = {}, &block) ⇒ Object
46 47 48 49 |
# File 'lib/lite/component/base.rb', line 46 def render(context, = {}, &block) klass = new(context, , &block) klass.render end |
Instance Method Details
#add(name, options = {}, &block) ⇒ Object
53 54 55 |
# File 'lib/lite/component/base.rb', line 53 def add(name, = {}, &block) components << [name, , block] end |
#locals ⇒ Object Also known as: l
57 58 59 |
# File 'lib/lite/component/base.rb', line 57 def locals @locals ||= Lite::Component::Locals.new([:locals]) end |
#render ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/lite/component/base.rb', line 63 def render return unless render? collection = .delete(:collection) return render_collection(collection) if collection.respond_to?(:each) render_content end |
#render? ⇒ Boolean
72 73 74 |
# File 'lib/lite/component/base.rb', line 72 def render? true end |
#render_content ⇒ Object
76 77 78 |
# File 'lib/lite/component/base.rb', line 76 def render_content context.render() end |
#to_partial_path ⇒ Object
80 81 82 |
# File 'lib/lite/component/base.rb', line 80 def to_partial_path "components/#{self.class.component_path}" end |
#yield ⇒ Object
84 85 86 |
# File 'lib/lite/component/base.rb', line 84 def yield context.safe_join(yield_content) end |