bruno 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/bin/bruno ADDED
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env ruby
2
+ require 'gli'
3
+ require 'bruno'
4
+
5
+ include GLI::App
6
+
7
+ program_desc 'Convert your strings files from Android to iOS and viceversa'
8
+
9
+ version Bruno::VERSION
10
+
11
+ desc 'Converts Localizable.strings into strings.xml or viceversa'
12
+ command :convert do |c|
13
+ c.desc 'input file (Localizable.strings or strings.xml)'
14
+ c.arg_name 'input File'
15
+ c.flag [:in]
16
+
17
+ c.desc 'output file (Localizable.strings or strings.xml)'
18
+ c.arg_name 'output File'
19
+ c.flag [:out]
20
+
21
+ c.action do |global_options, options, args|
22
+ raise 'You must provide an input file' if options[:in].nil?
23
+ raise 'You must provide an output file' if options[:out].nil?
24
+
25
+ # If you have any errors, just raise them
26
+ #raise "that command made no sense"
27
+
28
+ strings_file = Bruno::StringsFile.new(options[:in])
29
+ strings_file.transform(options[:out])
30
+ puts "convert command ran"
31
+ end
32
+ end
33
+
34
+ pre do |global,command,options,args|
35
+ # Pre logic here
36
+ # Return true to proceed; false to abort and not call the
37
+ # chosen command
38
+ # Use skips_pre before a command to skip this block
39
+ # on that command only
40
+ true
41
+ end
42
+
43
+ post do |global,command,options,args|
44
+ # Post logic here
45
+ # Use skips_post before a command to skip this
46
+ # block on that command only
47
+ end
48
+
49
+ on_error do |exception|
50
+ # Error logic here
51
+ # return false to skip default error handling
52
+ true
53
+ end
54
+
55
+ exit run(ARGV)
data/lib/bruno/main.rb ADDED
@@ -0,0 +1,9 @@
1
+ module Bruno
2
+ def self.is_ios?(file_content)
3
+ !(file_content =~ /".*" = ".*";/).nil?
4
+ end
5
+
6
+ def self.is_android?(file_content)
7
+ !(file_content =~ /<string name=".*">.*<\/string>/).nil?
8
+ end
9
+ end
@@ -0,0 +1,92 @@
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
+ Bruno.is_ios?(@content)
23
+ end
24
+
25
+ def is_android?
26
+ Bruno.is_android?(@content)
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
@@ -0,0 +1,3 @@
1
+ module Bruno
2
+ VERSION = '0.0.1'
3
+ end
data/lib/bruno.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'bruno/version'
2
+ require 'bruno/strings_file'
3
+ require 'bruno/main'
4
+
5
+ # Add requires for other files you add to your project here, so
6
+ # you just need to require this one file in your bin file
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bruno
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - José M. Gilgado
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rdoc
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: aruba
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: gli
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - '='
84
+ - !ruby/object:Gem::Version
85
+ version: 2.5.4
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - '='
92
+ - !ruby/object:Gem::Version
93
+ version: 2.5.4
94
+ - !ruby/object:Gem::Dependency
95
+ name: nokogiri
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - '='
100
+ - !ruby/object:Gem::Version
101
+ version: 1.5.9
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - '='
108
+ - !ruby/object:Gem::Version
109
+ version: 1.5.9
110
+ description: Bruno is a small tool to convert your Localizable.strings (iOS) files
111
+ into strings.xml (Android) and viceversa.
112
+ email: jm.gilgado@gmail.com
113
+ executables:
114
+ - bruno
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - bin/bruno
119
+ - lib/bruno/version.rb
120
+ - lib/bruno/strings_file.rb
121
+ - lib/bruno/main.rb
122
+ - lib/bruno.rb
123
+ homepage: http://github.com/josem/bruno
124
+ licenses: []
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ none: false
132
+ requirements:
133
+ - - ! '>='
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 1.8.24
145
+ signing_key:
146
+ specification_version: 3
147
+ summary: Convert your i18n files between Android and iOS
148
+ test_files: []