Class: RideTheStreetcar::Custom

Inherits:
Object
  • Object
show all
Includes:
Streamlined::Renderable
Defined in:
lib/ride_the_streetcar/custom.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, **attributes, &block) ⇒ Custom

Returns a new instance of Custom.



14
15
16
17
18
# File 'lib/ride_the_streetcar/custom.rb', line 14

def initialize(tag_name, **attributes, &block)
  @tag_name = tag_name.to_s.tr("_", "-").prepend("sc-c-")
  @attributes = attributes
  @block = block
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



9
10
11
# File 'lib/ride_the_streetcar/custom.rb', line 9

def attributes
  @attributes
end

#blockObject (readonly)

Returns the value of attribute block.



12
13
14
# File 'lib/ride_the_streetcar/custom.rb', line 12

def block
  @block
end

#tag_nameObject (readonly)

Returns the value of attribute tag_name.



6
7
8
# File 'lib/ride_the_streetcar/custom.rb', line 6

def tag_name
  @tag_name
end

Instance Method Details

#templateObject



20
21
22
23
24
25
26
27
28
# File 'lib/ride_the_streetcar/custom.rb', line 20

def template
  interior = helpers.capture(&block).then { "<template>#{_1.to_s.strip}</template>" } if block
  tag_name = self.tag_name.then { attributes.empty? ? _1 : "#{_1} " }

  html -> { <<~HTML.strip
    <#{text tag_name}#{html_attributes attributes}>#{html->{ interior }}</#{text tag_name.strip}>
  HTML
  }
end