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
-
#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
Instance Method Summary collapse
-
#initialize(context, options = {}) ⇒ Base
constructor
A new instance of Base.
- #locals ⇒ Object (also: #l)
- #render ⇒ Object
- #render_content ⇒ Object
- #to_partial_path ⇒ Object
Constructor Details
#initialize(context, options = {}) ⇒ Base
Returns a new instance of Base.
13 14 15 16 |
# File 'lib/lite/component/base.rb', line 13 def initialize(context, = {}) @context = context @options = .deep_merge() end |
Instance Attribute Details
#context ⇒ Object (readonly) Also known as: helpers, c
Returns the value of attribute context.
10 11 12 |
# File 'lib/lite/component/base.rb', line 10 def context @context end |
#iteration ⇒ Object Also known as: i
39 40 41 |
# File 'lib/lite/component/base.rb', line 39 def iteration @iteration ||= Lite::Component::Iteration.new(1, 0) end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
10 11 12 |
# File 'lib/lite/component/base.rb', line 10 def @options end |
Class Method Details
.component_name ⇒ Object
24 25 26 |
# File 'lib/lite/component/base.rb', line 24 def component_name component_path.split('/').last end |
.component_path ⇒ Object
28 29 30 |
# File 'lib/lite/component/base.rb', line 28 def component_path name.underscore.sub('_component', '') end |
.render(context, options = {}) ⇒ Object
32 33 34 35 |
# File 'lib/lite/component/base.rb', line 32 def render(context, = {}) klass = new(context, ) klass.render end |
Instance Method Details
#locals ⇒ Object Also known as: l
45 46 47 |
# File 'lib/lite/component/base.rb', line 45 def locals @locals ||= Lite::Component::Locals.new([:locals]) end |
#render ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/lite/component/base.rb', line 51 def 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_content ⇒ Object
62 63 64 |
# File 'lib/lite/component/base.rb', line 62 def render_content context.render() end |
#to_partial_path ⇒ Object
66 67 68 |
# File 'lib/lite/component/base.rb', line 66 def to_partial_path "components/#{self.class.component_path}" end |