Skip to content

Commit

Permalink
Fixes xcode macros format
Browse files Browse the repository at this point in the history
  • Loading branch information
François Benaiteau committed Oct 29, 2014
1 parent 0b02a92 commit 20888c0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/babelish/xcode_macros.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ def self.write_macros(file_path, table, keys)

def process(table, keys)
keys.each do |key|
macro_name = "LS_#{key.upcase}"
clean_key = key.gsub(' ', '')
clean_key.gsub!(/[[:punct:]]/, '_')
clean_key.gsub!('__', '_')
clean_key = clean_key[1..clean_key.size-1] if clean_key[0] == '_'
clean_key = clean_key[0..clean_key.size-2] if clean_key.size > 1 and clean_key[clean_key.size-1] == '_'
macro_name = "LS_#{clean_key.upcase}"
macro_name += "_#{table.upcase}" if table != "Localizable"
macro_name.gsub!(' ', '')
macro_name.gsub!('.', '_')
macro_name.gsub!('-', '_')
@content << String.new(<<-EOS)
#define #{macro_name} NSLocalizedStringFromTable(@"#{key}",@"#{table}",@"")
EOS
Expand Down
27 changes: 27 additions & 0 deletions test/babelish/test_xcode_macros.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,31 @@ def test_write_macros_process
#clean up
system("rm -f ./Babelish.h")
end

def test_write_macros_process_with_special_characters
keys = ["%d blabla", "login!", "HEY!!"]
table = "Localizable"
macros = Babelish::XcodeMacros.new
macros.process(table, keys)
macros.write_content("Babelish.h")
expected_output = String.new(<<-EOS)
//
// Babelish.h
//
// This file was generated by Babelish
//
// https://github.com/netbe/babelish
//
#define LS_DBLABLA NSLocalizedStringFromTable(@"%d blabla",@"Localizable",@"")
#define LS_LOGIN NSLocalizedStringFromTable(@"login!",@"Localizable",@"")
#define LS_HEY NSLocalizedStringFromTable(@"HEY!!",@"Localizable",@"")
EOS
assert File.exists?("Babelish.h")
result = File.read("Babelish.h")
assert_equal expected_output, result
#clean up
system("rm -f ./Babelish.h")
end


end

0 comments on commit 20888c0

Please sign in to comment.