Class: Stringer::Processor
- Inherits:
-
Object
- Object
- Stringer::Processor
- Defined in:
- lib/stringer/processor.rb
Instance Method Summary collapse
-
#default_options ⇒ Object
Some sensible defaults in a hash.
-
#dir_path_for_dir_with_same_name_as_parent_dir ⇒ Object
If standard Xcode template is used, this is the dir where most files will be.
-
#files ⇒ Object
Returns an array of all files needed to be processed.
- #genstrings_command ⇒ Object
-
#initialize(locale, options = {}) ⇒ Processor
constructor
The Processor will be doing the genstringing part of the operation.
- #log(message) ⇒ Object
- #lproj_folder ⇒ Object
- #run ⇒ Object
- #show_changes(keys, string) ⇒ Object
- #strings_file_path ⇒ Object
Constructor Details
#initialize(locale, options = {}) ⇒ Processor
The Processor will be doing the genstringing part of the operation.
Possible options:
- file_folder : Folder where `genstrings` should look for
.m files. It searches this recursively.
- genstrings : Location of the genstrings command
- lproj_parent : Path to folder containing the `<locale>.lproj`
14 15 16 17 18 19 20 |
# File 'lib/stringer/processor.rb', line 14 def initialize(locale, = {}) = .merge() @locale = locale @files_folder = [:files_folder] @genstrings = [:genstrings] @lproj_parent = [:lproj_parent] end |
Instance Method Details
#default_options ⇒ Object
Some sensible defaults in a hash
23 24 25 26 27 28 29 |
# File 'lib/stringer/processor.rb', line 23 def { :lproj_parent => dir_path_for_dir_with_same_name_as_parent_dir, :files_folder => dir_path_for_dir_with_same_name_as_parent_dir, :genstrings => "/usr/bin/genstrings" } end |
#dir_path_for_dir_with_same_name_as_parent_dir ⇒ Object
If standard Xcode template is used, this is the dir where most files will be. For a project created with name “Something”
Something:
Something:
en.lproj/
*.m
Returns the path
40 41 42 43 44 |
# File 'lib/stringer/processor.rb', line 40 def dir_path_for_dir_with_same_name_as_parent_dir current_dir_path = File.dirname(__FILE__) current_dir_name = File.basename(current_dir_path) File.join(current_dir_path, current_dir_name) end |
#files ⇒ Object
Returns an array of all files needed to be processed.
51 52 53 |
# File 'lib/stringer/processor.rb', line 51 def files `find #{@files_folder} -name \*.m`.split("\n") end |
#genstrings_command ⇒ Object
46 47 48 |
# File 'lib/stringer/processor.rb', line 46 def genstrings_command "#{@genstrings} -q -o #{lproj_folder} #{files.join(" ")}" end |
#log(message) ⇒ Object
75 76 77 |
# File 'lib/stringer/processor.rb', line 75 def log() puts end |
#lproj_folder ⇒ Object
67 68 69 |
# File 'lib/stringer/processor.rb', line 67 def lproj_folder File.join(@lproj_parent, "#{@locale}.lproj") end |
#run ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/stringer/processor.rb', line 55 def run log("Generating #{@locale}.lproj") original_file = StringsFile.new(strings_file_path) if system(genstrings_command) new_file = StringsFile.new(strings_file_path) added_keys, removed_keys = original_file.apply(new_file) show_changes(added_keys, "Added") show_changes(removed_keys, "Removed") end original_file.write! end |
#show_changes(keys, string) ⇒ Object
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/stringer/processor.rb', line 79 def show_changes(keys, string) number = keys.count if number == 1 string = " - #{string} #{number} key" else string = " - #{string} #{number} keys" end string << " (#{keys.join(";")[0..50]}...)" unless number == 0 log string end |
#strings_file_path ⇒ Object
71 72 73 |
# File 'lib/stringer/processor.rb', line 71 def strings_file_path "#{lproj_folder}/Localizable.strings" end |