Class: Condenser::SVGTransformer::Tag
- Inherits:
-
Object
- Object
- Condenser::SVGTransformer::Tag
- Defined in:
- lib/condenser/transformers/svg_transformer/tag.rb
Instance Attribute Summary collapse
-
#attrs ⇒ Object
Returns the value of attribute attrs.
-
#children ⇒ Object
Returns the value of attribute children.
-
#namespace ⇒ Object
Returns the value of attribute namespace.
-
#tag_name ⇒ Object
Returns the value of attribute tag_name.
Instance Method Summary collapse
-
#initialize(name) ⇒ Tag
constructor
A new instance of Tag.
- #inspect ⇒ Object
- #to_js(append: nil, var_generator:, indentation: 4, namespace: nil) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name) ⇒ Tag
Returns a new instance of Tag.
7 8 9 10 11 |
# File 'lib/condenser/transformers/svg_transformer/tag.rb', line 7 def initialize(name) @tag_name = name @attrs = [] @children = [] end |
Instance Attribute Details
#attrs ⇒ Object
Returns the value of attribute attrs.
5 6 7 |
# File 'lib/condenser/transformers/svg_transformer/tag.rb', line 5 def attrs @attrs end |
#children ⇒ Object
Returns the value of attribute children.
5 6 7 |
# File 'lib/condenser/transformers/svg_transformer/tag.rb', line 5 def children @children end |
#namespace ⇒ Object
Returns the value of attribute namespace.
5 6 7 |
# File 'lib/condenser/transformers/svg_transformer/tag.rb', line 5 def namespace @namespace end |
#tag_name ⇒ Object
Returns the value of attribute tag_name.
5 6 7 |
# File 'lib/condenser/transformers/svg_transformer/tag.rb', line 5 def tag_name @tag_name end |
Instance Method Details
#inspect ⇒ Object
17 18 19 |
# File 'lib/condenser/transformers/svg_transformer/tag.rb', line 17 def inspect "#<SVG::Tag:#{self.object_id} @tag_name=#{tag_name}>" end |
#to_js(append: nil, var_generator:, indentation: 4, namespace: nil) ⇒ Object
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/condenser/transformers/svg_transformer/tag.rb', line 21 def to_js(append: nil, var_generator:, indentation: 4, namespace: nil) 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.is_a?(String) ? v : 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?(Condenser::SVGTransformer::Tag) child.to_js(var_generator: var_generator, indentation: indentation, append: output_var, namespace: namespace) else child.to_js(var_generator: var_generator, indentation: indentation, append: output_var) end end js << "#{' '*indentation}#{append}.append(#{output_var});\n" if append js end |
#to_s ⇒ Object
13 14 15 |
# File 'lib/condenser/transformers/svg_transformer/tag.rb', line 13 def to_s @value end |