twine 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7eafefd496b0b0b32cdf00d9581ad752d089e2bf
4
- data.tar.gz: 610848a3c93b4e17276b619561029daadfb30d50
3
+ metadata.gz: 53375dd6df95fcacd2f758d20789d9b6ee7900d6
4
+ data.tar.gz: a294854a635e8eae127e0383fc4f8324466eb8a8
5
5
  SHA512:
6
- metadata.gz: d350f728eee0e6bebdb35d33cc935e4df7fa1f2ef83fd688bc2fdf9bc0eec91bb132db3e6d0f4ffee10db690b51c763ef720fc87ff0b09217ed535bce4d4382f
7
- data.tar.gz: d34c508686b8dda827b622f2742f947b05e0be859d75c0ca78ca6a8a69e0c57d5f447d4c6347a67e7bba3df5c89718c75f87dbf90427863173e4e53e498e3bd0
6
+ metadata.gz: ec63b938c4df50f488c0d00fd2c2d3f950b4f22fea88d2db0fa7c1e3db980543038bedefe9220ba1baf5c6d42df66164a782f4867e43c69373a0a7deda70d389
7
+ data.tar.gz: db626cb3482bafac41d2b2f213fa55e6bf55d8b4872978232f986d18e963c00524b19f69dc4dc7fe2491c6570ba0a612a8f8cfe177dcf9a95ce9363793e138cc
@@ -78,6 +78,10 @@ module Twine
78
78
  switch: ['-p', '--[no-]pedantic'],
79
79
  description: 'When validating a Twine file, perform additional checks that go beyond pure validity (like presence of tags).'
80
80
  },
81
+ quiet: {
82
+ switch: ['-q', '--[no-]quiet'],
83
+ description: 'Suppress all console output except error messages.'
84
+ },
81
85
  tags: {
82
86
  switch: ['-t', '--tags TAG1,TAG2,TAG3', Array],
83
87
  description: <<-DESC,
@@ -110,6 +114,7 @@ module Twine
110
114
  :format,
111
115
  :include,
112
116
  :languages,
117
+ :quiet,
113
118
  :tags,
114
119
  :untagged,
115
120
  :validate
@@ -131,6 +136,7 @@ module Twine
131
136
  :file_name,
132
137
  :format,
133
138
  :include,
139
+ :quiet,
134
140
  :tags,
135
141
  :untagged,
136
142
  :validate
@@ -147,6 +153,7 @@ module Twine
147
153
  :developer_language,
148
154
  :encoding,
149
155
  :include,
156
+ :quiet,
150
157
  :tags,
151
158
  :untagged,
152
159
  :validate
@@ -164,6 +171,7 @@ module Twine
164
171
  :format,
165
172
  :languages,
166
173
  :output_path,
174
+ :quiet,
167
175
  :tags
168
176
  ],
169
177
  option_validation: Proc.new { |options|
@@ -183,6 +191,7 @@ module Twine
183
191
  :encoding,
184
192
  :format,
185
193
  :output_path,
194
+ :quiet,
186
195
  :tags
187
196
  ],
188
197
  example: 'twine consume-all-localization-files twine.txt Resources/Locales/ --developer-language en --tags DefaultTag1,DefaultTag2'
@@ -197,6 +206,7 @@ module Twine
197
206
  :encoding,
198
207
  :format,
199
208
  :output_path,
209
+ :quiet,
200
210
  :tags
201
211
  ],
202
212
  example: 'twine consume-localization-archive twine.txt LocDrop5.zip'
@@ -206,7 +216,8 @@ module Twine
206
216
  arguments: [:twine_file],
207
217
  optional_options: [
208
218
  :developer_language,
209
- :pedantic
219
+ :pedantic,
220
+ :quiet
210
221
  ],
211
222
  example: 'twine validate-twine-file twine.txt'
212
223
  }
@@ -227,7 +238,7 @@ module Twine
227
238
 
