Module: DataMapper::Serialize::XMLSerializers::Nokogiri
- Defined in:
- lib/dm-serializer/xml_serializers/nokogiri.rb
Class Method Summary collapse
- .add_node(parent, name, value, attrs = {}) ⇒ Object
- .add_xml(parent, xml) ⇒ Object
- .new_document ⇒ Object
- .output(doc) ⇒ Object
- .root_node(doc, name, attrs = {}) ⇒ Object
Class Method Details
.add_node(parent, name, value, attrs = {}) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/dm-serializer/xml_serializers/nokogiri.rb', line 18 def self.add_node(parent, name, value, attrs = {}) node = ::Nokogiri::XML::Node.new(name, parent.document) node << ::Nokogiri::XML::Text.new(value.to_s, parent.document) unless value.nil? attrs.each {|attr_name, attr_val| node[attr_name] = attr_val } parent << node node end |
.add_xml(parent, xml) ⇒ Object
26 27 28 |
# File 'lib/dm-serializer/xml_serializers/nokogiri.rb', line 26 def self.add_xml(parent, xml) parent << xml.root end |
.new_document ⇒ Object
5 6 7 |
# File 'lib/dm-serializer/xml_serializers/nokogiri.rb', line 5 def self.new_document ::Nokogiri::XML::Document.new end |
.output(doc) ⇒ Object
30 31 32 |
# File 'lib/dm-serializer/xml_serializers/nokogiri.rb', line 30 def self.output(doc) doc.root.to_s end |
.root_node(doc, name, attrs = {}) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/dm-serializer/xml_serializers/nokogiri.rb', line 9 def self.root_node(doc, name, attrs = {}) root = ::Nokogiri::XML::Node.new(name, doc) attrs.each do |attr_name, attr_val| root[attr_name] = attr_val end doc.root.nil? ? doc.root = root : doc.root << root root end |