bruno 0.0.2 → 0.0.3

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
- SHA1:
3
- metadata.gz: b5d6cfae46b2ac02726fbd6ac66c9b79d5527011
4
- data.tar.gz: d05f086e46249d0b8ee33d084b7f83b0a4ef30bb
2
+ SHA256:
3
+ metadata.gz: 94569696331e1bbe5c72e3eae5754ed38a5c85fce3c6a1146728fd11cff97d11
4
+ data.tar.gz: '081f36a280059288d2eaebeb0bb251f96fd209c49cb6fe7c1932984c4c612fac'
5
5
  SHA512:
6
- metadata.gz: 6173d509f006861e0ea898fb1bf7e5bd074c8d46a2290858c2d2e43639e4c1f334122f7244b58d644b2dfb80f5716d1ce283a7fdf1c0fcdcbc6f5f2a60782c23
7
- data.tar.gz: 5d2b4b0a6bca51cd7462c7eeb9c96a1c90eebfad7894cbff52a432c73f2f3e91f5ed1a226e6a387cf1a77d24f95ad057a663912ca4286dacf9d6e5b11681d535
6
+ metadata.gz: 440cf0fb11cf40d24c754bb374e997eee9998ba7de9f522d54da30b7a75b5cdf6b1caaf217825c9a4ea885918a51ea96fa02244c615a985e7d366ab17b06cb1a
7
+ data.tar.gz: fbf6b4ea99516e01f11996e0e15eb53b8c3aecbd29ed71f80e4cd031ca8bd33f8fb8c97e16d5be940453fb0559e877d130038882940cc2de276e8a31dba12696
data/bin/bruno CHANGED
@@ -22,11 +22,8 @@ command :convert do |c|
22
22
  raise 'You must provide an input file' if options[:in].nil?
23
23
  raise 'You must provide an output file' if options[:out].nil?
24
24
 
25
- # If you have any errors, just raise them
26
- #raise "that command made no sense"
25
+ Bruno::Converter.convert(options[:in], options[:out])
27
26
 
28
- strings_file = Bruno::StringsFile.new(options[:in])
29
- strings_file.transform(options[:out])
30
27
  puts "convert command ran"
31
28
  end
32
29
  end