228
239
  mapped_command = DEPRECATED_COMMAND_MAPPINGS[command]
229
240
  if mapped_command
230
- Twine::stderr.puts "WARNING: Twine commands names have changed. `#{command}` is now `#{mapped_command}`. The old command is deprecated and will soon stop working. For more information please check the documentation at https://github.com/mobiata/twine"
241
+ Twine::stdout.puts "WARNING: Twine commands names have changed. `#{command}` is now `#{mapped_command}`. The old command is deprecated and will soon stop working. For more information please check the documentation at https://github.com/mobiata/twine"
231
242
  command = mapped_command
232
243
  end
233
244
 
@@ -38,7 +38,7 @@ module Twine
38
38
  definition.translations[lang] = value
39
39
  end
40
40
  elsif @options[:consume_all]
41
- Twine::stderr.puts "Adding new definition '#{key}' to twine file."
41
+ Twine::stdout.puts "Adding new definition '#{key}' to twine file."
42
42
  current_section = @twine_file.sections.find { |s| s.name == 'Uncategorized' }
43
43
  unless current_section
44
44
  current_section = TwineSection.new('Uncategorized')
@@ -54,7 +54,7 @@ module Twine
54
54
  @twine_file.definitions_by_key[key] = current_definition
55
55
  @twine_file.definitions_by_key[key].translations[lang] = value
56
56
  else
57
- Twine::stderr.puts "Warning: '#{key}' not found in twine file."
57
+ Twine::stdout.puts "WARNING: '#{key}' not found in twine file."
58
58
  end
59
59
  if !@twine_file.language_codes.include?(lang)
60
60
  @twine_file.add_language_code(lang)
@@ -67,7 +67,8 @@ module Twine
67
67
 
68
68
  key = child.attributes['name']
69
69
 
70
- set_translation_for_key(key, lang, child.text)
70
+ content = child.children.map(&:to_s).join
71
+ set_translation_for_key(key, lang, content)
71
72
  set_comment_for_key(key, comment) if comment
72
73
 
73
74
  comment = nil
@@ -5,6 +5,14 @@ Twine::Plugin.new # Initialize plugins first in Runner.
5
5
 
6
6
  module Twine
7
7
  class Runner
8
+ class NullOutput
9
+ def puts(message)
10
+ end
11
+ def string
12
+ ""
13
+ end
14
+ end
15
+
8
16
  def self.run(args)
9
17
  options = CLI.parse(args)
10
18
 
@@ -35,6 +43,9 @@ module Twine
35
43
  def initialize(options = {}, twine_file = TwineFile.new)
36
44
  @options = options
37
45
  @twine_file = twine_file
46
+ if @options[:quite]
47
+ Twine::stdout = NullOutput.new
48
+ end
38
49
  end
39
50
 
40
51
  def write_twine_data(path)
@@ -90,7 +101,7 @@ module Twine
90
101
 
91
102
  output = formatter.format_file(lang)
92
103
  unless output
93
- Twine::stderr.puts "Skipping file at path #{file_path} since it would not contain any translations."
104
+ Twine::stdout.puts "Skipping file at path #{file_path} since it would not contain any translations."
94
105
  next
95
106
  end
96
107
 
@@ -112,7 +123,7 @@ module Twine
112
123
  file_path = File.join(output_path, file_name)
113
124
  output = formatter.format_file(lang)
114
125
  unless output
115
- Twine::stderr.puts "Skipping file at path #{file_path} since it would not contain any translations."
126
+ Twine::stdout.puts "Skipping file at path #{file_path} since it would not contain any translations."
116
127
  next
117
128
  end
118
129
 
@@ -148,7 +159,7 @@ module Twine
148
159
 
149
160
  output = formatter.format_file(lang)
150
161
  unless output
151
- Twine::stderr.puts "Skipping file #{file_name} since it would not contain any translations."
162
+ Twine::stdout.puts "Skipping file #{file_name} since it would not contain any translations."
152
163
  next
