i18n-tasks-mongoid 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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +36 -0
- data/Rakefile +1 -0
- data/bin/i18n-tasks-mongoid +129 -0
- data/i18n-tasks-mongoid.gemspec +25 -0
- data/lib/i18n/tasks/mongoid.rb +9 -0
- data/lib/i18n/tasks/mongoid/version.rb +7 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e34d498e53f6885ae958a84395f8f68843a251d8
|
4
|
+
data.tar.gz: 4cbccb901f11567c597cf6dfbe19b4481aae7b2f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a2c1c72fa790f71c60d28119036cf499ed79cba04859d031634a491a5901347824a184d184b987b36418b510d068c066f3babc1e9d2220f54562bdb77e541928
|
7
|
+
data.tar.gz: c65e175418c39c6753c419d8348138d02ee9db81def31986b1db2ea35de4ba0cba80c1f8ae221dafbe526b9d0f7bd3b39f908f82d246871f0585d52386b7dce1
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 glebtv
|
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,36 @@
|
|
1
|
+
# I18n::Tasks::Mongoid
|
2
|
+
|
3
|
+
Automatically fills locale data based on mongoid models and attributes.
|
4
|
+
|
5
|
+
Work-in-progress. Buggy.
|
6
|
+
|
7
|
+
Works by wrapping i18n-tasks gem and feeding it with data received from live Mongoid models from your app, so sometimes unwanted (non-visible by user) fields might apper in i18n data, such as version, modifier, c_at, etc.
|
8
|
+
|
9
|
+
Tries to be smart about what attributes are shared between models.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
gem 'i18n-tasks-mongoid'
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install i18n-tasks-mongoid
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
$ i18n-tasks-mongoid missing
|
28
|
+
$ i18n-tasks-mongoid add-missing ru
|
29
|
+
|
30
|
+
## Contributing
|
31
|
+
|
32
|
+
1. Fork it ( http://github.com/<my-github-username>/i18n-tasks-mongoid/fork )
|
33
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
34
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
35
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
36
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,129 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
ENV['RAILS_ENV'] = 'development'
|
4
|
+
require File.expand_path(Dir.pwd + "/config/environment")
|
5
|
+
Dir[Rails.root + 'app/models/**/*.rb'].each do |path|
|
6
|
+
require path
|
7
|
+
end
|
8
|
+
User
|
9
|
+
News
|
10
|
+
Page
|
11
|
+
Menu
|
12
|
+
ContactMessage
|
13
|
+
|
14
|
+
|
15
|
+
require 'i18n/tasks'
|
16
|
+
require 'i18n/tasks/commands'
|
17
|
+
require 'slop'
|
18
|
+
require 'i18n/tasks/used_keys'
|
19
|
+
|
20
|
+
module I18n::Tasks::UsedKeys
|
21
|
+
def used_keys_group(keys)
|
22
|
+
models = Object.constants.reject{|sym| %i(Config).include?(sym) }.collect { |sym| Object.const_get(sym) }.select { |constant| constant.class == Class && constant.include?(Mongoid::Document) }
|
23
|
+
|
24
|
+
all_fields = Hash.new(0)
|
25
|
+
models.each do |m|
|
26
|
+
m.fields.keys.each do |key|
|
27
|
+
all_fields[key] += 1
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
fields = []
|
32
|
+
done = []
|
33
|
+
models.each do |m|
|
34
|
+
m.fields.each_pair do |key, value|
|
35
|
+
next if key.to_s == 'lft' || key.to_s == 'rgt' || key.to_s == 'depth' || !key.to_s.index('_content_type').nil? || !key.to_s.index('_file_name').nil? ||
|
36
|
+
!key.to_s.index('_file_size').nil? || !key.to_s.index('_fingerprint').nil? || !key.to_s.index('_updated_at').nil?
|
37
|
+
|
38
|
+
if done.include?(key)
|
39
|
+
next
|
40
|
+
else
|
41
|
+
done << key
|
42
|
+
end
|
43
|
+
|
44
|
+
if all_fields[key] > 1
|
45
|
+
fields << I18n::Tasks::Key.new(['attributes.' + key.to_s, key.to_s.humanize])
|
46
|
+
else
|
47
|
+
fields << I18n::Tasks::Key.new(['mongoid.attributes.' + m.model_name.i18n_key.to_s + '.' + key.to_s, key.to_s.humanize])
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
keys = keys + models.map {|m| I18n::Tasks::Key.new(['mongoid.models.' + m.model_name.i18n_key.to_s, m.model_name.i18n_key.to_s.humanize]) } + fields
|
52
|
+
|
53
|
+
::I18n::Tasks::KeyGroup.new keys, type: :used, key_filter: scanner.key_filter
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
command = nil
|
58
|
+
slop = Slop.parse(help: true) do
|
59
|
+
on('-v', '--version', 'Print the version') {
|
60
|
+
puts I18n::Tasks::VERSION
|
61
|
+
exit
|
62
|
+
}
|
63
|
+
::I18n::Tasks::Commands.cmds.each do |name, attr|
|
64
|
+
command name.tr('_', '-') do
|
65
|
+
description attr.desc if attr.desc
|
66
|
+
instance_exec(&attr.opts) if attr.opts
|
67
|
+
run do |opts, args|
|
68
|
+
command = [name, opts, args]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
gem_paths = []
|
75
|
+
begin
|
76
|
+
gem_paths << "#{Gem::Specification.find_by_name("rocket_cms").gem_dir}/config/locales/%{locale}.models.yml"
|
77
|
+
rescue
|
78
|
+
end
|
79
|
+
#begin
|
80
|
+
# gem_paths << "#{Gem::Specification.find_by_name("rs_russian").gem_dir}/lib/russian/locale/*.yml"
|
81
|
+
#rescue
|
82
|
+
#end
|
83
|
+
|
84
|
+
DEFAULT_CONFIG = {
|
85
|
+
base_locale: :ru,
|
86
|
+
locales: [:ru],
|
87
|
+
data: {
|
88
|
+
adapter: 'file_system',
|
89
|
+
read: ['config/locales/%{locale}.yml', 'config/locales/*.%{locale}.yml', 'config/locales/%{locale}.*.yml'] + gem_paths,
|
90
|
+
write: [[/\A(attributes|mongoid).*\z/, 'config/locales/%{locale}.models.yml'], [/\A.*\z/, 'config/locales/%{locale}.yml']]
|
91
|
+
}
|
92
|
+
}
|
93
|
+
|
94
|
+
require 'i18n/tasks/configuration'
|
95
|
+
module I18n::Tasks::Configuration
|
96
|
+
def file_config
|
97
|
+
file = CONFIG_FILES.detect { |f| File.exists?(f) }
|
98
|
+
file = YAML.load(Erubis::Eruby.new(File.read(file)).result) if file
|
99
|
+
if file.presence
|
100
|
+
{}.with_indifferent_access.merge(file.presence || {})
|
101
|
+
else
|
102
|
+
DEFAULT_CONFIG
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
if command
|
108
|
+
cmd = ::I18n::Tasks::Commands.new
|
109
|
+
meth = command[0]
|
110
|
+
opts = command[1].to_hash.reject { |k, v| v.nil? }
|
111
|
+
args = command[2]
|
112
|
+
begin
|
113
|
+
if opts.empty? && args.empty?
|
114
|
+
cmd.log_verbose "run #{meth.tr('_', '-')} without arguments"
|
115
|
+
cmd.send meth
|
116
|
+
else
|
117
|
+
opts = opts.merge(arguments: args) unless args.empty?
|
118
|
+
cmd.log_verbose "run #{meth.tr('_', '-')} with #{opts.map { |k, v| "#{k}=#{v}" } * ' '}"
|
119
|
+
cmd.send meth, opts
|
120
|
+
end
|
121
|
+
rescue Errno::EPIPE
|
122
|
+
# ignore Errno::EPIPE which is throw when pipe breaks, e.g.:
|
123
|
+
# i18n-tasks missing | head
|
124
|
+
end
|
125
|
+
else
|
126
|
+
STDERR.puts Term::ANSIColor.red "Command unknown: #{ARGV[0]}" if ARGV[0]
|
127
|
+
puts slop.help
|
128
|
+
exit 64
|
129
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'i18n/tasks/mongoid/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "i18n-tasks-mongoid"
|
8
|
+
spec.version = I18n::Tasks::Mongoid::VERSION
|
9
|
+
spec.authors = ["glebtv"]
|
10
|
+
spec.email = ["glebtv@gmail.com"]
|
11
|
+
spec.summary = %q{i18n-tasks extractor (scanner) for Mongoid models. Work in progress}
|
12
|
+
spec.description = %q{}
|
13
|
+
spec.homepage = "https://github.com/rs-pro/i18n-tasks-mongoid/"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
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.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
|
24
|
+
spec.add_dependency "i18n-tasks"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: i18n-tasks-mongoid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- glebtv
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-04 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.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
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
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: i18n-tasks
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: ''
|
56
|
+
email:
|
57
|
+
- glebtv@gmail.com
|
58
|
+
executables:
|
59
|
+
- i18n-tasks-mongoid
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/i18n-tasks-mongoid
|
69
|
+
- i18n-tasks-mongoid.gemspec
|
70
|
+
- lib/i18n/tasks/mongoid.rb
|
71
|
+
- lib/i18n/tasks/mongoid/version.rb
|
72
|
+
homepage: https://github.com/rs-pro/i18n-tasks-mongoid/
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.2.1
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: i18n-tasks extractor (scanner) for Mongoid models. Work in progress
|
96
|
+
test_files: []
|