A class that encapsulats the XML generation functionality. Utilizes duck typing to redirect output to a target buffer.
Methods
Included Modules
- XmlHelper
Attributes
| [RW] | target | The target receives the generated xml, should respond_to :<< |
Public Class methods
[ show source ]
# File lib/raw/view/xml.rb, line 113
113: def initialize(target = '')
114: @target = target
115: end
Public Instance methods
[ show source ]
# File lib/raw/view/xml.rb, line 117
117: def << (str)
118: @target << str
119: end
Emit a comment.
[ show source ]
# File lib/glue/builder/xml.rb, line 79
79: def comment!(str)
80: @buffer << "<!-- #{str} -->"
81:
82: return self
83: end
Emit the end (closing) tag of an element.
[ show source ]
# File lib/glue/builder/xml.rb, line 71
71: def end_tag!(tag)
72: @buffer << "</#{tag}>"
73:
74: return self
75: end
[ show source ]
# File lib/glue/builder/xml.rb, line 19
19: def method_missing(tag, *args, &block)
20: self.class.module_eval "def \#{tag}(*args)\nattrs = args.last.is_a?(Hash) ? args.pop : nil\n\nif block_given?\nstart_tag!('\#{tag}', attrs)\nyield\nend_tag!('\#{tag}')\nelsif (!args.empty?)\nstart_tag!('\#{tag}', attrs)\n@buffer << args.first.to_s\nend_tag!('\#{tag}')\nelse\nstart_tag!('\#{tag}', attrs, false)\n@buffer << ' />'\nend\n\nreturn self\nend\n", __FILE__, __LINE__
21:
22: self.send(tag, *args, &block)
23: end
Alias for #processing_instruction!
Emit a processing instruction.
This method is also aliased as
pi!
[ show source ]
# File lib/glue/builder/xml.rb, line 87
87: def processing_instruction!(name, attributes = nil)
88: unless attributes
89: @buffer << "<?#{name} ?>"
90: else
91: @buffer << "<?#{name} "
92: attributes.each do |a, v|
93: @buffer << %[#{a}="#{v}" ]
94: end
95: @buffer << "?>"
96: end
97:
98: return self
99: end
Emit the start (opening) tag of an element.
[ show source ]
# File lib/glue/builder/xml.rb, line 47
47: def start_tag!(tag, attributes = nil, close = true)
48: unless attributes
49: if close
50: @buffer << "<#{tag}>"
51: else
52: @buffer << "<#{tag}"
53: end
54: else
55: @buffer << "<#{tag}"
56: for name, value in attributes
57: if value
58: @buffer << %| #{name}="#{value}"|
59: else
60: @buffer << %| #{name}="1"|
61: end
62: end
63: @buffer << ">" if close
64: end
65:
66: return self
67: end
[ show source ]
# File lib/raw/view/xml.rb, line 121
121: def to_s
122: @target.to_s
123: end