phrase 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/phrase/tool.rb +50 -26
  2. data/phrase.gemspec +1 -1
  3. metadata +2 -2
data/lib/phrase/tool.rb CHANGED
@@ -53,24 +53,23 @@ module PhraseGem
53
53
  puts "No config present. Please initialize phrase before pushing or pulling."
54
54
  exit(43)
55
55
  end
56
-
57
- files.each do |file|
58
- if file.split('.').last != 'yml'
59
- $stderr.puts "Currently only .yml files are supported."
60
- exit(43)
61
- end
62
- end
63
-
56
+
64
57
  upload_files(files, config)
65
58
  end
66
59
 
67
60
  def choose_files_to_upload
68
61
  file_name = args[1]
62
+
69
63
  unless file_name
70
- $stderr.puts "Need either a file or directory:"
71
- $stderr.puts " phrase push FILE"
72
- $stderr.puts " phrase push DIRECTORY"
73
- exit(46)
64
+ if self.class.rails_default_locale_folder_is_available
65
+ file_name = self.class.rails_default_locale_folder
66
+ puts "No file or directory specified, using #{self.class.rails_default_locale_folder}"
67
+ else
68
+ $stderr.puts "Need either a file or directory:"
69
+ $stderr.puts " phrase push FILE"
70
+ $stderr.puts " phrase push DIRECTORY"
71
+ exit(46)
72
+ end
74
73
  end
75
74
 
76
75
  unless File.exist?(file_name)
@@ -87,22 +86,35 @@ module PhraseGem
87
86
 
88
87
  def upload_files(files, config)
89
88
  files.each do |file|
90
- puts "Uploading #{file}..."
91
- params = {
92
- 'auth_token'=>config.secret,
93
- 'filename'=> file,
94
- 'file_content' => File.read(file)
95
- }
89
+ proceed_with_upload = true
96
90
 
97
- http = http_client(config)
91
+ if File.directory?(file)
92
+ proceed_with_upload = false
93
+ end
98
94
 
99
- request = Net::HTTP::Post.new("#{config.api_path_prefix}/translation_keys/upload")
100
- request.set_form_data(params)
101
- res = http.request(request)
102
-
103
- dump_summary_to_file(res, file)
104
- unless res.code.to_s =~ /^[23]/
105
- print_server_error(res, file)
95
+ if is_yaml_file(file)
96
+ proceed_with_upload = false
97
+ $stderr.puts "Error: Could not upload #{file} (extension not supported)"
98
+ end
99
+
100
+ if proceed_with_upload
101
+ puts "Uploading #{file}..."
102
+ params = {
103
+ 'auth_token'=>config.secret,
104
+ 'filename'=> file,
105
+ 'file_content' => File.read(file)
106
+ }
107
+
108
+ http = http_client(config)
109
+
110
+ request = Net::HTTP::Post.new("#{config.api_path_prefix}/translation_keys/upload")
111
+ request.set_form_data(params)
112
+ res = http.request(request)
113
+
114
+ dump_summary_to_file(res, file)
115
+ unless res.code.to_s =~ /^[23]/
116
+ print_server_error(res, file)
117
+ end
106
118
  end
107
119
  end
108
120
  end
@@ -180,5 +192,17 @@ USAGE
180
192
  http.ca_file = File.join(File.dirname(__FILE__), "..", "..", "cacert.pem")
181
193
  http
182
194
  end
195
+
196
+ def is_yaml_file(filepath)
197
+ !File.directory?(filepath) && filepath.split('.').last != 'yml'
198
+ end
199
+
200
+ def self.rails_default_locale_folder
201
+ "./config/locales/"
202
+ end
203
+
204
+ def self.rails_default_locale_folder_is_available
205
+ File.exist?(rails_default_locale_folder) && File.directory?(rails_default_locale_folder)
206
+ end
183
207
  end
184
208
  end
data/phrase.gemspec CHANGED
@@ -4,7 +4,7 @@ $:.unshift lib unless $:.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "phrase"
7
- s.version = "0.0.2"
7
+ s.version = "0.0.3"
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Dynport GmbH"]
10
10
  s.email = ["info@phraseapp.com"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phrase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-14 00:00:00.000000000Z
12
+ date: 2012-03-16 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: The best way to manage i18n.
15
15
  email: