Module: LittleWheels::Component
- Defined in:
- lib/little_wheels.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #+(other) ⇒ Object
- #accepts_slot(block) ⇒ Object
- #capture(&block) ⇒ Object
- #default_template_name ⇒ Object
- #helpers ⇒ Object
- #o(&block) ⇒ Object
- #render_in(context) ⇒ Object
- #renderer ⇒ Object
- #slot ⇒ Object
- #t(template, **locals) ⇒ Object
- #t!(template, **locals) ⇒ Object
- #to_html ⇒ Object
- #to_s ⇒ Object
- #x ⇒ Object
Class Method Details
.included(base) ⇒ Object
21 |
# File 'lib/little_wheels.rb', line 21 def self.included(base) = base.extend(ClassMethods) |
Instance Method Details
#+(other) ⇒ Object
31 |
# File 'lib/little_wheels.rb', line 31 def +(other) = Buffer.new(to_s + other.to_s) |
#accepts_slot(block) ⇒ Object
33 |
# File 'lib/little_wheels.rb', line 33 def accepts_slot(block) = @_slot = block |
#capture(&block) ⇒ Object
35 |
# File 'lib/little_wheels.rb', line 35 def capture(&block) = block.call.to_s.html_safe |
#default_template_name ⇒ Object
37 |
# File 'lib/little_wheels.rb', line 37 def default_template_name = "shared/#{self.class.name.underscore}" |
#helpers ⇒ Object
39 |
# File 'lib/little_wheels.rb', line 39 def helpers = LittleWheels.helpers |
#o(&block) ⇒ Object
29 |
# File 'lib/little_wheels.rb', line 29 def o(&block) = block.binding.receiver.capture(&block) |
#render_in(context) ⇒ Object
43 |
# File 'lib/little_wheels.rb', line 43 def render_in(context) = context.render(:inline => to_html) |
#renderer ⇒ Object
41 |
# File 'lib/little_wheels.rb', line 41 def renderer = LittleWheels.renderer |
#slot ⇒ Object
47 48 49 50 51 |
# File 'lib/little_wheels.rb', line 47 def slot context = @_slot.binding.receiver context.capture { @_slot.call.to_s } end |
#t(template, **locals) ⇒ Object
23 |
# File 'lib/little_wheels.rb', line 23 def t(template, **locals) = renderer.render(inline: template, locals:) |
#t!(template, **locals) ⇒ Object
25 |
# File 'lib/little_wheels.rb', line 25 def t!(template, **locals) = renderer.render(template, locals:, layout: nil) |
#to_html ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/little_wheels.rb', line 53 def to_html helpers.capture do if self.class.const_defined?(:TEMPLATE) t(self.class.const_get(:TEMPLATE), c: self, x: self.x ) else t!(default_template_name, c: self, x: self.x ) end end end |
#to_s ⇒ Object
45 |
# File 'lib/little_wheels.rb', line 45 def to_s = to_html |
#x ⇒ Object
27 |
# File 'lib/little_wheels.rb', line 27 def x = helpers.tag |