Class: Terrestrial::Cli::AndroidXmlFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/terrestrial/cli/android_xml_formatter.rb

Instance Method Summary collapse

Constructor Details

#initialize(entries) ⇒ AndroidXmlFormatter

Returns a new instance of AndroidXmlFormatter.



7
8
9
# File 'lib/terrestrial/cli/android_xml_formatter.rb', line 7

def initialize(entries)
  @entries = entries
end

Instance Method Details

#format_foreign_translationObject



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/terrestrial/cli/android_xml_formatter.rb', line 11

def format_foreign_translation
  root = REXML::Element.new("resources")

  entries.each do |entry|
    root.add_element("string", {
      "name"    => entry.identifier 
    }).add_text(entry.string)
  end

  print_xml(root)
end


23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/terrestrial/cli/android_xml_formatter.rb', line 23

def print_xml(document)
  # In which we wrestle with REXML's insanity

  REXML::Attribute.class_eval( %q^
                                    def to_string
                                      %Q[#@expanded_name="#{to_s().gsub(/"/, '"')}"]
                                    end
                                ^)
  formatter = CustomPrinter.new(4) # See editor/printer
  formatter.compact = true
  formatter.write(document,"") + "\n"
end