Module: LittleWheels::Component

Defined in:
lib/little_wheels.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

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_nameObject



37
# File 'lib/little_wheels.rb', line 37

def default_template_name = "shared/#{self.class.name.underscore}"

#helpersObject



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)

#rendererObject



41
# File 'lib/little_wheels.rb', line 41

def renderer = LittleWheels.renderer

#slotObject



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_htmlObject



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_sObject



45
# File 'lib/little_wheels.rb', line 45

def to_s = to_html

#xObject



27
# File 'lib/little_wheels.rb', line 27

def x = helpers.tag