Method: Builder::XmlBase#tag!

Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/builder-3.2.4/lib/builder/xmlbase.rb

#tag!(sym, *args, &block) ⇒ Object

Create a tag named sym. Other than the first argument which is the tag name, the arguments are the same as the tags implemented via method_missing.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/builder-3.2.4/lib/builder/xmlbase.rb', line 42

def tag!(sym, *args, &block)
  text = nil
  attrs = nil
  sym = "#{sym}:#{args.shift}" if args.first.kind_of?(::Symbol)
  sym = sym.to_sym unless sym.class == ::Symbol
  args.each do |arg|
    case arg
    when ::Hash
      attrs ||= {}
      attrs.merge!(arg)
    when nil
      attrs ||= {}
      attrs.merge!({:nil => true}) if explicit_nil_handling?
    else
      text ||= ''.dup
      text << arg.to_s
    end
  end
  if block
    unless text.nil?
      ::Kernel::raise ::ArgumentError,
        "XmlMarkup cannot mix a text argument with a block"
    end
    _indent
    _start_tag(sym, attrs)
    _newline
    begin
      _nested_structures(block)
    ensure
      _indent
      _end_tag(sym)
      _newline
    end
  elsif text.nil?
    _indent
    _start_tag(sym, attrs, true)
    _newline
  else
    _indent
    _start_tag(sym, attrs)
    text! text
    _end_tag(sym)
    _newline
  end
  @target
end