Class: RideTheStreetcar::Custom
- Inherits:
-
Object
- Object
- RideTheStreetcar::Custom
- Includes:
- Streamlined::Renderable
- Defined in:
- lib/ride_the_streetcar/custom.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#tag_name ⇒ Object
readonly
Returns the value of attribute tag_name.
Instance Method Summary collapse
-
#initialize(tag_name, **attributes, &block) ⇒ Custom
constructor
A new instance of Custom.
- #template ⇒ Object
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
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
9 10 11 |
# File 'lib/ride_the_streetcar/custom.rb', line 9 def attributes @attributes end |
#block ⇒ Object (readonly)
Returns the value of attribute block.
12 13 14 |
# File 'lib/ride_the_streetcar/custom.rb', line 12 def block @block end |
#tag_name ⇒ Object (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
#template ⇒ Object
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 |