153
164
  end
154
165
 
@@ -197,6 +208,7 @@ module Twine
197
208
  raise Twine::Error.new("File does not exist: #{@options[:input_path]}")
198
209
  end
199
210
 
211
+ error_encountered = false
200
212
  Dir.mktmpdir do |temp_dir|
201
213
  Zip::File.open(@options[:input_path]) do |zipfile|
202
214
  zipfile.each do |entry|
@@ -209,6 +221,7 @@ module Twine
209
221
  read_localization_file(real_path)
210
222
  rescue Twine::Error => e
211
223
  Twine::stderr.puts "#{e.message}"
224
+ error_encountered = true
212
225
  end
213
226
  end
214
227
  end
@@ -216,6 +229,10 @@ module Twine
216
229
 
217
230
  output_path = @options[:output_path] || @options[:twine_file]
218
231
  write_twine_data(output_path)
232
+
233
+ if error_encountered
234
+ raise Twine::Error.new("At least one file could not be consumed")
235
+ end
219
236
  end
220
237
 
221
238
  def validate_twine_file
@@ -190,7 +190,7 @@ module Twine
190
190
 
191
191
  value = write_value(definition, dev_lang, f)
192
192
  if !value && !definition.reference_key
193
- puts "Warning: #{definition.key} does not exist in developer language '#{dev_lang}'"
193
+ Twine::stdout.puts "WARNING: #{definition.key} does not exist in developer language '#{dev_lang}'"
194
194
  end
195
195
 
196
196
  if definition.reference_key
@@ -1,3 +1,3 @@
1
1
  module Twine
2
- VERSION = '1.0.3'
2
+ VERSION = '1.0.4'
3
3
  end
@@ -82,6 +82,13 @@ class CLITest < TwineTest
82
82
  assert_equal @output_path, @options[:output_path]
83
83
  end
84
84
 
85
+ def assert_option_quiet
86
+ parse_with '--quiet'
87
+ assert @options[:quiet]
88
+ parse_with '--no-quiet'
89
+ refute @options[:quiet]
90
+ end
91
+
85
92
  def assert_option_tags
86
93
  # single tag
87
94
  random_tag = "tag#{rand(100)}"
@@ -174,6 +181,7 @@ class TestGenerateLocalizationFileCLI < CLITest
174
181
  assert_option_include
175
182
  assert_option_single_language
176
183
  assert_raises(Twine::Error) { assert_option_multiple_languages }
184
+ assert_option_quiet
177
185
  assert_option_tags
178
186
  assert_option_untagged
179
187
  assert_option_validate
@@ -211,6 +219,7 @@ class TestGenerateAllLocalizationFilesCLI < CLITest
211
219
  assert_option_encoding
212
220
  assert_option_format
213
221
  assert_option_include
222
+ assert_option_quiet
214
223
  assert_option_tags
215
224
  assert_option_untagged
216
225
  assert_option_validate
@@ -260,6 +269,7 @@ class TestGenerateLocalizationArchiveCLI < CLITest
260
269
  assert_option_developer_language
261
270
  assert_option_encoding
262
271
  assert_option_include
272
+ assert_option_quiet
263
273
  assert_option_tags
264
274
  assert_option_untagged
265
275
  assert_option_validate
@@ -278,7 +288,7 @@ class TestGenerateLocalizationArchiveCLI < CLITest
278
288
 
279
289
  def test_deprecated_command_prints_warning
280
290
  parse "generate-loc-drop #{@twine_file_path} #{@output_path} --format apple"
281
- assert_match "WARNING: Twine commands names have changed.", Twine::stderr.string
291
+ assert_match "WARNING: Twine commands names have changed.", Twine::stdout.string
282
292
  end
283
293
  end
284
294
 
@@ -317,6 +327,7 @@ class TestConsumeLocalizationFileCLI < CLITest
317
327
  assert_option_single_language
