locamotion 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8f98cc06a39c9782efbfd0f0cc9af6c6666a6773
4
+ data.tar.gz: 957a717ca5a6e7830b1ae3afb99d7248c3d0ea3c
5
+ SHA512:
6
+ metadata.gz: 34f9570f3f00031e7aaddbe7ba6fd681d81a48da8b8fe63dfdadebaad3092dab44c0f84b54b85136a2b797a811df3b2de46e72647646d17b38a48fcb67870ce1
7
+ data.tar.gz: 6ac24e7ee55dc2da2dab3d163501bd9a8ef6a02a6861df17add45d5ef4073a21c884e70a3d1f74076998ed47b661c7e2123f2e2d86a359d9c8c2ef848026cee0
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ gem 'thor', "~> 0"
9
+ group :development do
10
+ gem 'aruba', "~> 0"
11
+ gem "rspec", "~> 3.1.0"
12
+ gem "rdoc", "~> 3.12"
13
+ gem "cucumber", ">= 0"
14
+ gem "bundler", "~> 1.0"
15
+ gem "jeweler", "~> 2.0.1"
16
+ gem "simplecov", ">= 0"
17
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,97 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.3.6)
5
+ aruba (0.6.1)
6
+ childprocess (>= 0.3.6)
7
+ cucumber (>= 1.1.1)
8
+ rspec-expectations (>= 2.7.0)
9
+ builder (3.2.2)
10
+ childprocess (0.5.5)
11
+ ffi (~> 1.0, >= 1.0.11)
12
+ cucumber (1.3.17)
13
+ builder (>= 2.1.2)
14
+ diff-lcs (>= 1.1.3)
15
+ gherkin (~> 2.12)
16
+ multi_json (>= 1.7.5, < 2.0)
17
+ multi_test (>= 0.1.1)
18
+ descendants_tracker (0.0.4)
19
+ thread_safe (~> 0.3, >= 0.3.1)
20
+ diff-lcs (1.2.5)
21
+ docile (1.1.5)
22
+ faraday (0.9.0)
23
+ multipart-post (>= 1.2, < 3)
24
+ ffi (1.9.6)
25
+ gherkin (2.12.2)
26
+ multi_json (~> 1.3)
27
+ git (1.2.8)
28
+ github_api (0.12.2)
29
+ addressable (~> 2.3)
30
+ descendants_tracker (~> 0.0.4)
31
+ faraday (~> 0.8, < 0.10)
32
+ hashie (>= 3.3)
33
+ multi_json (>= 1.7.5, < 2.0)
34
+ nokogiri (~> 1.6.3)
35
+ oauth2
36
+ hashie (3.3.2)
37
+ highline (1.6.21)
38
+ jeweler (2.0.1)
39
+ builder
40
+ bundler (>= 1.0)
41
+ git (>= 1.2.5)
42
+ github_api
43
+ highline (>= 1.6.15)
44
+ nokogiri (>= 1.5.10)
45
+ rake
46
+ rdoc
47
+ json (1.8.1)
48
+ jwt (1.2.0)
49
+ mini_portile (0.6.1)
50
+ multi_json (1.10.1)
51
+ multi_test (0.1.1)
52
+ multi_xml (0.5.5)
53
+ multipart-post (2.0.0)
54
+ nokogiri (1.6.5)
55
+ mini_portile (~> 0.6.0)
56
+ oauth2 (1.0.0)
57
+ faraday (>= 0.8, < 0.10)
58
+ jwt (~> 1.0)
59
+ multi_json (~> 1.3)
60
+ multi_xml (~> 0.5)
61
+ rack (~> 1.2)
62
+ rack (1.6.0)
63
+ rake (10.4.2)
64
+ rdoc (3.12.2)
65
+ json (~> 1.4)
66
+ rspec (3.1.0)
67
+ rspec-core (~> 3.1.0)
68
+ rspec-expectations (~> 3.1.0)
69
+ rspec-mocks (~> 3.1.0)
70
+ rspec-core (3.1.7)
71
+ rspec-support (~> 3.1.0)
72
+ rspec-expectations (3.1.2)
73
+ diff-lcs (>= 1.2.0, < 2.0)
74
+ rspec-support (~> 3.1.0)
75
+ rspec-mocks (3.1.3)
76
+ rspec-support (~> 3.1.0)
77
+ rspec-support (3.1.2)
78
+ simplecov (0.9.1)
79
+ docile (~> 1.1.0)
80
+ multi_json (~> 1.0)
81
+ simplecov-html (~> 0.8.0)
82
+ simplecov-html (0.8.0)
83
+ thor (0.19.1)
84
+ thread_safe (0.3.4)
85
+
86
+ PLATFORMS
87
+ ruby
88
+
89
+ DEPENDENCIES
90
+ aruba (~> 0)
91
+ bundler (~> 1.0)
92
+ cucumber
93
+ jeweler (~> 2.0.1)
94
+ rdoc (~> 3.12)
95
+ rspec (~> 3.1.0)
96
+ simplecov
97
+ thor (~> 0)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Incredible Bee Ltd.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # locamotion
2
+
3
+ Locamotion is a helper tool for automating localizing RubyMotion apps using [SugarCube localized](https://github.com/rubymotion/sugarcube).
4
+
5
+ ## Installation
6
+ gem install locamotion
7
+
8
+ ## Usage
9
+
10
+ Locamotion has two commands to be run in any RubyMotion project folder:
11
+
12
+ ### locamotion slurp
13
+
14
+ With slurp, Locamotion will go through the _app_ directory of the RubyMotion project and find all localized strings. These are declared with Sugarcube as follows:
15
+
16
+ "I am a localized string"._
17
+
18
+ Locamotion will then look in the _resources/en.lproj/Localizable.strings_ file, create it if it doesn't exist, and then add the strings that are missing from it.
19
+
20
+ ### locamotion generate
21
+
22
+ With generate, Locamotion will go through the strings inside each localizable file in the English _resources/en.lproj_ localization folder, and place them in each available localization folder for another language, that is: _resources/<language_code>.lproj_.
23
+
24
+
25
+ ## Contributing to locamotion
26
+
27
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
28
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
29
+ * Fork the project.
30
+ * Start a feature/bugfix branch.
31
+ * Commit and push until you are happy with your contribution.
32
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
33
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
34
+
35
+ ## Copyright
36
+
37
+ Copyright (c) 2014 Incredible Bee Ltd. See LICENSE.txt for
38
+ further details.
39
+
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
17
+ gem.name = "locamotion"
18
+ gem.homepage = "http://github.com/incbee/locamotion"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{CLI tool to generate localizable files in RubyMotion projects}
21
+ gem.description = %Q{Locamotion (Localization Motion) is a Command Line tool to generate localizable files in RubyMotion projects. It parses the 'app' directory for SugarCube (https://github.com/rubymotion/sugarcube) strings, ending in '._'. It also transfers the english localized files into others.}
22
+ gem.email = "ramon.martin.huidobro@gmail.com"
23
+ gem.authors = ["Ramon Huidobro"]
24
+ gem.executables = ['locamotion']
25
+ gem.files.include %w(lib/**/*.rb)
26
+ # dependencies defined in Gemfile
27
+ end
28
+ Jeweler::RubygemsDotOrgTasks.new
29
+
30
+ require 'rspec/core'
31
+ require 'rspec/core/rake_task'
32
+ RSpec::Core::RakeTask.new(:spec) do |spec|
33
+ spec.pattern = FileList['spec/**/*_spec.rb']
34
+ end
35
+
36
+ desc "Code coverage detail"
37
+ task :simplecov do
38
+ ENV['COVERAGE'] = "true"
39
+ Rake::Task['spec'].execute
40
+ Rake::Task['features'].execute
41
+ end
42
+
43
+ require 'cucumber/rake/task'
44
+ Cucumber::Rake::Task.new(:features)
45
+
46
+ task :default => :spec
47
+
48
+ require 'rdoc/task'
49
+ Rake::RDocTask.new do |rdoc|
50
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
51
+
52
+ rdoc.rdoc_dir = 'rdoc'
53
+ rdoc.title = "locamotion #{version}"
54
+ rdoc.rdoc_files.include('README*')
55
+ rdoc.rdoc_files.include('lib/**/*.rb')
56
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/bin/locamotion ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'locamotion'
4
+
5
+ Locamotion::Runner.new(ARGV.dup).execute!
@@ -0,0 +1,137 @@
1
+ Feature: Locamotion generate
2
+ In order to automate localization in RubyMotion apps for languages other than English
3
+ As a user
4
+ I should be able to use locamotion to generate strings
5
+
6
+
7
+ Background:
8
+
9
+ In order to slurp and/or generate localization strings, users
10
+ should have a RubyMotion project with some ruby files.
11
+
12
+ Given a file named "rm-project/app/test.rb" with:
13
+ """
14
+ puts "I am localized!"._
15
+ string = "I am also localized."._
16
+ """
17
+ And a file named "rm-project/app/test2.rb" with:
18
+ """
19
+ value = 3
20
+ string = "I am localized with a value of #{value}."._
21
+ """
22
+ And a file named "rm-project/resources/en.lproj/Localizable.strings" with:
23
+ """
24
+ "I am localized!" = "I am localized!";
25
+ "I am also localized." = "I am also localized.";
26
+ "I am localized with a value of #{value}." = "I am localized with a value of #{value}.";
27
+ """
28
+ Given a directory named "rm-project/resources/es.lproj"
29
+ When I cd to "rm-project"
30
+
31
+
32
+ Scenario: Generate Spanish strings
33
+
34
+ Users can generate strings for other existing localizations
35
+ from the English ones using 'locamotion generate'
36
+
37
+ When I run `locamotion generate`
38
+ Then the output should contain "3 new strings"
39
+ And the file "resources/es.lproj/Localizable.strings" should contain:
40
+ """
41
+ "I am localized!" = "I am localized!";
42
+ "I am also localized." = "I am also localized.";
43
+ "I am localized with a value of #{value}." = "I am localized with a value of #{value}.";
44
+ """
45
+
46
+ Scenario: Generate Spanish and German strings
47
+
48
+ Users can generate strings for several existing localizations
49
+ from the English ones using 'locamotion generate'
50
+
51
+ Given a directory named "resources/de.lproj"
52
+ When I run `locamotion generate`
53
+ Then the output should contain "3 new strings entered into resources/de.lproj/Localizable.strings"
54
+ Then the output should contain "3 new strings entered into resources/es.lproj/Localizable.strings"
55
+ And the file "resources/es.lproj/Localizable.strings" should contain:
56
+ """
57
+ "I am localized!" = "I am localized!";
58
+ "I am also localized." = "I am also localized.";
59
+ "I am localized with a value of #{value}." = "I am localized with a value of #{value}.";
60
+ """
61
+ And the file "resources/de.lproj/Localizable.strings" should contain:
62
+ """
63
+ "I am localized!" = "I am localized!";
64
+ "I am also localized." = "I am also localized.";
65
+ "I am localized with a value of #{value}." = "I am localized with a value of #{value}.";
66
+ """
67
+
68
+ Scenario: Generate Spanish and German strings with some taken strings
69
+
70
+ Users can generate missing strings for several existing localizations
71
+ from the English ones using 'locamotion generate'
72
+
73
+ Given a directory named "resources/de.lproj"
74
+ Given a file named "resources/es.lproj/Localizable.strings" with:
75
+ """
76
+ "I am localized!" = "Tengo traduccion!";
77
+ "I am also localized." = "Yo tambien tengo traduccion.";
78
+ """
79
+ Given a file named "resources/de.lproj/Localizable.strings" with:
80
+ """
81
+ "I am also localized." = "Ich bin auch übersetzt.";
82
+ """
83
+ When I run `locamotion generate`
84
+ Then the output should contain "2 new strings entered into resources/de.lproj/Localizable.strings"
85
+ Then the output should contain "1 new string entered into resources/es.lproj/Localizable.strings"
86
+ And the file "resources/es.lproj/Localizable.strings" should contain:
87
+ """
88
+ "I am localized with a value of #{value}." = "I am localized with a value of #{value}.";
89
+ """
90
+ And the file "resources/de.lproj/Localizable.strings" should contain:
91
+ """
92
+ "I am localized!" = "I am localized!";
93
+ "I am localized with a value of #{value}." = "I am localized with a value of #{value}.";
94
+ """
95
+
96
+ Scenario: Generate Spanish and German strings with all taken strings
97
+
98
+ Users can attempt to generate strings for existing localizations,
99
+ even though these are all taken.
100
+
101
+ Given a directory named "resources/de.lproj"
102
+ Given a file named "resources/es.lproj/Localizable.strings" with:
103
+ """
104
+ "I am localized!" = "Tengo traduccion!";
105
+ "I am also localized." = "Yo tambien tengo traduccion.";
106
+ "I am localized with a value of #{value}." = "Tengo traduccion con el valor #{value}.";
107
+ """
108
+ Given a file named "resources/de.lproj/Localizable.strings" with:
109
+ """
110
+ "I am localized!" = "Ich bin übersetzt!";
111
+ "I am also localized." = "Ich bin auch übersetzt.";
112
+ "I am localized with a value of #{value}." = "Ich bin mit den wert #{value} übersetzt.";
113
+ """
114
+ When I run `locamotion generate`
115
+ Then the output should contain "No new strings added to resources/de.lproj/Localizable.strings"
116
+ Then the output should contain "No new strings added to resources/es.lproj/Localizable.strings"
117
+ And the file "resources/es.lproj/Localizable.strings" should contain:
118
+ """
119
+ "I am localized!" = "Tengo traduccion!";
120
+ "I am also localized." = "Yo tambien tengo traduccion.";
121
+ "I am localized with a value of #{value}." = "Tengo traduccion con el valor #{value}.";
122
+ """
123
+ And the file "resources/de.lproj/Localizable.strings" should contain:
124
+ """
125
+ "I am localized!" = "Ich bin übersetzt!";
126
+ "I am also localized." = "Ich bin auch übersetzt.";
127
+ "I am localized with a value of #{value}." = "Ich bin mit den wert #{value} übersetzt.";
128
+ """
129
+
130
+ Scenario: Attempt to run Locamotion where there's no RubyMotion project
131
+
132
+ Users should be informed that they're trying to run Locamotion outside
133
+ of a RubyMotion project, which won't work.
134
+
135
+ When I cd to "../"
136
+ And I run `locamotion generate`
137
+ Then the stderr should contain "Error: 'resources' folder not found. Are you running Locamotion in a RubyMotion project?"
@@ -0,0 +1,79 @@
1
+ Feature: Locamotion slurp
2
+ In order to automate English localization in RubyMotion apps
3
+ As a user
4
+ I should be able to use locamotion to slurp English strings
5
+
6
+
7
+ Background:
8
+
9
+ In order to slurp and/or generate localization strings, users
10
+ should have a RubyMotion project with some ruby files.
11
+
12
+ Given a file named "rm-project/app/test.rb" with:
13
+ """
14
+ puts "I am localized!"._
15
+ string = "I am also localized."._
16
+ """
17
+ And a file named "rm-project/app/test2.rb" with:
18
+ """
19
+ value = 3
20
+ string = "I am localized with a value of #{value}."._
21
+ """
22
+ When I cd to "rm-project"
23
+
24
+ Scenario: Slurp with english files
25
+
26
+ To slurp, the user has to call "locamotion slurp"
27
+
28
+ When I run `locamotion slurp`
29
+ Then the output should contain "3 new strings"
30
+ And the file "resources/en.lproj/Localizable.strings" should contain:
31
+ """
32
+ "I am localized!" = "I am localized!";
33
+ "I am also localized." = "I am also localized.";
34
+ "I am localized with a value of #{value}." = "I am localized with a value of #{value}.";
35
+ """
36
+
37
+ Scenario: Slurp with existing english files
38
+
39
+ Users can add missing strings to their english file.
40
+
41
+ Given a file named "resources/en.lproj/Localizable.strings" with:
42
+ """
43
+ "I am localized!" = "I am localized!";
44
+ """
45
+ When I run `locamotion slurp`
46
+ Then the output should contain "2 new strings"
47
+ And the file "resources/en.lproj/Localizable.strings" should contain:
48
+ """
49
+ "I am also localized." = "I am also localized.";
50
+ "I am localized with a value of #{value}." = "I am localized with a value of #{value}.";
51
+ """
52
+
53
+ Scenario: Slurp with all existing english strings
54
+
55
+ Locamotion should not add strings that already exist.
56
+
57
+ Given a file named "resources/en.lproj/Localizable.strings" with:
58
+ """
59
+ "I am localized!" = "I am localized!";
60
+ "I am also localized." = "I am also localized.";
61
+ "I am localized with a value of #{value}." = "I am localized with a value of #{value}.";
62
+ """
63
+ When I run `locamotion slurp`
64
+ Then the output should contain "No new strings"
65
+ And the file "resources/en.lproj/Localizable.strings" should contain:
66
+ """
67
+ "I am localized!" = "I am localized!";
68
+ "I am also localized." = "I am also localized.";
69
+ "I am localized with a value of #{value}." = "I am localized with a value of #{value}.";
70
+ """
71
+
72
+ Scenario: Attempt to run Locamotion where there's no RubyMotion project
73
+
74
+ Users should be informed that they're trying to run Locamotion outside
75
+ of a RubyMotion project, which won't work.
76
+
77
+ When I cd to "../"
78
+ And I run `locamotion slurp`
79
+ Then the stderr should contain "Error: 'app' folder not found. Are you running Locamotion in a RubyMotion project?"
File without changes
@@ -0,0 +1,33 @@
1
+ require 'simplecov'
2
+
3
+ module SimpleCov::Configuration
4
+ def clean_filters
5
+ @filters = []
6
+ end
7
+ end
8
+
9
+ SimpleCov.configure do
10
+ clean_filters
11
+ load_profile 'test_frameworks'
12
+ end
13
+
14
+ ENV["COVERAGE"] && SimpleCov.start do
15
+ add_filter "/.rvm/"
16
+ end
17
+ require 'bundler'
18
+ begin
19
+ Bundler.setup(:default, :development)
20
+ rescue Bundler::BundlerError => e
21
+ $stderr.puts e.message
22
+ $stderr.puts "Run `bundle install` to install missing gems"
23
+ exit e.status_code
24
+ end
25
+
26
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
27
+ require 'rspec/expectations'
28
+ require 'aruba/cucumber'
29
+ require 'aruba/in_process'
30
+ require 'locamotion/runner'
31
+
32
+ Aruba::InProcess.main_class = Locamotion::Runner
33
+ Aruba.process = Aruba::InProcess
data/lib/locamotion.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "locamotion/app"
2
+ require "locamotion/runner"
3
+
4
+ module Locamotion
5
+ end
@@ -0,0 +1,107 @@
1
+ require 'thor'
2
+
3
+ module Locamotion
4
+ class App < Thor
5
+ desc 'slurp', "Slurp the app's localized strings into the English localization"
6
+
7
+ def slurp
8
+ if File.exist? 'app'
9
+ slurp_main
10
+ else
11
+ abort "Error: 'app' folder not found. Are you running Locamotion in a RubyMotion project?"
12
+ end
13
+ end
14
+
15
+ desc 'generate', "Generate the other language's strings based on that of the english localization"
16
+
17
+ def generate
18
+ if File.exist? 'resources'
19
+ generate_main
20
+ else
21
+ abort "Error: 'resources' folder not found. Are you running Locamotion in a RubyMotion project?"
22
+ end
23
+ end
24
+
25
+ no_commands {
26
+ def slurp_main
27
+ matches = parse_rubymotion_app('app/**/*.rb')
28
+ FileUtils.mkdir_p('resources/en.lproj') unless File.exist?('resources/en.lproj')
29
+ localizable = 'resources/en.lproj/Localizable.strings'
30
+ system("touch #{localizable}")
31
+ strings_added_count = 0
32
+ matches.each do |string|
33
+ strings_added_count += 1 if add_missing_string(localizable, string)
34
+ end
35
+ puts announce_slurp_results(strings_added_count)
36
+ end
37
+
38
+ def generate_main
39
+ Dir.glob('resources/en.lproj/*.strings') do |strings_file|
40
+ Dir.glob('resources/*.lproj') do |folder|
41
+ next if folder == 'resources/en.lproj'
42
+ generate_strings_in_folder(folder, strings_file)
43
+ end
44
+ end
45
+ end
46
+
47
+ def generate_strings_in_folder(folder, strings_file)
48
+ strings_added_count = 0
49
+ localized_strings_file = File.join(folder, File.basename(strings_file))
50
+ system("touch #{localized_strings_file}")
51
+ File.open(strings_file).each do |line|
52
+ localizable_string_matcher = /(".*"\s*=\s*".*";)/
53
+ match = line[localizable_string_matcher, 1]
54
+ next unless match
55
+ string = match[/(".*")\s*=/, 1]
56
+ strings_added_count += 1 if add_missing_localized_string(localized_strings_file, string)
57
+ end
58
+ puts announce_generate_results(strings_added_count, localized_strings_file)
59
+ end
60
+
61
+ def parse_rubymotion_app(path)
62
+ matches = []
63
+ Dir.glob(path) do |ruby_file|
64
+ File.open(ruby_file).each do |line|
65
+ matches += line.scan(/"([^"]+)"\._/)
66
+ matches += line.scan(/'([^']+)'\._/)
67
+ end
68
+ end
69
+ matches.flatten
70
+ end
71
+
72
+ def add_missing_localized_string(file, string)
73
+ added = false
74
+ unless File.open(file).read =~ /#{Regexp.quote(string)}\s*=\s*".*";/
75
+ File.open(file, 'a+') { |f| f.write("#{string} = #{string};\n") }
76
+ added = true
77
+ end
78
+ added
79
+ end
80
+
81
+ def add_missing_string(file, string)
82
+ added = false
83
+ unless File.open(file).read =~ /"#{Regexp.quote(string)}"\s*=\s*"#{Regexp.quote(string)}";/
84
+ File.open(file, 'a+') { |f| f.write("\"#{string}\" = \"#{string}\";\n") }
85
+ added = true
86
+ end
87
+ added
88
+ end
89
+
90
+ def announce_slurp_results(strings_added_count)
91
+ if strings_added_count > 0
92
+ "#{strings_added_count} new string#{strings_added_count == 1 ? '' : 's'} entered into ./resources/en.lproj/Localizable.strings"
93
+ else
94
+ 'No new strings added.'
95
+ end
96
+ end
97
+
98
+ def announce_generate_results(strings_added_count, localized_strings_file)
99
+ if strings_added_count > 0
100
+ "#{strings_added_count} new string#{strings_added_count == 1 ? '' : 's'} entered into #{localized_strings_file}"
101
+ else
102
+ "No new strings added to #{localized_strings_file}."
103
+ end
104
+ end
105
+ }
106
+ end
107
+ end
@@ -0,0 +1,51 @@
1
+ require 'locamotion/app'
2
+
3
+ # Adapted from: https://github.com/erikhuda/thor/wiki/Integrating-with-Aruba-In-Process-Runs
4
+
5
+ module Locamotion
6
+ class Runner
7
+ # Allow everything fun to be injected from the outside while defaulting to normal implementations.
8
+ def initialize(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel)
9
+ @argv, @stdin, @stdout, @stderr, @kernel = argv, stdin, stdout, stderr, kernel
10
+ end
11
+
12
+ def execute!
13
+ exit_code = begin
14
+ # Thor accesses these streams directly rather than letting them be injected, so we replace them...
15
+ $stderr = @stderr
16
+ $stdin = @stdin
17
+ $stdout = @stdout
18
+
19
+ # Run our normal Thor app the way we know and love.
20
+ Locamotion::App.start(@argv)
21
+
22
+ # Thor::Base#start does not have a return value, assume success if no exception is raised.
23
+ 0
24
+ rescue StandardError => e
25
+ # The ruby interpreter would pipe this to STDERR and exit 1 in the case of an unhandled exception
26
+ b = e.backtrace
27
+ @stderr.puts("#{b.shift}: #{e.message} (#{e.class})")
28
+ @stderr.puts(b.map{|s| "\tfrom #{s}"}.join("\n"))
29
+ 1
30
+ rescue SystemExit => e
31
+ e.status
32
+ ensure
33
+ # TODO: reset your app here, free up resources, etc.
34
+ # Examples:
35
+ # MyApp.logger.flush
36
+ # MyApp.logger.close
37
+ # MyApp.logger = nil
38
+ #
39
+ # MyApp.reset_singleton_instance_variables
40
+
41
+ # ...then we put the streams back.
42
+ $stderr = STDERR
43
+ $stdin = STDIN
44
+ $stdout = STDOUT
45
+ end
46
+
47
+ # Proxy our exit code back to the injected kernel.
48
+ @kernel.exit(exit_code)
49
+ end
50
+ end
51
+ end
data/spec/app_spec.rb ADDED
@@ -0,0 +1,36 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Slurp" do
4
+ before do
5
+ FileUtils.rm_rf('/tmp/rm_project') if File.exist?('/tmp/rm_project')
6
+ FileUtils.mkdir_p('/tmp/rm_project/app')
7
+ content = <<-eos
8
+ "I am localized!"._
9
+ "I am also localized."._
10
+ eos
11
+ File.open('/tmp/rm_project/app/test1.rb', 'a+') { |f| f.write(content) }
12
+ File.open('/tmp/rm_project/app/test2.rb', 'a+') { |f| f.write("\"I am to be localized\"._") }
13
+ @app = Locamotion::App.new
14
+ end
15
+
16
+ after do
17
+ FileUtils.rm_rf('/tmp/rm_project')
18
+ end
19
+
20
+ it "gets all localizable strings" do
21
+ expect(@app.parse_rubymotion_app('/tmp/rm_project/app/**/*.rb')).to match_array(["I am localized!", "I am also localized.", "I am to be localized"])
22
+ end
23
+
24
+ it "announces 3 finished strings" do
25
+ expect(@app.announce_slurp_results(3)).to eq("3 new strings entered into ./resources/en.lproj/Localizable.strings")
26
+ end
27
+
28
+ it "announces 1 finished string" do
29
+ expect(@app.announce_slurp_results(1)).to eq("1 new string entered into ./resources/en.lproj/Localizable.strings")
30
+ end
31
+
32
+ it "announces no finished strings" do
33
+ expect(@app.announce_slurp_results(0)).to eq("No new strings added.")
34
+ end
35
+
36
+ end
@@ -0,0 +1,19 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "generate" do
4
+ before do
5
+ @app = Locamotion::App.new
6
+ end
7
+
8
+ it "announces 3 german strings" do
9
+ expect(@app.announce_generate_results(3, '/tmp/rm_project/resources/de.lproj/Localizable.strings')).to eq("3 new strings entered into /tmp/rm_project/resources/de.lproj/Localizable.strings")
10
+ end
11
+
12
+ it "announces 1 german strings" do
13
+ expect(@app.announce_generate_results(1, '/tmp/rm_project/resources/de.lproj/Localizable.strings')).to eq("1 new string entered into /tmp/rm_project/resources/de.lproj/Localizable.strings")
14
+ end
15
+
16
+ it "announces no german strings" do
17
+ expect(@app.announce_generate_results(0, '/tmp/rm_project/resources/de.lproj/Localizable.strings')).to eq("No new strings added to /tmp/rm_project/resources/de.lproj/Localizable.strings.")
18
+ end
19
+ end
@@ -0,0 +1,29 @@
1
+ require 'simplecov'
2
+
3
+ module SimpleCov::Configuration
4
+ def clean_filters
5
+ @filters = []
6
+ end
7
+ end
8
+
9
+ SimpleCov.configure do
10
+ clean_filters
11
+ load_profile 'test_frameworks'
12
+ end
13
+
14
+ ENV["COVERAGE"] && SimpleCov.start do
15
+ add_filter "/.rvm/"
16
+ end
17
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
18
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
19
+
20
+ require 'rspec'
21
+ require 'locamotion'
22
+
23
+ # Requires supporting files with custom matchers and macros, etc,
24
+ # in ./support/ and its subdirectories.
25
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
26
+
27
+ RSpec.configure do |config|
28
+
29
+ end
metadata ADDED
@@ -0,0 +1,179 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: locamotion
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ramon Huidobro
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: aruba
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.1.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.1.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rdoc
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.12'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.12'
69
+ - !ruby/object:Gem::Dependency
70
+ name: cucumber
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: jeweler
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 2.0.1
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 2.0.1
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Locamotion (Localization Motion) is a Command Line tool to generate localizable
126
+ files in RubyMotion projects. It parses the 'app' directory for SugarCube (https://github.com/rubymotion/sugarcube)
127
+ strings, ending in '._'. It also transfers the english localized files into others.
128
+ email: ramon.martin.huidobro@gmail.com
129
+ executables:
130
+ - locamotion
131
+ extensions: []
132
+ extra_rdoc_files:
133
+ - LICENSE.txt
134
+ - README.md
135
+ files:
136
+ - ".document"
137
+ - ".rspec"
138
+ - Gemfile
139
+ - Gemfile.lock
140
+ - LICENSE.txt
141
+ - README.md
142
+ - Rakefile
143
+ - VERSION
144
+ - bin/locamotion
145
+ - features/generate.feature
146
+ - features/slurp.feature
147
+ - features/step_definitions/locamotion_steps.rb
148
+ - features/support/env.rb
149
+ - lib/locamotion.rb
150
+ - lib/locamotion/app.rb
151
+ - lib/locamotion/runner.rb
152
+ - spec/app_spec.rb
153
+ - spec/generate_spec.rb
154
+ - spec/spec_helper.rb
155
+ homepage: http://github.com/incbee/locamotion
156
+ licenses:
157
+ - MIT
158
+ metadata: {}
159
+ post_install_message:
160
+ rdoc_options: []
161
+ require_paths:
162
+ - lib
163
+ required_ruby_version: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ required_rubygems_version: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ requirements: []
174
+ rubyforge_project:
175
+ rubygems_version: 2.2.2
176
+ signing_key:
177
+ specification_version: 4
178
+ summary: CLI tool to generate localizable files in RubyMotion projects
179
+ test_files: []