41: def tag!(sym, *args, &block)
42: text = nil
43: attrs = nil
44: sym = "#{sym}:#{args.shift}" if args.first.kind_of?(::Symbol)
45: sym = sym.to_sym unless sym.class == ::Symbol
46: args.each do |arg|
47: case arg
48: when ::Hash
49: attrs ||= {}
50: attrs.merge!(arg)
51: when nil
52: attrs ||= {}
53: attrs.merge!({:nil => true}) if explicit_nil_handling?
54: else
55: text ||= ''
56: text << arg.to_s
57: end
58: end
59: if block
60: unless text.nil?
61: ::Kernel::raise ::ArgumentError,
62: "XmlMarkup cannot mix a text argument with a block"
63: end
64: _indent
65: _start_tag(sym, attrs)
66: _newline
67: begin
68: _nested_structures(block)
69: ensure
70: _indent
71: _end_tag(sym)
72: _newline
73: end
74: elsif text.nil?
75: _indent
76: _start_tag(sym, attrs, true)
77: _newline
78: else
79: _indent
80: _start_tag(sym, attrs)
81: text! text
82: _end_tag(sym)
83: _newline
84: end
85: @target
86: end