banyan 1.0.1 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.gitignore +2 -0
- data/Rakefile +4 -1
- data/banyan.gemspec +4 -3
- data/features/step_definitions/translation_import_and_export_steps.rb +79 -0
- data/features/support/env.rb +11 -0
- data/features/translation_import_and_export.feature +89 -0
- data/lib/banyan.rb +2 -0
- data/lib/banyan/railtie.rb +9 -0
- data/lib/banyan/tasks.rb +101 -0
- data/lib/banyan/version.rb +1 -1
- metadata +37 -15
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
N2EzZjI3OWRmMjg2ZmNlNmUzY2U3NWQxYmQ2MDRmNTIyNmQ5NzY4ZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZmI1MzIzMzQwYmY2ZjdkYzQ2MGQ0N2NjZWNkYTg3YTU2OWE5OTY4Ng==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OWE3MGFiZmZhYWYxMWUyNzliZTNkNzhmZDdlNzAxMzBiYzY0OWQxNGE3N2Mz
|
10
|
+
MmUxMzA0NTZmNGEyNTk4MDQzNDBhZGM0YmVhZmFmZWEyOWU1OTE0ZDE4NjY0
|
11
|
+
Mjc1OWI1MDMxMzU2MzdkYzJmYzE4OWYyNDA1OWMwMDg1N2VjOWE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NjI5ZTgxNjEyNjFmZmQ3MGZjZGJhN2M1ZGRjNjA4OTE4ZjhhNzhhMjU2YTNi
|
14
|
+
NjEyNWY3MGM4ZDNmYWIxYTI2NDY3YjRlMDMzMjg3NmM3ZDMyMmM1MThkMWZj
|
15
|
+
NzRkZTFkMGQ1YjU2MmMwYjI0MGRjODc0ZTUxYmFjYWVjZTg4ZTk=
|
data/.gitignore
CHANGED
data/Rakefile
CHANGED
data/banyan.gemspec
CHANGED
@@ -13,10 +13,11 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.add_dependency 'rails', '~> 3.0'
|
14
14
|
s.add_dependency 'globalize3', '~> 0.3'
|
15
15
|
s.add_dependency 'awesome_nested_set', '~> 2.0'
|
16
|
-
s.add_development_dependency '
|
17
|
-
s.add_development_dependency 'rspec-rails', '~> 2.6'
|
18
|
-
s.add_development_dependency 'factory_girl', '~> 4.2'
|
16
|
+
s.add_development_dependency 'aruba', '~> 0.5'
|
19
17
|
s.add_development_dependency 'database_cleaner', '< 1.1.0'
|
18
|
+
s.add_development_dependency 'factory_girl', '~> 4.2'
|
19
|
+
s.add_development_dependency 'rspec-rails', '~> 2.6'
|
20
|
+
s.add_development_dependency 'sqlite3', '~> 1.3'
|
20
21
|
|
21
22
|
s.files = `git ls-files`.split("\n")
|
22
23
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
@@ -0,0 +1,79 @@
|
|
1
|
+
Given /^I setup a new rails app "([^"]*)"$/ do |app|
|
2
|
+
run_simple("rails new #{app} -d mysql")
|
3
|
+
cd app
|
4
|
+
end
|
5
|
+
|
6
|
+
Given /^I install banyan$/ do
|
7
|
+
run_simple("bundle exec rake db:create", true)
|
8
|
+
run_simple("rails g banyan", true)
|
9
|
+
run_simple("bundle exec rake db:migrate", true)
|
10
|
+
end
|
11
|
+
|
12
|
+
Then /^the file "([^"]*)" should be valid yaml$/ do |file|
|
13
|
+
expect do
|
14
|
+
in_current_dir do
|
15
|
+
YAML::load_file(file)
|
16
|
+
end
|
17
|
+
end.to_not raise_error
|
18
|
+
end
|
19
|
+
|
20
|
+
Given /^I seed the database with Categories:$/ do |table|
|
21
|
+
in_current_dir do
|
22
|
+
File.open("db/seeds.rb", 'w+') do |file|
|
23
|
+
table.hashes.each do |row|
|
24
|
+
file.puts("category = Banyan::Category.create!(tag: #{row['tag'].inspect}, name: #{row['name'].inspect})")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
run_simple("bundle exec rake db:seed", true)
|
30
|
+
end
|
31
|
+
|
32
|
+
Given /^I seed the database with Groups:$/ do |table|
|
33
|
+
in_current_dir do
|
34
|
+
File.open("db/seeds.rb", 'w+') do |file|
|
35
|
+
table.hashes.each do |row|
|
36
|
+
file.puts("category_group = Banyan::CategoryGroup.create!(tag: #{row['tag'].inspect}, name: #{row['name'].inspect})")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
run_simple("bundle exec rake db:seed", true)
|
42
|
+
end
|
43
|
+
|
44
|
+
Given /^"a file named "([^"]*)" with:"$/ do |filename, hash|
|
45
|
+
in_current_dir do
|
46
|
+
File.open(filename, "w") do |f|
|
47
|
+
f.puts(yaml(hash))
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
Given /^I translate "([^"]*)" to "([^"]*)" into "([^"]*)"$/ do |path, value, filename|
|
53
|
+
in_current_dir do
|
54
|
+
categories, language, tag = path.split('.')
|
55
|
+
|
56
|
+
patch_hash = {categories => {language => {tag => value}}}
|
57
|
+
|
58
|
+
ydata = YAML.load_file(filename)
|
59
|
+
|
60
|
+
deep_merge_strategy = lambda do |conflicted_key, receiver_value, argument_value|
|
61
|
+
case receiver_value when Hash
|
62
|
+
case argument_value when Hash
|
63
|
+
receiver_value.merge(argument_value,&deep_merge_strategy)
|
64
|
+
else
|
65
|
+
argument_value
|
66
|
+
end
|
67
|
+
else
|
68
|
+
argument_value
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
ydata.merge!(patch_hash,&deep_merge_strategy)
|
73
|
+
|
74
|
+
File.open(filename, "w") do |f|
|
75
|
+
f.puts(ydata.to_yaml)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
@@ -0,0 +1,89 @@
|
|
1
|
+
@disable-bundler @rails-app
|
2
|
+
Feature: Facilitating translation of Banyan Categories
|
3
|
+
|
4
|
+
Background:
|
5
|
+
Given I setup a new rails app "dummy"
|
6
|
+
And I append to "Gemfile" with:
|
7
|
+
"""
|
8
|
+
gem 'banyan', path: "../../.."
|
9
|
+
"""
|
10
|
+
And a file named "config/environment.rb" with:
|
11
|
+
"""
|
12
|
+
Encoding.default_external = Encoding::UTF_8
|
13
|
+
Encoding.default_internal = Encoding::UTF_8
|
14
|
+
# Load the rails application
|
15
|
+
require File.expand_path('../application', __FILE__)
|
16
|
+
# Initialize the rails application
|
17
|
+
Dummy::Application.initialize!
|
18
|
+
"""
|
19
|
+
And I successfully run `bundle install` for up to 24 seconds
|
20
|
+
And I install banyan
|
21
|
+
And a file named "config/locales/de.yml" with:
|
22
|
+
"""
|
23
|
+
de:
|
24
|
+
hello: hallo
|
25
|
+
"""
|
26
|
+
And a file named "config/locales/fr.yml" with:
|
27
|
+
"""
|
28
|
+
fr:
|
29
|
+
hello: bonjour
|
30
|
+
"""
|
31
|
+
And I seed the database with Categories:
|
32
|
+
| tag | name |
|
33
|
+
| Business | Business|
|
34
|
+
| Tools & Utilities | Tools & Utilities |
|
35
|
+
And I seed the database with Groups:
|
36
|
+
| tag | name |
|
37
|
+
| appzone | AppZone |
|
38
|
+
| categories | Categories |
|
39
|
+
| form_factors | Form Factors |
|
40
|
+
|
41
|
+
Scenario: Exporting Banyan Category Translations
|
42
|
+
When I run `bundle exec rake translations:categories:export[current_translations.yml]`
|
43
|
+
Then the file "current_translations.yml" should contain "en:"
|
44
|
+
And the file "current_translations.yml" should be valid yaml
|
45
|
+
|
46
|
+
Scenario: Importing Banyan Category Translations
|
47
|
+
Given a file named "new_translations.yml" with:
|
48
|
+
"""
|
49
|
+
---
|
50
|
+
banyan_category_translations:
|
51
|
+
de:
|
52
|
+
Business: Unternehmen_DE
|
53
|
+
"Tools & Utilities": Werkzeuge und Hilfsprogramme_DE
|
54
|
+
banyan_category_group_translations:
|
55
|
+
de:
|
56
|
+
appzone: AppZone_DE
|
57
|
+
categories: Kategorien_DE
|
58
|
+
form_factors: Formfaktoren_DE
|
59
|
+
"""
|
60
|
+
When I run `bundle exec rake translations:categories:import[new_translations.yml]`
|
61
|
+
Then the output should contain "Updated 5 translations"
|
62
|
+
|
63
|
+
Scenario: Import and Export
|
64
|
+
Given a file named "new_translations.yml" with:
|
65
|
+
"""
|
66
|
+
---
|
67
|
+
banyan_category_translations:
|
68
|
+
de:
|
69
|
+
Business: Unternehmen
|
70
|
+
"Tools & Utilities": Werkzeuge und Hilfsprogramme
|
71
|
+
banyan_category_group_translations:
|
72
|
+
de:
|
73
|
+
appzone: AppZone
|
74
|
+
categories: Kategorien
|
75
|
+
form_factors: Formfaktoren
|
76
|
+
"""
|
77
|
+
And I run `rake translations:categories:import[new_translations.yml]`
|
78
|
+
When I run `rake translations:categories:export[current_translations.yml]`
|
79
|
+
Then the file "current_translations.yml" should contain "form_factors: Formfaktoren"
|
80
|
+
|
81
|
+
Scenario: Export and Import (and Export)
|
82
|
+
Given I run `bundle exec rake translations:categories:export[new_fr_translations.yml]`
|
83
|
+
And I translate "banyan_category_translations.fr.Tools & Utilities" to "Outils & Utilitaires" into "new_fr_translations.yml"
|
84
|
+
And I translate "banyan_category_group_translations.fr.categories" to "Catégories" into "new_fr_translations.yml"
|
85
|
+
When I run `rake translations:categories:import[new_fr_translations.yml]`
|
86
|
+
Then the output should contain "Updated 2 translations"
|
87
|
+
And I run `rake translations:categories:export[current_translations.yml]`
|
88
|
+
Then the file "current_translations.yml" should contain "Tools & Utilities: Outils & Utilitaires"
|
89
|
+
And the file "current_translations.yml" should contain "categories: Catégories"
|
data/lib/banyan.rb
CHANGED
@@ -8,6 +8,8 @@ module Banyan
|
|
8
8
|
autoload :Categorization, "#{ROOT}/banyan/categorization"
|
9
9
|
autoload :Category, "#{ROOT}/banyan/category"
|
10
10
|
autoload :CategoryGroup, "#{ROOT}/banyan/category_group"
|
11
|
+
|
12
|
+
require "#{ROOT}/banyan/railtie" if defined?(Rails)
|
11
13
|
end
|
12
14
|
|
13
15
|
ActiveRecord::Base.class_eval { include Banyan::Categorizable }
|
data/lib/banyan/tasks.rb
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'rake'
|
2
|
+
|
3
|
+
module Banyan
|
4
|
+
class Tasks
|
5
|
+
include ::Rake::DSL
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
define_tasks
|
9
|
+
end
|
10
|
+
|
11
|
+
def define_tasks
|
12
|
+
namespace :translations do
|
13
|
+
namespace :categories do
|
14
|
+
desc "export data into yml file"
|
15
|
+
task :export, [:full_filename] => :environment do |t, args|
|
16
|
+
args.with_defaults(full_filename: "current_translations.yml")
|
17
|
+
filename = args[:full_filename] || 'current_translations.yml'
|
18
|
+
|
19
|
+
hash_categorygroup_translations = {}
|
20
|
+
I18n.available_locales.each do |l|
|
21
|
+
cg_translations = Banyan::CategoryGroup::Translation.select('banyan_category_group_id, name').where(locale: l)
|
22
|
+
hash_categorygroup_translations[l.to_s] = cg_translations.each_with_object({}) do |cgt,h|
|
23
|
+
banyan_category_group = Banyan::CategoryGroup.find cgt.banyan_category_group_id
|
24
|
+
h[banyan_category_group.tag] = cgt.name
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
hash_category_translations = {}
|
29
|
+
I18n.available_locales.each do |l|
|
30
|
+
cat_translations = Banyan::Category::Translation.select('banyan_category_id, name').where(locale: l)
|
31
|
+
hash_category_translations[l.to_s] = cat_translations.each_with_object({}) do |ct,h|
|
32
|
+
banyan_category = Banyan::Category.find ct.banyan_category_id
|
33
|
+
h[banyan_category.tag] = ct.name
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
File.open("#{Rails.root}/#{filename}", 'w') do |file|
|
38
|
+
file.puts({'banyan_category_group_translations' => hash_categorygroup_translations,
|
39
|
+
'banyan_category_translations' => hash_category_translations }.to_yaml)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
desc "import translations from yml file"
|
44
|
+
task :import, [:full_filename] => :environment do |t, args|
|
45
|
+
args.with_defaults(full_filename: "new_translations.yml")
|
46
|
+
filename = args[:full_filename] || 'new_translations.yml'
|
47
|
+
|
48
|
+
counter = 0
|
49
|
+
yf = File.open("#{Rails.root}/#{filename}", "r")
|
50
|
+
ydata = YAML.load_file(yf)
|
51
|
+
|
52
|
+
ydata.each do |(kind,node)|
|
53
|
+
if kind == 'banyan_category_group_translations'
|
54
|
+
puts I18n.available_locales.inspect
|
55
|
+
I18n.available_locales.each do |l|
|
56
|
+
if node[l.to_s]
|
57
|
+
hash = node[l.to_s]
|
58
|
+
hash.each_pair do |key, value|
|
59
|
+
banyan_category_groups = Banyan::CategoryGroup.where(tag: key)
|
60
|
+
banyan_category_groups.each do |banyan_category_group|
|
61
|
+
banyan_category_group_translation = Array(banyan_category_group.translations.find_or_create_by_locale(l)).first
|
62
|
+
if banyan_category_group_translation
|
63
|
+
banyan_category_group_translation.attributes= {name: value}
|
64
|
+
if banyan_category_group_translation.changed? && banyan_category_group_translation.save!
|
65
|
+
counter += 1
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
elsif kind == 'banyan_category_translations'
|
73
|
+
I18n.available_locales.each do |l|
|
74
|
+
if node[l.to_s]
|
75
|
+
hash = node[l.to_s]
|
76
|
+
hash.each_pair do |key, value|
|
77
|
+
banyan_categories = Banyan::Category.where(tag: key)
|
78
|
+
banyan_categories.each do |banyan_category|
|
79
|
+
banyan_category_translation = Array(banyan_category.translations.find_or_create_by_locale(l)).first
|
80
|
+
if banyan_category_translation
|
81
|
+
banyan_category_translation.attributes = {name: value}
|
82
|
+
if banyan_category_translation.changed? && banyan_category_translation.save!
|
83
|
+
counter += 1
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
puts "Updated #{counter} translations"
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
data/lib/banyan/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: banyan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bernard Potocki
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-09-
|
12
|
+
date: 2013-09-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -54,33 +54,33 @@ dependencies:
|
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '2.0'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
|
-
name:
|
57
|
+
name: aruba
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
60
|
- - ~>
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: '
|
62
|
+
version: '0.5'
|
63
63
|
type: :development
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
67
|
- - ~>
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: '
|
69
|
+
version: '0.5'
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
|
-
name:
|
71
|
+
name: database_cleaner
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
|
-
- -
|
74
|
+
- - <
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
-
version:
|
76
|
+
version: 1.1.0
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
|
-
- -
|
81
|
+
- - <
|
82
82
|
- !ruby/object:Gem::Version
|
83
|
-
version:
|
83
|
+
version: 1.1.0
|
84
84
|
- !ruby/object:Gem::Dependency
|
85
85
|
name: factory_girl
|
86
86
|
requirement: !ruby/object:Gem::Requirement
|
@@ -96,19 +96,33 @@ dependencies:
|
|
96
96
|
- !ruby/object:Gem::Version
|
97
97
|
version: '4.2'
|
98
98
|
- !ruby/object:Gem::Dependency
|
99
|
-
name:
|
99
|
+
name: rspec-rails
|
100
100
|
requirement: !ruby/object:Gem::Requirement
|
101
101
|
requirements:
|
102
|
-
- -
|
102
|
+
- - ~>
|
103
103
|
- !ruby/object:Gem::Version
|
104
|
-
version:
|
104
|
+
version: '2.6'
|
105
105
|
type: :development
|
106
106
|
prerelease: false
|
107
107
|
version_requirements: !ruby/object:Gem::Requirement
|
108
108
|
requirements:
|
109
|
-
- -
|
109
|
+
- - ~>
|
110
110
|
- !ruby/object:Gem::Version
|
111
|
-
version:
|
111
|
+
version: '2.6'
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: sqlite3
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ~>
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '1.3'
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ~>
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '1.3'
|
112
126
|
description:
|
113
127
|
email:
|
114
128
|
- bernard.potocki@rebased.pl
|
@@ -123,11 +137,16 @@ files:
|
|
123
137
|
- README.md
|
124
138
|
- Rakefile
|
125
139
|
- banyan.gemspec
|
140
|
+
- features/step_definitions/translation_import_and_export_steps.rb
|
141
|
+
- features/support/env.rb
|
142
|
+
- features/translation_import_and_export.feature
|
126
143
|
- lib/banyan.rb
|
127
144
|
- lib/banyan/categorizable.rb
|
128
145
|
- lib/banyan/categorization.rb
|
129
146
|
- lib/banyan/category.rb
|
130
147
|
- lib/banyan/category_group.rb
|
148
|
+
- lib/banyan/railtie.rb
|
149
|
+
- lib/banyan/tasks.rb
|
131
150
|
- lib/banyan/version.rb
|
132
151
|
- lib/generators/banyan/banyan_generator.rb
|
133
152
|
- lib/generators/banyan/templates/migration.rb
|
@@ -170,6 +189,9 @@ signing_key:
|
|
170
189
|
specification_version: 4
|
171
190
|
summary: Pluggable categories and category groups to ActiveRecord models
|
172
191
|
test_files:
|
192
|
+
- features/step_definitions/translation_import_and_export_steps.rb
|
193
|
+
- features/support/env.rb
|
194
|
+
- features/translation_import_and_export.feature
|
173
195
|
- spec/banyan/banyan_category_group_spec.rb
|
174
196
|
- spec/banyan/banyan_category_spec.rb
|
175
197
|
- spec/banyan/banyan_group_model_spec.rb
|