Class: EJX::Template::HTMLTag
Defined Under Namespace
Classes: AttributeValue
Instance Attribute Summary collapse
-
#attrs ⇒ Object
Returns the value of attribute attrs.
-
#namespace ⇒ Object
Returns the value of attribute namespace.
-
#tag_name ⇒ Object
Returns the value of attribute tag_name.
Attributes inherited from Node
Instance Method Summary collapse
-
#initialize ⇒ HTMLTag
constructor
A new instance of HTMLTag.
- #inspect ⇒ Object
- #to_js(append: "__output", var_generator:, indentation: 4, namespace: nil, promises: '__promises') ⇒ Object
- #to_s ⇒ Object
Methods inherited from Node
Constructor Details
#initialize ⇒ HTMLTag
Returns a new instance of HTMLTag.
7 8 9 10 |
# File 'lib/ejx/template/html_tag.rb', line 7 def initialize super @attrs = [] end |
Instance Attribute Details
#attrs ⇒ Object
Returns the value of attribute attrs.
5 6 7 |
# File 'lib/ejx/template/html_tag.rb', line 5 def attrs @attrs end |
#namespace ⇒ Object
Returns the value of attribute namespace.
5 6 7 |
# File 'lib/ejx/template/html_tag.rb', line 5 def namespace @namespace end |
#tag_name ⇒ Object
Returns the value of attribute tag_name.
5 6 7 |
# File 'lib/ejx/template/html_tag.rb', line 5 def tag_name @tag_name end |
Instance Method Details
#inspect ⇒ Object
16 17 18 |
# File 'lib/ejx/template/html_tag.rb', line 16 def inspect "#<EJX::HTMLTag:#{self.object_id} @tag_name=#{tag_name}>" end |
#to_js(append: "__output", var_generator:, indentation: 4, namespace: nil, promises: '__promises') ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/ejx/template/html_tag.rb', line 20 def to_js(append: "__output", var_generator:, indentation: 4, namespace: nil, promises: '__promises') namespace ||= self.namespace output_var = var_generator.next js = "#{' '*indentation}var #{output_var} = document.createElement" js << if namespace "NS(#{namespace.to_js}, #{JSON.generate(tag_name)});\n" else "(#{JSON.generate(tag_name)});\n" end @attrs.each do |attr| if attr.is_a?(Hash) attr.each do |k, v| js << "#{' '*indentation}#{output_var}.setAttribute(#{JSON.generate(k)}, #{v.to_js});\n" end else js << "#{' '*indentation}#{output_var}.setAttribute(#{JSON.generate(attr)}, \"\");\n" end end @children.each do |child| js << if child.is_a?(EJX::Template::String) "#{' '*indentation}__ejx_append(#{child.to_js}, #{output_var}, 'unescape', #{promises});\n" elsif child.is_a?(EJX::Template::HTMLTag) child.to_js(var_generator: var_generator, indentation: indentation, append: output_var, namespace: namespace, promises: promises) else child.to_js(var_generator: var_generator, indentation: indentation, append: output_var, promises: promises) end end js << "#{' '*indentation}__ejx_append(#{output_var}, #{append}, 'unescape', #{promises});\n" js end |
#to_s ⇒ Object
12 13 14 |
# File 'lib/ejx/template/html_tag.rb', line 12 def to_s @value end |