Class: Urbane::Generator

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

Constant Summary collapse

GENERATORS =
{
  :json => lambda{|content| JSON.pretty_generate(content)},
  :yaml => lambda{|content| content.to_yaml},
  :xml  => lambda do |content|
              builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
                xml.send('resource-bundle', 'xmlns' => '',
                              'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance') do
                  content.each do |key, translation|
                    xml.resource(translation, 'key' => key)
                  end
                end
              end
              builder.to_xml(:indent => 2,  :encoding => 'UTF-8')
           end,
  :apple_strings => lambda do |content|
                      output = ""
                      content.each do |key, translation|
                        output << "\"#{key}\" = \"#{translation}\";\n"
                      end
                      output
                    end
}

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Generator

Returns a new instance of Generator.



34
35
36
37
38
39
40
41
42
# File 'lib/urbane.rb', line 34

def initialize(options)
  @target_dir = options[:target_dir]
  @spreadsheet_id = options[:spreadsheet_id]
  @file_name_for_translation_file = options[:file_name]
  @language_locale_map = options[:languages]
  @languages = @language_locale_map.keys
  @fallback_language = options[:fallback_language]
  @format = options[:format] || :json
end

Instance Method Details

#google_spreadsheet_urlObject



54
55
56
# File 'lib/urbane.rb', line 54

def google_spreadsheet_url
  "http://spreadsheets.google.com/feeds/worksheets/#{@spreadsheet_id}/public/values/?alt=json"
end

#runObject



44
45
46
47
48
49
50
51
52
# File 'lib/urbane.rb', line 44

def run
  @text_ids = {}
  @languages.each do |language|
    @text_ids[language] = {}
  end

  process_spreadsheet
  write_files
end