@@ -0,0 +1,30 @@
1
+ require 'nokogiri'
2
+
3
+ class Bruno::AndroidFile < Bruno::I18nFile
4
+ def self.is_android?(content)
5
+ !(content =~ /<string name=".*">.*<\/string>/).nil?
6
+ end
7
+
8
+ def self.read(content)
9
+ strings = []
10
+ xml = Nokogiri::XML(content)
11
+ xml.root.xpath('string').each do |string|
12
+ strings << {:key => string.attribute('name').value, :value => string.content}
13
+ end
14
+
15
+ strings
16
+ end
17
+
18
+ def write(path)
19
+ file = File.new(path, 'w+')
20
+ builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
21
+ xml.resources {
22
+ @strings.each do |string|
23
+ xml.string({:name => string[:key]}) { xml.text string[:value] }
24
+ end
25
+ }
26
+ end
27
+ file.write(builder.to_xml)
28
+ file.close
29
+ end
30
+ end
@@ -0,0 +1,7 @@
1
+ module Bruno
2
+ class Converter
3
+ def self.convert(in_path, out_path)
4
+ I18nFile.read(in_path).write(out_path)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,25 @@
1
+ module Bruno
2
+ class I18nFile
3
+ attr_writer :strings
4
+
5
+ def initialize(strings)
6
+ @strings = strings
7
+ end
8
+
9
+ def self.read(path)
10
+ if File.readable?(path)
11
+ content = File.read(path)
12
+
13
+ if IOSFile.is_ios?(content)
14
+ return AndroidFile.new(IOSFile.read(content))
15
+ elsif AndroidFile.is_android?(content)
16
+ return IOSFile.new(AndroidFile.read(content))
17
+ else
18
+ raise 'Format of the file is not correct'
19
+ end
20
+ else
21
+ raise 'File is not readable'
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,34 @@
1
+ class Bruno::IOSFile < Bruno::I18nFile
2
+ def self.is_ios?(content)
3
+ !(content =~ /".*" = ".*";/).nil?
4
+ end
5
+
6
+ def self.read(content)
7
+ strings = []
8
+ content.each_line do |line|
9
+ match_key = line.match(/\"([^\"]+)\"/)
10
+ match_value = line.match(/= \"([^\"]+)\";/) #"
11
+ strings << {:key => match_key[1], :value => match_value[1]}
12
+ end
13
+ strings
14
+ end
15
+
16
+ def write(path)
17
+ file = File.new(path,'w+')
18
+
19
+ @strings.each_with_index do |string, index|
20
+ file.write(compose_line(string[:key], string[:value]))
21
+
22
+ if index != @strings.length - 1
23
+ file.write("\n")
24
+ end
25
+ end
26
+ file.close
27
+ end
28
+
29
+
30
+ private
31
+ def compose_line(key, value)
32
+ '"' + key + '" = "' + value + '";'
33
+ end
34
+ end
data/lib/bruno/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Bruno
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
data/lib/bruno.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'bruno/version'
2
- require 'bruno/strings_file'
3
-
4
- # Add requires for other files you add to your project here, so
5
- # you just need to require this one file in your bin file
2
+ require 'bruno/i18n_file'
3
+ require 'bruno/android_file'
4
+ require 'bruno/ios_file'
5
+ require 'bruno/converter'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bruno
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - José M. Gilgado
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-02 00:00:00.000000000 Z
11
+ date: 2018-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -70,14 +70,14 @@ dependencies:
70
70
  requirements:
71
71
  - - '='
72
72
  - !ruby/object:Gem::Version
73
- version: 1.5.9
73
+ version: 1.8.4
74
74
  type: :runtime
75
75
  prerelease: false
76
76
  version_requirements: !ruby/object:Gem::Requirement
77
77
  requirements:
78
78
  - - '='
79
79
  - !ruby/object:Gem::Version
80
- version: 1.5.9
80
+ version: 1.8.4
81
81
  description: Bruno is a small tool to convert your Localizable.strings (iOS) files
82
82
  into strings.xml (Android) and viceversa.
83
83
  email: jm.gilgado@gmail.com
@@ -88,9 +88,12 @@ extra_rdoc_files: []
88
88
  files:
89
89
  - bin/bruno
90
90
  - lib/bruno.rb
91
- - lib/bruno/strings_file.rb
91
+ - lib/bruno/android_file.rb
92
+ - lib/bruno/converter.rb
93
+ - lib/bruno/i18n_file.rb
94
+ - lib/bruno/ios_file.rb
92
95
  - lib/bruno/version.rb
93
- homepage: http://github.com/josem/bruno
96
+ homepage: https://github.com/josem/bruno
94
97
  licenses:
95
98
  - MIT
96
99
  metadata: {}
@@ -111,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
114
  version: '0'
112
115
  requirements: []
113
116
  rubyforge_project:
114
- rubygems_version: 2.2.2
117
+ rubygems_version: 2.7.7
115
118
  signing_key:
116
119
  specification_version: 4
117
120
  summary: Convert your i18n files between Android and iOS
@@ -1,92 +0,0 @@
1
- require 'nokogiri'
2
-
3
- module Bruno
4
- class StringsFile
5
- def initialize(file_path)
6
- if File.readable?(file_path)
7
- @content = File.read(file_path)
8
- else
9
- raise 'File is not readable'
10
- end
11
- end
12
-
13
- def transform(path)
14
- if is_ios?
15
- to_android(path)
16
- elsif is_android?
17
- to_ios(path)
18
- end
19
- end
20
-
21
- def is_ios?
22
- !(@content =~ /".*" = ".*";/).nil?
23
- end
24
-
25
- def is_android?
26
- !(@content =~ /<string name=".*">.*<\/string>/).nil?
27
- end
28
-
29
- def to_ios(ios_file_path)
30
- return if @content == ''
31
- strings = get_strings_from_android
32
- write_ios_file(ios_file_path, strings)
33
- end
34
-
35
- def to_android(android_file_path)
36
- return if @content == ''
37
- strings = get_strings_from_ios
38
- write_android_file(android_file_path, strings)
39
- end
40
-
41
- private
42
- def get_strings_from_android
43
- strings = []
44
- xml = Nokogiri::XML(@content)
45
- xml.root.xpath('string').each do |string|
46
- strings << {:key => string.attribute('name').value, :value => string.content}
47
- end
48
-
49
- strings
50
- end
51
-
52
- def get_strings_from_ios
53
- strings = []
54
- @content.each_line do |line|
55
- match_key = line.match(/\"([^\"]+)\"/)
56
- match_value = line.match(/= \"([^\"]+)\";/)
57
- strings << {:key => match_key[1], :value => match_value[1]}
58
- end
59
- strings
60
- end
61
-
62
- def compose_ios_line(key, value)
63
- '"' + key + '" = "' + value + '";'
64
- end
65
-
66
- def write_ios_file(path, strings)
67
- ios_file = File.new(path,'w+')
68
-
69
- strings.each_with_index do |string, index|
70
- ios_file.write(compose_ios_line(string[:key], string[:value]))
71
-
72
- if index != strings.length - 1
73
- ios_file.write("\n")
74
- end
75
- end
76
- ios_file.close
77
- end
78
-
79
- def write_android_file(path, strings)
80
- android_file = File.new(path, 'w+')
81
- builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
82
- xml.resources {
83
- strings.each do |string|
84
- xml.string({:name => string[:key]}) { xml.text string[:value] }
85
- end
86
- }
87
- end
88
- android_file.write(builder.to_xml)
89
- android_file.close
90
- end
91
- end
92
- end