Class: Erector::Tag
- Inherits:
-
Object
- Object
- Erector::Tag
- Defined in:
- lib/erector/tag.rb
Overview
Defines a type of tag (not an actual element with attributes and contents)
Instance Attribute Summary collapse
-
#method_name ⇒ Object
readonly
Returns the value of attribute method_name.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(name, *params) ⇒ Tag
constructor
Pass the self_closing and inline params as symbols, e.g.
- #inline? ⇒ Boolean
- #newliney? ⇒ Boolean
- #self_closing? ⇒ Boolean
-
#snake_case(s) ⇒ String
Convert to snake case.
Constructor Details
#initialize(name, *params) ⇒ Tag
Pass the self_closing and inline params as symbols, e.g.
Tag.new(“i”, :inline) Tag.new(“input”, :inline, :self_closing)
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/erector/tag.rb', line 16 def initialize(name, *params) @name = name.to_s @method_name = if params.first.is_a? String params.shift else @name end @self_closing = params.include?(:self_closing) @inline = params.include?(:inline) @method_name = snake_case(@method_name) if params.include?(:snake_case) end |
Instance Attribute Details
#method_name ⇒ Object (readonly)
Returns the value of attribute method_name.
28 29 30 |
# File 'lib/erector/tag.rb', line 28 def method_name @method_name end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
28 29 30 |
# File 'lib/erector/tag.rb', line 28 def name @name end |
Instance Method Details
#inline? ⇒ Boolean
38 39 40 |
# File 'lib/erector/tag.rb', line 38 def inline? @inline end |
#newliney? ⇒ Boolean
34 35 36 |
# File 'lib/erector/tag.rb', line 34 def newliney? !@inline end |
#self_closing? ⇒ Boolean
30 31 32 |
# File 'lib/erector/tag.rb', line 30 def self_closing? @self_closing end |
#snake_case(s) ⇒ String
Convert to snake case.
"FooBar".snake_case #=> "foo_bar"
"HeadlineCNNNews".snake_case #=> "headline_cnn_news"
"CNN".snake_case #=> "cnn"
borrowed from github.com/datamapper/extlib/blob/master/lib/extlib/string.rb
53 54 55 56 57 58 59 60 61 |
# File 'lib/erector/tag.rb', line 53 def snake_case(s) if s.match(/\A[A-Z]+\z/) s.downcase else s.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2'). gsub(/([a-z])([A-Z])/, '\1_\2'). downcase end end |