babel_diff 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +3 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +2 -0
- data/babel_diff.gemspec +22 -0
- data/bin/babel_diff +2 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/config/locales/phrases.en.additions.yml +5 -0
- data/config/locales/phrases.en.previous_version.yml +9 -0
- data/config/locales/phrases.en.updates.yml +5 -0
- data/config/locales/phrases.en.yml +9 -0
- data/lib/babel_diff.rb +18 -0
- data/lib/babel_diff/file_handler.rb +52 -0
- data/lib/babel_diff/version.rb +3 -0
- data/lib/babel_diff/yaml_differ.rb +88 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5aa732702170dd08fea7d0cc274ee53e57b64a5a
|
4
|
+
data.tar.gz: a6c9fc90a1de9f1fd7c283be13592440fa0c2868
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0d87eaaed17c191a4c21dc518b0c3b5431d48803a913a687d7e15e425a4b6d78f1b91e8db93389612d3ef6b07690ad1dd88395da16b097d12774368782486487
|
7
|
+
data.tar.gz: 747107866360f35bbeeec53319c0d39970b2a752eef39a54d4dbafceada2d9d9c2c71021ca87445449f8d4fb045c1910e7adf4413c6d8b825170b553a3db5eb8
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
babel_diff
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.1.1
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Ryan Nash
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# BabelDiff
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'babel_diff'
|
9
|
+
```
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install babel_diff
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
BabelDiff.run
|
23
|
+
```
|
24
|
+
|
25
|
+
Running the above command from the Rails console will create two files, "phrases.en.additions.yml" and "phrases.en.updates.yml", in your locales directory.
|
26
|
+
|
27
|
+
These files will contain all added and updated translation keys, respectively. If this is your first time running BabelDiff, the additions file will contain all of your translation keys.
|
28
|
+
|
29
|
+
The file "phrases.en.previous_version.yml" will also be created to serve as the benchmark against which future diffs will be compared.
|
30
|
+
|
31
|
+
If you want to run BabelDiff on a different locale file, you can pass it to the "#run" method. The default file path is "config/locales/phrases.en.yml".
|
32
|
+
|
33
|
+
The following code:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
BabelDiff.run("config/locales/random_folder/phrases.fr.yml")
|
37
|
+
```
|
38
|
+
|
39
|
+
would produce the following files:
|
40
|
+
|
41
|
+
Additions => config/locales/random_folder/phrases.additions.fr.yml
|
42
|
+
Updates => config/locales/random_folder/phrases.updates.fr.yml
|
43
|
+
Previous Version => config/locales/random_folder/phrases.previous_version.fr.yml
|
data/Rakefile
ADDED
data/babel_diff.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'babel_diff/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "babel_diff"
|
8
|
+
spec.version = BabelDiff::VERSION
|
9
|
+
spec.authors = ["Ryan McGarvey", "Noah Gordon"]
|
10
|
+
spec.email = ["ryan@gust.com", "noah@gust.com", "devs@gust.com"]
|
11
|
+
spec.summary = %q{A logger for updates and additions to locale yaml files.}
|
12
|
+
spec.homepage = "https://github.com/zephyr-dev/babel_diff"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.add_development_dependency "bundler", "~> 1.8"
|
20
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
21
|
+
spec.add_development_dependency "pry"
|
22
|
+
end
|
data/bin/babel_diff
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "babel_diff"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/babel_diff.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "babel_diff/version"
|
2
|
+
require "babel_diff/file_handler"
|
3
|
+
require "babel_diff/yaml_differ"
|
4
|
+
|
5
|
+
module BabelDiff
|
6
|
+
def self.run(current_version_path = "config/locales/phrases.en.yml")
|
7
|
+
handler = FileHandler.new(current_version_path)
|
8
|
+
|
9
|
+
yaml_differ = YamlDiffer.new(handler.current_version, handler.previous_version)
|
10
|
+
updates = yaml_differ.updates
|
11
|
+
additions = yaml_differ.additions
|
12
|
+
|
13
|
+
handler.create_updates(updates)
|
14
|
+
handler.create_additions(additions)
|
15
|
+
handler.version_files
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module BabelDiff
|
2
|
+
class FileHandler < Struct.new(:current_version_path)
|
3
|
+
def previous_version
|
4
|
+
File.exist?(previous_version_path) ? File.read(previous_version_path) : ""
|
5
|
+
end
|
6
|
+
|
7
|
+
def current_version
|
8
|
+
if File.exist?(current_version_path)
|
9
|
+
File.read(current_version_path)
|
10
|
+
else
|
11
|
+
raise "Phrase file not found"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def create_updates(content)
|
16
|
+
File.open(updates_file_path, "w+") do |f|
|
17
|
+
f.write(content)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def create_additions(content)
|
22
|
+
File.open(additions_file_path, "w+") do |f|
|
23
|
+
f.write(content)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def version_files
|
28
|
+
current_contents = File.read(current_version_path)
|
29
|
+
File.open(previous_version_path, "w+") do |f|
|
30
|
+
f.write(current_contents)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def previous_version_path
|
37
|
+
root_path + ".previous_version.yml"
|
38
|
+
end
|
39
|
+
|
40
|
+
def updates_file_path
|
41
|
+
root_path + ".updates.yml"
|
42
|
+
end
|
43
|
+
|
44
|
+
def additions_file_path
|
45
|
+
root_path + ".additions.yml"
|
46
|
+
end
|
47
|
+
|
48
|
+
def root_path
|
49
|
+
current_version_path.split(".")[0...-1].join(".")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'pry'
|
3
|
+
|
4
|
+
module BabelDiff
|
5
|
+
class YamlDiffer < Struct.new(:current_version, :previous_version)
|
6
|
+
def updates
|
7
|
+
process_difference(current_version_hash) unless @processed
|
8
|
+
@processed = true
|
9
|
+
updates_hash.to_yaml
|
10
|
+
end
|
11
|
+
|
12
|
+
def additions
|
13
|
+
process_difference(current_version_hash) unless @processed
|
14
|
+
@processed = true
|
15
|
+
additions_hash.to_yaml
|
16
|
+
end
|
17
|
+
|
18
|
+
def process_difference(current_hash, keys = [])
|
19
|
+
current_hash.each do |key, value|
|
20
|
+
keys << key
|
21
|
+
if value.is_a? Hash
|
22
|
+
process_difference(value, keys)
|
23
|
+
else
|
24
|
+
if previous_version_is_missing_key?(keys)
|
25
|
+
add_key_to_additions(keys, value)
|
26
|
+
elsif previous_version_value_is_different?(keys, value)
|
27
|
+
add_key_to_updates(keys, value)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
keys.pop
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def previous_version_is_missing_key?(keys)
|
35
|
+
current_value = previous_version_hash
|
36
|
+
keys.each do |key|
|
37
|
+
current_value = current_value[key]
|
38
|
+
return true if current_value.nil?
|
39
|
+
end
|
40
|
+
|
41
|
+
return false
|
42
|
+
end
|
43
|
+
|
44
|
+
def previous_version_value_is_different?(keys, value)
|
45
|
+
current_value = previous_version_hash
|
46
|
+
keys.each do |key|
|
47
|
+
current_value = current_value[key]
|
48
|
+
end
|
49
|
+
|
50
|
+
return current_value != value
|
51
|
+
end
|
52
|
+
|
53
|
+
def add_key_to_updates(keys, value)
|
54
|
+
current_value = updates_hash
|
55
|
+
keys[0...-1].each do |key|
|
56
|
+
current_value = current_value[key] ||= {}
|
57
|
+
end
|
58
|
+
current_value[keys.last] = value
|
59
|
+
end
|
60
|
+
|
61
|
+
def add_key_to_additions(keys, value)
|
62
|
+
current_value = additions_hash
|
63
|
+
keys[0...-1].each do |key|
|
64
|
+
current_value = current_value[key] ||= {}
|
65
|
+
end
|
66
|
+
current_value[keys.last] = value
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def updates_hash
|
73
|
+
@updated_hash ||= {}
|
74
|
+
end
|
75
|
+
|
76
|
+
def additions_hash
|
77
|
+
@additions_hash ||= {}
|
78
|
+
end
|
79
|
+
|
80
|
+
def previous_version_hash
|
81
|
+
YAML.load(previous_version) || {}
|
82
|
+
end
|
83
|
+
|
84
|
+
def current_version_hash
|
85
|
+
YAML.load(current_version) || {}
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: babel_diff
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryan McGarvey
|
8
|
+
- Noah Gordon
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-02-11 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.8'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.8'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '10.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '10.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: pry
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
description:
|
57
|
+
email:
|
58
|
+
- ryan@gust.com
|
59
|
+
- noah@gust.com
|
60
|
+
- devs@gust.com
|
61
|
+
executables: []
|
62
|
+
extensions: []
|
63
|
+
extra_rdoc_files: []
|
64
|
+
files:
|
65
|
+
- ".gitignore"
|
66
|
+
- ".rspec"
|
67
|
+
- ".ruby-gemset"
|
68
|
+
- ".ruby-version"
|
69
|
+
- ".travis.yml"
|
70
|
+
- CODE_OF_CONDUCT.md
|
71
|
+
- Gemfile
|
72
|
+
- LICENSE.txt
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- babel_diff.gemspec
|
76
|
+
- bin/babel_diff
|
77
|
+
- bin/console
|
78
|
+
- bin/setup
|
79
|
+
- config/locales/phrases.en.additions.yml
|
80
|
+
- config/locales/phrases.en.previous_version.yml
|
81
|
+
- config/locales/phrases.en.updates.yml
|
82
|
+
- config/locales/phrases.en.yml
|
83
|
+
- lib/babel_diff.rb
|
84
|
+
- lib/babel_diff/file_handler.rb
|
85
|
+
- lib/babel_diff/version.rb
|
86
|
+
- lib/babel_diff/yaml_differ.rb
|
87
|
+
homepage: https://github.com/zephyr-dev/babel_diff
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.2.2
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: A logger for updates and additions to locale yaml files.
|
111
|
+
test_files: []
|