318
328
  assert_raises(Twine::Error) { assert_option_multiple_languages }
319
329
  assert_option_output_path
330
+ assert_option_quiet
320
331
  assert_option_tags
321
332
  end
322
333
  end
@@ -354,6 +365,7 @@ class TestConsumeAllLocalizationFilesCLI < CLITest
354
365
  assert_option_encoding
355
366
  assert_option_format
356
367
  assert_option_output_path
368
+ assert_option_quiet
357
369
  assert_option_tags
358
370
  end
359
371
  end
@@ -391,6 +403,7 @@ class TestConsumeLocalizationArchiveCLI < CLITest
391
403
  assert_option_encoding
392
404
  assert_option_format
393
405
  assert_option_output_path
406
+ assert_option_quiet
394
407
  assert_option_tags
395
408
  end
396
409
 
@@ -401,7 +414,7 @@ class TestConsumeLocalizationArchiveCLI < CLITest
401
414
 
402
415
  def test_deprecated_command_prints_warning
403
416
  parse "consume-loc-drop #{@twine_file_path} #{@input_path}"
404
- assert_match "WARNING: Twine commands names have changed.", Twine::stderr.string
417
+ assert_match "WARNING: Twine commands names have changed.", Twine::stdout.string
405
418
  end
406
419
  end
407
420
 
@@ -432,6 +445,7 @@ class TestValidateTwineFileCLI < CLITest
432
445
  def test_options
433
446
  assert_help
434
447
  assert_option_developer_language
448
+ assert_option_quiet
435
449
  end
436
450
 
437
451
  def test_option_pedantic
@@ -4,24 +4,30 @@ class TestConsumeLocalizationArchive < CommandTest
4
4
  def setup
5
5
  super
6
6
 
7
- options = {}
8
- options[:input_path] = fixture_path 'consume_localization_archive.zip'
9
- options[:output_path] = @output_path
10
- options[:format] = 'apple'
11
-
12
7
  @twine_file = build_twine_file 'en', 'es' do
13
8
  add_section 'Section' do
14
9
  add_definition key1: 'value1'
15
10
  end
16
11
  end
12
+ end
13
+
14
+ def new_runner(options = {})
15
+ options[:input_path] = fixture_path 'consume_localization_archive.zip'
16
+ options[:output_path] = @output_path
17
17
 
18
- @runner = Twine::Runner.new(options, @twine_file)
18
+ Twine::Runner.new(options, @twine_file)
19
19
  end
20
20
 
21
21
  def test_consumes_zip_file
22
- @runner.consume_localization_archive
22
+ new_runner(format: 'android').consume_localization_archive
23
23
 
24
24
  assert @twine_file.definitions_by_key['key1'].translations['en'], 'value1-english'
25
25
  assert @twine_file.definitions_by_key['key1'].translations['es'], 'value1-spanish'
26
26
  end
27
+
28
+ def test_raises_error_if_format_ambiguous
29
+ assert_raises Twine::Error do
30
+ new_runner.consume_localization_archive
31
+ end
32
+ end
27
33
  end
@@ -101,6 +101,21 @@ class TestAndroidFormatter < FormatterTest
101
101
  assert_equal 'This is\n a string', @empty_twine_file.definitions_by_key["foo"].translations['en']
102
102
  end
103
103
 
104
+ def test_read_html_tags
105
+ content = <<-EOCONTENT
106
+ <?xml version="1.0" encoding="utf-8"?>
107
+ <resources>
108
+ <string name="foo">Hello, <b>BOLD</b></string>
109
+ </resources>
110
+ EOCONTENT
111
+
112
+ io = StringIO.new(content)
113
+
114
+ @formatter.read io, 'en'
115
+
116
+ assert_equal 'Hello, <b>BOLD</b>', @empty_twine_file.definitions_by_key["foo"].translations['en']
117
+ end
118
+
104
119
  def test_set_translation_converts_leading_spaces
