yamlstrings 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 011ca680f04b49677d5d2436c28f471a5c3e330a
4
+ data.tar.gz: d07ffb9523b843b3f3c700411e8a3796de21f178
5
+ SHA512:
6
+ metadata.gz: bd022a7955ab362ec116307c43c1306087f462044264b28ba9e0d745c264ffa3132e582af06cb433ee61da1ad602f9630410620f985b91d68fb2237744385494
7
+ data.tar.gz: de43db6cd6617a9192d336321dbfeda08c192b248d1e74f098be2ad16ec316a04ad448edb693157ee3d2438ab0098a5c69453eed207c7baa4caf843e1517858b
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in yamlstrings.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Nicolas Goy
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # Yamlstrings
2
+
3
+ Small utility to convert YAML files to Objective-C (used by NSBundle) strings files.
4
+
5
+ The following YAML file:
6
+
7
+ foo:
8
+ bar: Hello World
9
+ bar2: Hello World 2
10
+
11
+ is converted to:
12
+
13
+ "foo.bar" = "Hello World";
14
+ "foo.bar2" = "Hello World 2";
15
+
16
+ Yamlstrings let you merge multiple input YAML files into one strings file using prefix.
17
+
18
+ Use a special key `_prefix` to have this prefix prepended to all keys. For example:
19
+
20
+ _prefix: important
21
+ foo:
22
+ bar: Hello World
23
+ bar2: Hello World 2
24
+
25
+ is converted to:
26
+
27
+ "important.foo.bar" = "Hello World";
28
+ "important.foo.bar2" = "Hello World 2";
29
+
30
+ ## Installation
31
+
32
+ Install it:
33
+
34
+ $ gem install yamlstrings
35
+
36
+ ## Usage
37
+
38
+ CLI:
39
+
40
+ $ yamlstrings input1.yaml input2.yaml output.strings
41
+
42
+ API:
43
+
44
+ converter = Yamlstrings::Converter.new(inputs)
45
+ converter.to_file(output)
46
+
47
+ ## Known issues
48
+
49
+ - Write specs
50
+ - Write doc
51
+
52
+ ## Contributing
53
+
54
+ 1. Fork it
55
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
56
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
57
+ 4. Push to the branch (`git push origin my-new-feature`)
58
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/yamlstrings ADDED
@@ -0,0 +1,4 @@
1
+ require "yamlstrings"
2
+
3
+ Yamlstrings::CLI.new
4
+
@@ -0,0 +1,6 @@
1
+ require "yamlstrings/version"
2
+ require "yamlstrings/utils"
3
+ require "yamlstrings/converter"
4
+ require "yamlstrings/cli"
5
+
6
+
@@ -0,0 +1,16 @@
1
+ module Yamlstrings
2
+ class CLI
3
+ def initialize
4
+ if ARGV.length < 2
5
+ puts "Usage: yamlstrings <input1> [<input2>, ...] <output>"
6
+ puts "\nyamlstrings version #{Yamlstrings::VERSION}"
7
+ puts "Converts YAML files to strings files"
8
+ return
9
+ end
10
+ inputs = ARGV[0..-2]
11
+ output = ARGV.last
12
+ converter = Yamlstrings::Converter.new(inputs)
13
+ converter.to_file(output)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,35 @@
1
+ require 'yaml'
2
+
3
+ module Yamlstrings
4
+ class Converter
5
+ def initialize(paths=nil)
6
+ @keys = {}
7
+ @paths = []
8
+ for p in paths
9
+ add_file(p)
10
+ end
11
+ end
12
+
13
+ def add_file(path)
14
+ keys = YAML.load_file(path)
15
+ prefix = keys['_prefix']
16
+ keys.delete('_prefix')
17
+ keys = {prefix => keys} if prefix
18
+ @keys.merge!(keys)
19
+ end
20
+
21
+ def to_file(path)
22
+ flat = @keys.hflatten
23
+ out = []
24
+
25
+ open(path, 'w') do |out|
26
+ flat.each_pair do |k, v|
27
+ k = k.to_s.gsub(/\._/, '')
28
+ v = v.gsub('"', '\"').gsub("\n", '\n')
29
+ k = k.gsub('"', '').gsub("\n", '')
30
+ out << %|"#{k}" = "#{v}";\n|
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,15 @@
1
+
2
+ class Hash
3
+ # Taken from https://gist.github.com/abevoelker/3219985/
4
+ def hflatten(path=[])
5
+ self.inject({}) do |a,(k,v)|
6
+ if v.is_a? Hash
7
+ # Recurse
8
+ a.merge(v.hflatten(path.dup << k))
9
+ else
10
+ # Base case
11
+ a[(path.dup << k).join('.')] = v; a
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module Yamlstrings
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'yamlstrings/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "yamlstrings"
8
+ spec.version = Yamlstrings::VERSION
9
+ spec.authors = ["Nicolas Goy"]
10
+ spec.email = ["kuon@goyman.com"]
11
+ spec.description = %q{Small utility to convert YAML files to Objective-C (used by NSBundle) strings files}
12
+ spec.summary = %q{Small utility to convert YAML files to Objective-C (used by NSBundle) strings files}
13
+ spec.homepage = "http://bitbucket.org/kuon/yamlstrings"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yamlstrings
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Nicolas Goy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Small utility to convert YAML files to Objective-C (used by NSBundle)
42
+ strings files
43
+ email:
44
+ - kuon@goyman.com
45
+ executables:
46
+ - yamlstrings
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - .gitignore
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - bin/yamlstrings
56
+ - lib/yamlstrings.rb
57
+ - lib/yamlstrings/cli.rb
58
+ - lib/yamlstrings/converter.rb
59
+ - lib/yamlstrings/utils.rb
60
+ - lib/yamlstrings/version.rb
61
+ - yamlstrings.gemspec
62
+ homepage: http://bitbucket.org/kuon/yamlstrings
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.0.3
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Small utility to convert YAML files to Objective-C (used by NSBundle) strings
86
+ files
87
+ test_files: []