localeapp 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # HEAD
2
+
3
+ * Add --standalone option to install to generate a .localeapp/ config
4
+ directory. This enables usage outside of rails.
5
+
1
6
  # Version 0.4.0
2
7
 
3
8
  * Use Psych to generate the yaml if it's available (This will completely change
data/README.md CHANGED
@@ -39,6 +39,14 @@ Install the gem:
39
39
  Create a project on localeapp.com and get the api key. Then run:
40
40
 
41
41
  localeapp install <YOUR_API_KEY>
42
+
43
+ ### Non rails projects
44
+
45
+ Install the gem and run:
46
+
47
+ localeapp install --standalone <YOUR_API_KEY>
48
+
49
+ This will create a `.localeapp` directory for your configuration files.
42
50
 
43
51
  ## Importing existing content
44
52
 
@@ -137,7 +145,7 @@ You can also add a new locale to a project via localeapp.com. This will create
137
145
  missing translations for every translation key. You will need to restart any
138
146
  listeners completely to pick up the new locale.
139
147
 
140
- ## Syck, Psych, and creating YAML
148
+ ### Syck, Psych, and creating YAML
141
149
 
142
150
  Since ruby 1.9.3-p0 Psych has been the default YAML engine in Ruby. Psych is
143
151
  based on libyaml and fixes a number of issues with the previous YAML library,
