class Terrestrial::Cli::Flight::IosWorkflow

Public Class Methods

new(bootstrap_results) click to toggle source
# File lib/terrestrial/cli/flight/ios_workflow.rb, line 6
def initialize(bootstrap_results)
  @results = bootstrap_results
end

Public Instance Methods

run() click to toggle source
# File lib/terrestrial/cli/flight/ios_workflow.rb, line 10
def run
  print_instructions
  command = STDIN.gets.chomp

  if command == "y"
    lproj_folder = TerminalUI.show_spinner do
      Editor.prepare_files(results.all_occurences)
      initalize_localizable_strings_files
    end
    add_file_to_config(lproj_folder)
    print_done_message(lproj_folder)
  end
end

Private Instance Methods

add_file_to_config(path) click to toggle source
# File lib/terrestrial/cli/flight/ios_workflow.rb, line 47
def add_file_to_config(path)
  path_to_file = Pathname.new(path)
  current_dir  = Pathname.new(Config[:directory])

  Config.load({ translation_files: [
    path_to_file.relative_path_from(current_dir).to_s
  ]})
  Config.update_project_config
end
create_path_to_localization_files() click to toggle source
# File lib/terrestrial/cli/flight/ios_workflow.rb, line 39
def create_path_to_localization_files
  folder_name = Pathname.new(Dir[Config[:directory] + "/*.xcodeproj"].first).basename(".*").to_s
  project_language = detect_project_language(folder_name)
  base_lproj_path = FileUtils.mkdir_p(Config[:directory] + "/#{folder_name}" + "/#{project_language}.lproj").first

  base_lproj_path + "/Localizable.strings"
end
detect_project_language(folder) click to toggle source
# File lib/terrestrial/cli/flight/ios_workflow.rb, line 57
def detect_project_language(folder)
  info_plist = Dir[Config[:directory] + "/#{folder}/Info.plist"].first
  lang = `defaults read '#{info_plist}' CFBundleDevelopmentRegion 2> /dev/null`.gsub("\n", "").squeeze(" ")

  if lang.empty?
    puts "Unable to detect project language. Defaulting to 'en'."
    'en'
  else
    lang
  end
end
initalize_localizable_strings_files() click to toggle source
# File lib/terrestrial/cli/flight/ios_workflow.rb, line 26
def initalize_localizable_strings_files
  path = create_path_to_localization_files

  File.open(path, "a+") do |f|
    formatter = DotStringsFormatter.new(results)

    f.write "// Created by Terrestrial (#{Time.now.to_s})"
    f.write "\n\n"
    f.write formatter.format
  end
  path
end
print_done_message(lproj_folder) click to toggle source
print_instructions() click to toggle source
results() click to toggle source
# File lib/terrestrial/cli/flight/ios_workflow.rb, line 86
def results
  @results
end