Top Level Namespace
Defined Under Namespace
Modules: Slim, Temple
Classes: String
Instance Method Summary
collapse
Instance Method Details
#hash_to_xml(hash, root = 'root') ⇒ Object
183
184
185
186
187
|
# File 'lib/shady.rb', line 183
def hash_to_xml(hash, root='root')
Nokogiri::XML::Builder.new do |xml|
xml.send(root) { hash_to_xml_builder(xml, hash) }
end.to_xml
end
|
#hash_to_xml_builder(xml, hash) ⇒ Object
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
# File 'lib/shady.rb', line 166
def hash_to_xml_builder(xml, hash)
hash.each do |key, value|
case value
when Hash
xml.send(key) { hash_to_xml_builder(xml, value) }
when Array
value.each do |v|
xml.send(key) do
v.is_a?(Hash) ? hash_to_xml_builder(xml, v) : xml.text(v)
end
end
else
xml.send(key, value)
end
end
end
|
#slim(str = "") ⇒ Object
217
218
219
|
# File 'lib/shady.rb', line 217
def slim(str="")
Slim::Template.new(pretty: true, strip: true, format: :xml) { str }.result
end
|