anastasia 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 23a3b81cf27ca521ef559fe94b886b182f0aa779a0cbf3bfeb84cfb795f73eb6
4
+ data.tar.gz: 23c8fb0ff7647145ea282c66d1b3f0ba49aae4bd17400c94e759016afaf59a94
5
+ SHA512:
6
+ metadata.gz: ac742bb68e4aa573299b127cc9709ef1c516f6c3adf50efe71c60728f1505939a07d561ebd1ce75038cca8413144dc784c8cb9e9d06236315b646010f274dced
7
+ data.tar.gz: 4c4e79f7a2da771c897540e237fd1773e67479c8beeb1b1860682908b933734f72d46c591085eea79a6ec3656f45f3614b238fcf9459c7c681bbfe90c72684da
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,42 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Metrics/AbcSize:
5
+ Max: 170
6
+
7
+ Metrics/BlockLength:
8
+ Max: 250
9
+
10
+ Metrics/ClassLength:
11
+ Max: 1000
12
+
13
+ Metrics/CyclomaticComplexity:
14
+ Max: 70
15
+
16
+ Metrics/MethodLength:
17
+ Max: 100
18
+
19
+ Metrics/ModuleLength:
20
+ Max: 1000
21
+
22
+ Metrics/ParameterLists:
23
+ Max: 50
24
+
25
+ Metrics/PerceivedComplexity:
26
+ Max: 80
27
+
28
+ Layout/SpaceInsideBlockBraces:
29
+ EnforcedStyle: no_space
30
+ SpaceBeforeBlockParameters: false
31
+
32
+ Style/Documentation:
33
+ Enabled: false
34
+
35
+ Style/NumericPredicate:
36
+ EnforcedStyle: comparison
37
+
38
+ Style/MultilineBlockChain:
39
+ Enabled: false
40
+
41
+ Style/SpecialGlobalVars:
42
+ EnforcedStyle: use_perl_names
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in anastasia.gemspec
6
+ gemspec
7
+
8
+ gem 'rake', '~> 13.0'
9
+
10
+ gem 'rspec', '~> 3.0'
data/Gemfile.lock ADDED
@@ -0,0 +1,57 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ anastasia (0.1.0)
5
+ yaml
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.2)
11
+ diff-lcs (1.5.0)
12
+ parallel (1.22.1)
13
+ parser (3.1.2.0)
14
+ ast (~> 2.4.1)
15
+ rainbow (3.1.1)
16
+ rake (13.0.6)
17
+ regexp_parser (2.5.0)
18
+ rexml (3.2.5)
19
+ rspec (3.11.0)
20
+ rspec-core (~> 3.11.0)
21
+ rspec-expectations (~> 3.11.0)
22
+ rspec-mocks (~> 3.11.0)
23
+ rspec-core (3.11.0)
24
+ rspec-support (~> 3.11.0)
25
+ rspec-expectations (3.11.0)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.11.0)
28
+ rspec-mocks (3.11.1)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.11.0)
31
+ rspec-support (3.11.0)
32
+ rubocop (1.30.1)
33
+ parallel (~> 1.10)
34
+ parser (>= 3.1.0.0)
35
+ rainbow (>= 2.2.2, < 4.0)
36
+ regexp_parser (>= 1.8, < 3.0)
37
+ rexml (>= 3.2.5, < 4.0)
38
+ rubocop-ast (>= 1.18.0, < 2.0)
39
+ ruby-progressbar (~> 1.7)
40
+ unicode-display_width (>= 1.4.0, < 3.0)
41
+ rubocop-ast (1.18.0)
42
+ parser (>= 3.1.1.0)
43
+ ruby-progressbar (1.11.0)
44
+ unicode-display_width (2.1.0)
45
+ yaml (0.2.0)
46
+
47
+ PLATFORMS
48
+ arm64-darwin-21
49
+
50
+ DEPENDENCIES
51
+ anastasia!
52
+ rake (~> 13.0)
53
+ rspec (~> 3.0)
54
+ rubocop
55
+
56
+ BUNDLED WITH
57
+ 2.3.16
data/LICENSE ADDED
@@ -0,0 +1,14 @@
1
+ Copyright 2022 Ishotihadus
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
4
+ documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
5
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
6
+ persons to whom the Software is furnished to do so, subject to the following conditions:
7
+
8
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
9
+ Software.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
12
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
13
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
14
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Anastasia
2
+
3
+ JSON generator for [i18next](https://www.i18next.com/) JSON from yaml.
4
+
5
+ ## Installation
6
+
7
+ Install the gem and add to the application's Gemfile by executing:
8
+
9
+ $ bundle add anastasia
10
+
11
+ If bundler is not being used to manage dependencies, install the gem by executing:
12
+
13
+ $ gem install anastasia
14
+
15
+ ## Usage
16
+
17
+ ```shell
18
+ $ anastasia input.yaml outdir
19
+ ```
20
+
21
+ ## Development
22
+
23
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
24
+
25
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
26
+
27
+ ## Contributing
28
+
29
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Ishotihadus/anastasia.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/anastasia.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/anastasia/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'anastasia'
7
+ spec.version = Anastasia::VERSION
8
+ spec.authors = ['Ishotihadus']
9
+ spec.email = ['hanachan.pao@gmail.com']
10
+
11
+ spec.summary = 'i18next JSON generator from yaml'
12
+ spec.description = 'i18next JSON generator from yaml'
13
+ spec.homepage = 'https://github.com/Ishotihadus/anastasia'
14
+ spec.required_ruby_version = '>= 2.6.0'
15
+
16
+ spec.metadata['homepage_uri'] = spec.homepage
17
+ spec.metadata['source_code_uri'] = spec.homepage
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(__dir__) do
22
+ `git ls-files -z`.split("\x0").reject do |f|
23
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
24
+ end
25
+ end
26
+ spec.bindir = 'exe'
27
+ spec.executables = spec.files.grep(%r{\Aexe/}) {|f| File.basename(f)}
28
+ spec.require_paths = ['lib']
29
+
30
+ spec.add_dependency 'yaml'
31
+ spec.add_development_dependency 'rubocop'
32
+ end
data/exe/anastasia ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'anastasia'
5
+ require 'json'
6
+ require 'fileutils'
7
+ require 'yaml'
8
+
9
+ unless ARGV.size == 2
10
+ warn "usage: #{$0} input outdir"
11
+ exit 1
12
+ end
13
+
14
+ files =
15
+ if File.file?(ARGV[0])
16
+ [ARGV[0]]
17
+ elsif File.directory?(ARGV[0])
18
+ Dir.glob("#{ARGV[0]}/*.yaml") + Dir.glob("#{ARGV[0]}/*.yml")
19
+ end
20
+
21
+ files.each do |file|
22
+ data = YAML.load_file(file)
23
+ Anastasia.convert(data).each do |lang, d|
24
+ FileUtils.mkdir_p("#{ARGV[1]}/#{lang.downcase}")
25
+ File.write("#{ARGV[1]}/#{lang.downcase}/#{File.basename(file, '.*')}.json", JSON.generate(d))
26
+ end
27
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Anastasia
4
+ VERSION = '0.1.0'
5
+ end
data/lib/anastasia.rb ADDED
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'anastasia/version'
4
+
5
+ module Anastasia
6
+ def self.convert(data)
7
+ convert_internal(data, [], {})
8
+ end
9
+
10
+ def self.convert_internal(data, pos, ret)
11
+ data.each do |k, v|
12
+ if k.start_with?(';')
13
+ append(k[1..], pos, v, ret)
14
+ else
15
+ convert_internal(v, pos + k.split('.'), ret)
16
+ end
17
+ end
18
+
19
+ ret
20
+ end
21
+
22
+ def self.append(lang, pos, value, ret)
23
+ pos = pos.dup
24
+ ret = (ret[lang] ||= {})
25
+ ret = (ret[pos.shift] ||= {}) while pos.count >= 2
26
+ append_value(lang, pos[0], value, ret)
27
+ end
28
+
29
+ def self.append_value(lang, key, value, ret)
30
+ case value
31
+ when String
32
+ ret[key] = value
33
+ when Array
34
+ ret[key] = value.join(no_space_language?(lang) ? '' : ' ')
35
+ when Hash
36
+ value.each do |k, v|
37
+ key_with_context = k == '_' ? key : "#{key}_#{k}"
38
+ append_value(lang, key_with_context, v, ret)
39
+ end
40
+ end
41
+ end
42
+
43
+ NO_SPACE_LANGUAGES = %w[ja zh].freeze
44
+
45
+ def self.no_space_language?(lang)
46
+ lang = lang.split('-').first.downcase
47
+ NO_SPACE_LANGUAGES.include?(lang)
48
+ end
49
+ end
data/sig/anastasia.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Anastasia
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: anastasia
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ishotihadus
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-06-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: yaml
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop
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: i18next JSON generator from yaml
42
+ email:
43
+ - hanachan.pao@gmail.com
44
+ executables:
45
+ - anastasia
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".rspec"
50
+ - ".rubocop.yml"
51
+ - Gemfile
52
+ - Gemfile.lock
53
+ - LICENSE
54
+ - README.md
55
+ - Rakefile
56
+ - anastasia.gemspec
57
+ - exe/anastasia
58
+ - lib/anastasia.rb
59
+ - lib/anastasia/version.rb
60
+ - sig/anastasia.rbs
61
+ homepage: https://github.com/Ishotihadus/anastasia
62
+ licenses: []
63
+ metadata:
64
+ homepage_uri: https://github.com/Ishotihadus/anastasia
65
+ source_code_uri: https://github.com/Ishotihadus/anastasia
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: 2.6.0
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubygems_version: 3.3.3
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: i18next JSON generator from yaml
85
+ test_files: []