data/bin/localeapp CHANGED
@@ -14,8 +14,8 @@ if ENV['FAKE_WEB_DURING_CUCUMBER_RUN'] && fake_data_as_json = ENV['FAKE_WEB_FAKE
14
14
  end
15
15
  end
16
16
 
17
- def include_config_file
18
- unless Localeapp.include_config_file
17
+ def initialize_config
18
+ unless Localeapp.initialize_config
19
19
  puts "Could not load config file"
20
20
  exit 1
21
21
  end
@@ -29,9 +29,13 @@ version Localeapp::VERSION
29
29
  desc "Creates new configuration files and confirms key works"
30
30
  arg_name "<api_key>"
31
31
  command :install do |c|
32
+ c.desc "install configuration files in .localeapp/"
33
+ c.switch [:s, 'standalone']
34
+
32
35
  c.action do |global_options, options, args|
33
36
  key = args.first
34
37
  installer = Localeapp::CLI::Install.new
38
+ installer.config_type = options[:standalone] ? :standalone : :rails
35
39
  unless installer.execute(key)
36
40
  exit_now! "", 1
37
41
  end
@@ -46,7 +50,7 @@ command :add do |c|
46
50
  if key.nil? || args.size.zero?
47
51
  exit_now! "localeapp add requires a key name and at least one translation", 1
48
52
  else
49
- include_config_file
53
+ initialize_config
50
54
  Localeapp::CLI::Add.new.execute(key, *args)
51
55
  end
52
56
  end
@@ -55,7 +59,7 @@ end
55
59
  desc "Pulls all translations from localeapp.com"
56
60
  command :pull do |c|
57
61
  c.action do |global_options, options, args|
58
- include_config_file
62
+ initialize_config
59
63
  Localeapp::CLI::Pull.new.execute
60
64
  end
61
65
  end
@@ -67,8 +71,8 @@ command :push do |c|
67
71
  if args.empty?
68
72
  exit_now! "localeapp push requires an file or directory to push", 1
69
73
  else
70
- include_config_file
71
74
  path = args.first
75
+ initialize_config
72
76
  pusher = Localeapp::CLI::Push.new
73
77
  pusher.execute(path)
74
78
  end
@@ -78,7 +82,7 @@ end
78
82
  desc "Gets any changes since the last poll and updates the yml"
79
83
  command :update do |c|
80
84
  c.action do |global_options, options, args|
81
- include_config_file
85
+ initialize_config
82
86
  Localeapp::CLI::Update.new.execute
83
87
  end
84
88
  end
@@ -94,7 +98,7 @@ command :daemon do |c|
94
98
  c.switch [:b, 'background']
95
99
 
96
100
  c.action do |global_options, options, args|
97
- include_config_file
101
+ initialize_config
98
102
 
99
103
  interval = options[:interval].to_i
100
104
 
@@ -16,7 +16,7 @@ Feature: localeapp executable
16
16
  error: Unknown command 'foo'. Use 'localeapp help' for a list of commands
17
17
  """
18
18
 
19
- Scenario: Running install
19
+ Scenario: Running Rails install
20
20
  In order to configure my project and check my api key is correct
21
21
  When I have a valid project on localeapp.com with api key "MYAPIKEY"
22
22
  And I run `localeapp install MYAPIKEY`
@@ -33,6 +33,24 @@ Feature: localeapp executable
33
33
  And a file named "config/initializers/localeapp.rb" should exist
34
34
  And the exit status should be 0
35
35
 
36
+ Scenario: Running standalone install
37
+ In order to configure my non rails project and check my api key is correct
38
+ When I have a valid project on localeapp.com with api key "MYAPIKEY"
39
+ And I run `localeapp install --standalone MYAPIKEY`
40
+ Then the output should contain:
41
+ """
42
+ Localeapp Install
43
+
44
+ Checking API key: MYAPIKEY
45
+ Success!
46
+ Project: Test Project
47
+ Default Locale: en (English)
48
+ """
49
+ And help should not be displayed
50
+ And a file named ".localeapp/config.rb" should exist
51
+ And the exit status should be 0
52
+
53
+
36
54
  Scenario: Running install with bad api key
37
55
  In order to configure my project and check my api key is correct
38
56
  When I have a valid project on localeapp.com but an incorrect api key "BADAPIKEY"
data/lib/localeapp.rb CHANGED
@@ -95,14 +95,20 @@ module Localeapp
95
95
  end
96
96
 
97
97
  # requires the Localeapp configuration
98
- def include_config_file(file_path=nil)
99
- file_path ||= File.join(Dir.pwd, 'config', 'initializers', 'localeapp')
100
- begin
101
- require file_path
102
- true
103
- rescue
104
- false
98
+ def initialize_config(file_path=nil)
99
+ file_paths = [ File.join(Dir.pwd, '.localeapp', 'config.rb'),
100
+ File.join(Dir.pwd, 'config', 'initializers', 'localeapp.rb') ]
101
+ file_paths << file_path if file_path
102
+ file_paths.each do |path|
103
+ next unless File.exists? path
104
+ begin
105
+ require path
106
+ return true
107
+ rescue
108
+ end
105
109
  end
110
+ false
106
111
  end
112
+
107
113
  end
108
114
  end
@@ -1,6 +1,12 @@
1
1
  module Localeapp
2
2
  module CLI
3
3
  class Install
4
+ attr_accessor :config_type
5
+
6
+ def initialize
7
+ @config_type = :rails
8
+ end
9
+
4
10
  def execute(key, output = $stdout)
5
11
  output.puts "Localeapp Install"
6
12
  output.puts ""
@@ -15,12 +21,24 @@ module Localeapp
15
21
  output.puts "Project: #{project_data['name']}"
16
22
  localeapp_default_code = project_data['default_locale']['code']
17
23
  output.puts "Default Locale: #{localeapp_default_code} (#{project_data['default_locale']['name']})"
18
- if I18n.default_locale.to_s != localeapp_default_code
19
- output.puts "WARNING: I18n.default_locale is #{I18n.default_locale}, change in config/environment.rb (Rails 2) or config/application.rb (Rails 3)"
24
+
25
+ if config_type == :rails
26
+ if I18n.default_locale.to_s != localeapp_default_code
27
+ output.puts "WARNING: I18n.default_locale is #{I18n.default_locale}, change in config/environment.rb (Rails 2) or config/application.rb (Rails 3)"
28
+ end
29
+ config_file_path = "config/initializers/localeapp.rb"
30
+ data_directory = "config/locales"
31
+ else
32
+ output.puts "NOTICE: you probably want to add .localeapp to your .gitignore file"
33
+ config_file_path = ".localeapp/config.rb"
34
+ data_directory = "locales"
20
35
  end
21
- config_file_path = "config/initializers/localeapp.rb"
22
36
  output.puts "Writing configuration file to #{config_file_path}"
23
37
  write_configuration_file config_file_path
38
+
39
+ unless File.directory?(data_directory)
40
+ output.puts "WARNING: please create the #{data_directory} directory. Your translation data will be stored there."
41
+ end
24
42
  true
25
43
  else
26
44
  output.puts "ERROR: Project not found"
@@ -34,7 +52,11 @@ module Localeapp
34
52
  end
35
53
 
36
54
  def write_configuration_file(path)
37
- Localeapp.configuration.write_initial(path)
55
+ if config_type == :rails
56
+ Localeapp.configuration.write_rails_configuration(path)
57
+ else
58
+ Localeapp.configuration.write_standalone_configuration(path)
59
+ end
38
60
  end
39
61
  end
40
62
  end
@@ -146,7 +146,7 @@ module Localeapp
146
146
  end
147
147
  end
148
148
 
149
- def write_initial(path)
149
+ def write_rails_configuration(path)
150
150
  dir = File.dirname(path)
151
151
  FileUtils.mkdir_p(dir)
152
152
  File.open(path, 'w+') do |file|
@@ -159,5 +159,21 @@ end
159
159
  CONTENT
160
160
  end
161
161
  end
162
+
163
+ def write_standalone_configuration(path)
164
+ dir = File.dirname(path)
165
+ FileUtils.mkdir_p(dir)
166
+ File.open(path, 'w+') do |file|
167
+ file.write <<-CONTENT
168
+ Localeapp.configure do |config|
169
+ config.api_key = '#{@api_key}'
170
+ config.translation_data_directory = 'locales'
171
+ config.synchronization_data_file = '.localeapp/log.yml'
172
+ config.daemon_pid_file = '.localeapp/localeapp.pid'
173
+ end
174
+ CONTENT
175
+ end
176
+ end
177
+
162
178
  end
163
179
  end
@@ -1,3 +1,3 @@
1
1
  module Localeapp
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -39,4 +39,26 @@ describe Localeapp::CLI::Install, '.execute(key, output = $stdout)' do
39
39
  @command.should_receive(:write_configuration_file).with('config/initializers/localeapp.rb')
40
40
  @command.execute('API_KEY', @output)
41
41
  end
42
+
43
+ it "asks the configuration to write itself to .localeapp when the --standalone switch is set" do
44
+ @command.stub!(:check_key).and_return([true, valid_project_data])
45
+ @command.config_type = :standalone
46
+ @command.should_receive(:write_configuration_file).with('.localeapp/config.rb')
47
+ @command.execute('API_KEY', @output)
48
+ end
49
+
50
+ it "displays warning if config.translation_data_directory doesn't exist" do
51
+ @command.stub!(:check_key).and_return([true, valid_project_data])
52
+ @command.stub!(:write_configuration_file)
53
+ @command.execute('API_KEY', @output)
54
+ @output.string.should match(/Your translation data will be stored there./)
55
+ end
56
+
57
+ it "doesn't display a warning if translation_data_directory exists" do
58
+ @command.stub!(:check_key).and_return([true, valid_project_data])
59
+ @command.stub!(:write_configuration_file)
60
+ File.should_receive(:directory?).and_return(true)
61
+ @command.execute('API_KEY', @output)
62
+ @output.string.should_not match(/Your translation data will be stored there./)
63
+ end
42
64
  end
@@ -303,7 +303,7 @@ describe Localeapp::Configuration do
303
303
  end
304
304
  end
305
305
 
306
- describe Localeapp::Configuration, "#write_initial(path)" do
306
+ describe Localeapp::Configuration, "#write_rails_configuration(path)" do
307
307
  it "creates a configuration file containing just the api key at the given path" do
308
308
  configuration = Localeapp::Configuration.new
309
309
  configuration.api_key = "APIKEY"
@@ -317,6 +317,26 @@ Localeapp.configure do |config|
317
317
  end
318
318
  CONTENT
319
319
  File.should_receive(:open).with(path, 'w+').and_yield(file)
320
- configuration.write_initial(path)
320
+ configuration.write_rails_configuration(path)
321
+ end
322
+ end
323
+
324
+
325
+ describe Localeapp::Configuration, "#write_standalone_configuration(path)" do
326
+ it "creates a configuration file containing the dot file configuration at the given path" do
327
+ configuration = Localeapp::Configuration.new
328
+ configuration.api_key = "APIKEY"
329
+ path = 'test_path'
330
+ file = stub('file')
331
+ file.should_receive(:write).with <<-CONTENT
332
+ Localeapp.configure do |config|
333
+ config.api_key = 'APIKEY'
334
+ config.translation_data_directory = 'locales'
335
+ config.synchronization_data_file = '.localeapp/log.yml'
336
+ config.daemon_pid_file = '.localeapp/localeapp.pid'
337
+ end
338
+ CONTENT
339
+ File.should_receive(:open).with(path, 'w+').and_yield(file)
340
+ configuration.write_standalone_configuration(path)
321
341
  end
322
342
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: localeapp
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 0
10
- version: 0.4.0
9
+ - 1
10
+ version: 0.4.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Christopher Dell
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2012-02-21 00:00:00 Z
19
+ date: 2012-03-02 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: i18n
@@ -288,7 +288,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
288
288
  requirements: []
289
289
 
290
290
  rubyforge_project: localeapp
291
- rubygems_version: 1.8.15
291
+ rubygems_version: 1.8.6
292
292
  signing_key:
293
293
  specification_version: 3
294
294
  summary: Easy i18n translation management with localeapp.com