Class: Matterhorn::JavaProperties

Inherits:
Object
  • Object
show all
Defined in:
lib/matterhorn/java_properties.rb

Overview

Matterhorn::JavaProperties ===

Class Method Summary collapse

Class Method Details

.generate_xml(hash, options = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/matterhorn/java_properties.rb', line 19

def self.generate_xml(hash, options = {})
  Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
    xml.doc.create_internal_subset('properties', nil, 'http://java.sun.com/dtd/properties.dtd')
    xml.properties do
      xml.comment_(options[:comment])    unless options[:comment].nil?
      hash.each_pair do |key, value|
        if options[:cdata] && options[:cdata].include?(key)
          xml.entry(:key => key) do
            xml.cdata(value)
          end
        else
          xml.entry(value, :key => key)
        end
      end
    end
  end.doc.to_xml
end

.write(hash, path, options = {}) ⇒ Object

———————————————————————————– methodes —



13
14
15
16
# File 'lib/matterhorn/java_properties.rb', line 13

def self.write(hash, path, options = {})
  xml = generate_xml(hash, options)
  File.write(path, generate_xml(hash, options))
end