Class: Htmlrb::Tag
- Inherits:
-
Object
- Object
- Htmlrb::Tag
- Defined in:
- lib/htmlrb/tag.rb
Instance Attribute Summary collapse
-
#html_parts ⇒ Object
readonly
Returns the value of attribute html_parts.
Instance Method Summary collapse
- #doctype ⇒ Object
-
#initialize ⇒ Tag
constructor
A new instance of Tag.
- #method_missing(method_name, content_or_options = "", options = {}, &block) ⇒ Object
Constructor Details
#initialize ⇒ Tag
9 10 11 |
# File 'lib/htmlrb/tag.rb', line 9 def initialize @html_parts = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, content_or_options = "", options = {}, &block) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/htmlrb/tag.rb', line 17 def method_missing(method_name, = "", = {}, &block) = if .is_a?(Hash) elm_name = method_name.to_s.gsub('_', '-') @html_parts << "<#{elm_name}" @html_parts << " " unless .empty? @html_parts << .map do |key, val| attr_name = key.to_s.gsub('_', '-') "#{attr_name}=\"#{CGI.escapeHTML(val)}\"" end.join(" ") @html_parts << ">" if block content = block.call(self) @html_parts << CGI.escapeHTML(content) if content elsif .is_a?(String) @html_parts << CGI.escapeHTML() end if block || .is_a?(String) @html_parts << "</#{elm_name}>" end nil end |
Instance Attribute Details
#html_parts ⇒ Object (readonly)
Returns the value of attribute html_parts.
7 8 9 |
# File 'lib/htmlrb/tag.rb', line 7 def html_parts @html_parts end |
Instance Method Details
#doctype ⇒ Object
13 14 15 |
# File 'lib/htmlrb/tag.rb', line 13 def doctype @html_parts << "<!DOCTYPE html>" end |