105
120
  @formatter.set_translation_for_key 'key1', 'en', "\u0020value"
106
121
  assert_equal ' value', @empty_twine_file.definitions_by_key['key1'].translations['en']
@@ -47,8 +47,8 @@ class TestGenerateAllLocalizationFiles < CommandTest
47
47
  end
48
48
 
49
49
  class TestDoNotCreateFolders < TestGenerateAllLocalizationFiles
50
- def new_runner(twine_file = nil)
51
- super(false, twine_file)
50
+ def new_runner(twine_file = nil, options = {})
51
+ super(false, twine_file, options)
52
52
  end
53
53
 
54
54
  def test_fails_if_output_folder_does_not_exist
@@ -67,13 +67,20 @@ class TestGenerateAllLocalizationFiles < CommandTest
67
67
  Dir.mkdir File.join @output_dir, 'en.lproj'
68
68
  empty_twine_file = build_twine_file('en') {}
69
69
  new_runner(empty_twine_file).generate_all_localization_files
70
- assert_match "Skipping file at path", Twine::stderr.string
70
+ assert_match "Skipping file at path", Twine::stdout.string
71
+ end
72
+
73
+ def test_does_not_print_empty_file_warnings_if_quite
74
+ Dir.mkdir File.join @output_dir, 'en.lproj'
75
+ empty_twine_file = build_twine_file('en') {}
76
+ new_runner(empty_twine_file, quite: true).generate_all_localization_files
77
+ refute_match "Skipping file at path", Twine::stdout.string
71
78
  end
72
79
  end
73
80
 
74
81
  class TestCreateFolders < TestGenerateAllLocalizationFiles
75
- def new_runner(twine_file = nil)
76
- super(true, twine_file)
82
+ def new_runner(twine_file = nil, options = {})
83
+ super(true, twine_file, options)
77
84
  end
78
85
 
79
86
  def test_creates_output_folder
@@ -92,7 +99,14 @@ class TestGenerateAllLocalizationFiles < CommandTest
92
99
  empty_twine_file = build_twine_file('en') {}
93
100
  new_runner(empty_twine_file).generate_all_localization_files
94
101
 
95
- assert_match "Skipping file at path", Twine::stderr.string
102
+ assert_match "Skipping file at path", Twine::stdout.string
103
+ end
104
+
105
+ def test_does_not_print_empty_file_warnings_if_quite
106
+ empty_twine_file = build_twine_file('en') {}
107
+ new_runner(empty_twine_file, quite: true).generate_all_localization_files
108
+
109
+ refute_match "Skipping file at path", Twine::stdout.string
96
110
  end
97
111
  end
98
112
 
@@ -1,8 +1,7 @@
1
1
  require 'command_test'
2
2
 
3
3
  class TestGenerateLocalizationArchive < CommandTest
4
- def new_runner(twine_file = nil)
5
- options = {}
4
+ def new_runner(twine_file = nil, options = {})
6
5
  options[:output_path] = @output_path
7
6
  options[:format] = 'apple'
8
7
 
@@ -45,7 +44,13 @@ class TestGenerateLocalizationArchive < CommandTest
45
44
  def test_prints_empty_file_warnings
46
45
  empty_twine_file = build_twine_file('en') {}
47
46
  new_runner(empty_twine_file).generate_localization_archive
48
- assert_match "Skipping file", Twine::stderr.string
47
+ assert_match "Skipping file", Twine::stdout.string
48
+ end
49
+
50
+ def test_does_not_print_empty_file_warnings_if_quite
51
+ empty_twine_file = build_twine_file('en') {}
52
+ new_runner(empty_twine_file, quite: true).generate_localization_archive
53
+ refute_match "Skipping file", Twine::stdout.string
49
54
  end
50
55
 
51
56
  class TestValidate < CommandTest
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twine
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Celis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-26 00:00:00.000000000 Z
11
+ date: 2018-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip