lolita-i18n 0.4.3 → 0.5.1

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: bbe2673c732802ba0079e01909b9cd61c242ba22
4
+ data.tar.gz: be7ccaad2c86382b09c42cb81e645461a04cd3df
5
+ SHA512:
6
+ metadata.gz: cdc8d31fdab9fa41d3eb412cbfcb1a12f95661ea03dd858ae30b77d00464dbceb5c81601d9ac6c39bf8b36de6bbaa89fad6ca8c3b606be6a629f0619b4fb762d
7
+ data.tar.gz: 0b5cc46476c14cf6b169f78adc59f07a5bbbda74eb94a05a668f94e7881886e3260faa1d2495f143a4bc2ad24314ef6283989ef8d0652a18d41b356445efbd39
data/Gemfile CHANGED
@@ -1,15 +1,16 @@
1
- source "http://rubygems.org"
1
+ source 'http://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
5
  group :test do
6
- gem "debugger"
7
- gem "rails", "~>3.2.2"
8
- gem "cover_me", "~>1.2.0"
9
- gem "bson_ext", "~>1.6.2"
10
- gem "mongoid", "~>2.4.8"
11
- gem "rspec-rails", "~>2.11.0"
12
- gem "capybara", "~> 1.1.3"
13
- gem "sass", "~>3.2.3"
14
- gem "coffee-script", "~>2.2.0"
15
- end
6
+ gem 'byebug'
7
+ gem 'rails', '~> 3.2.0'
8
+ gem 'simplecov', '~> 0.7.1'
9
+ gem 'bson_ext', '~> 1.9.0'
10
+ gem 'mongoid', '~> 2.7.1'
11
+ gem 'rspec-rails', '~> 2.14'
12
+ gem 'capybara', '~> 2.1'
13
+ gem 'selenium-webdriver', '~> 2.33.0'
14
+ gem 'sass', '~> 3.2.3'
15
+ gem 'coffee-script', '~>2.2.0'
16
+ end
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # About
2
2
 
3
- Lolita I18n is Lolita[https://github.com/ithouse/lolita] plugin, that enables .yml file translation from WEB interface.
3
+ Lolita I18n is [Lolita](https://github.com/ithouse/lolita) plugin, that enables .yml file translation from WEB interface.
4
4
 
5
5
  ## Usage
6
6
 
7
- * setup rails >3.1 project with ["Lolita"](https://github.com/ithouse/lolita)
7
+ * setup rails 3.2+ project with ["Lolita"](https://github.com/ithouse/lolita)
8
8
  * setup [Redis DB](http://redis.io) on your server
9
9
  * add `gem 'lolita-i18n'` into Gemfile
10
10
  * in your lolita setup block add `config.i18n.store = {:db => REDIS_DB}` or `config.i18n.store = Redis.new`
@@ -8,7 +8,7 @@ module Lolita
8
8
  if Lolita.rails3?
9
9
  require 'lolita-i18n/rails'
10
10
  end
11
- end
11
+ end
12
12
  # Rerturn existing store or create new Redis connection without any arguments.
13
13
  def store
14
14
  unless @store
@@ -42,7 +42,7 @@ module Lolita
42
42
  def initialize_chain
43
43
  ::I18n::Backend::Chain.new(self.backend, self.yaml_backend)
44
44
  end
45
-
45
+
46
46
  def init
47
47
  unless @initialized
48
48
  include_modules
@@ -64,17 +64,17 @@ module Lolita
64
64
  else
65
65
  disconnect
66
66
  @connected = begin
67
- connection = Redis.new
68
- connection.ping
67
+ store.client.reconnect
68
+ store.ping
69
69
  ::I18n.backend = initialize_chain
70
70
  true
71
71
  rescue Errno::ECONNREFUSED => e
72
72
  warn "Warning: Lolita was unable to connect to Redis DB: #{e}"
73
73
  false
74
- end
74
+ end
75
75
  end
76
76
  end
77
-
77
+
78
78
  def disconnect
79
79
  if @connected
80
80
  store.client.disconnect
@@ -90,7 +90,6 @@ module Lolita
90
90
  def include_modules
91
91
  ::I18n::Backend::Simple.send(:include, ::I18n::Backend::Flatten)
92
92
  ::I18n::Backend::Simple.send(:include, ::I18n::Backend::Pluralization)
93
- ::I18n::Backend::Simple.send(:include, ::I18n::Backend::Metadata)
94
93
  ::I18n::Backend::Simple.send(:include, ::I18n::Backend::InterpolationCompiler)
95
94
  end
96
95
  end
@@ -22,7 +22,7 @@ module Lolita
22
22
  def validate_array(key,values)
23
23
  translation = Translation.new(key,values)
24
24
  if translation.original.class != values.class || translation.original.size != values.size
25
- raise Exceptions::TranslationDoesNotMatch.new(values,translation.original)
25
+ raise Exceptions::TranslationDoesNotMatch.new(values,translation.original)
26
26
  end
27
27
  values.each_with_index do |value,index|
28
28
  validate_value(key,value,:index => index)
@@ -32,7 +32,7 @@ module Lolita
32
32
  def validate_hash(key,hash)
33
33
  translation = Translation.new(key,hash)
34
34
  if translation.original.class != hash.class || (hash.keys.map(&:to_sym) - translation.original.keys).any?
35
- raise Exceptions::TranslationDoesNotMatch.new(hash,translation.original)
35
+ raise Exceptions::TranslationDoesNotMatch.new(hash,translation.original)
36
36
  end
37
37
  hash.each do |hash_key,value|
38
38
  validate_value(key,value, :key => hash_key)
@@ -40,7 +40,7 @@ module Lolita
40
40
  end
41
41
 
42
42
  def validate_value(key,value, options = {})
43
- value = value.to_s
43
+ value = value.to_s
44
44
  original_value = current_value_for_original(key,value,options)
45
45
  unless interpolations(value) == interpolations(original_value)
46
46
  raise Exceptions::MissingInterpolationArgument.new(interpolations(original_value))
@@ -101,6 +101,7 @@ module Lolita
101
101
 
102
102
  class Translations
103
103
  def initialize(translations_hash)
104
+ translations_hash.delete(:'i18n')
104
105
  @translations = translations_hash
105
106
  end
106
107
 
@@ -126,8 +127,8 @@ module Lolita
126
127
  end
127
128
 
128
129
  def final_value?(value)
129
- !value.is_a?(Hash) ||
130
- (value.is_a?(Hash) && value.keys.map(&:to_sym).include?(:other) && value.keys.size > 1 && !value.values.detect{|value| value.is_a?(Array) || value.is_a?(Hash)})
130
+ !value.is_a?(Hash) ||
131
+ (value.is_a?(Hash) && value.keys.map(&:to_sym).include?(:other) && value.keys.size > 1 && !value.values.detect{|value| value.is_a?(Array) || value.is_a?(Hash)})
131
132
  end
132
133
 
133
134
  def translation_value key, value, locale
@@ -166,7 +167,7 @@ module Lolita
166
167
 
167
168
  def translations locale
168
169
  Lolita.i18n.load_translations
169
- translations = Translations.new(Lolita.i18n.yaml_backend.send(:translations)[::I18n.default_locale])
170
+ translations = Translations.new(Lolita.i18n.yaml_backend.send(:translations)[::I18n.default_locale])
170
171
  translations.normalized(locale)
171
172
  end
172
173
 
@@ -194,11 +195,7 @@ module Lolita
194
195
  @validator ||= Validator.new()
195
196
  end
196
197
 
197
- def del key
198
- Lolita.i18n.store.del key
199
- end
200
-
201
- private
198
+ private
202
199
 
203
200
  def both_values_complex?(value_a, value_b)
204
201
  (value_a.is_a?(Hash) || value_a.is_a?(Array)) && [Array,Hash].include?(value_b.class)
@@ -207,7 +204,7 @@ module Lolita
207
204
  def complex_value?(value_a, value_b)
208
205
  (value_a.is_a?(Hash) || value_a.is_a?(Array)) && ![Array,Hash].include?(value_b.class)
209
206
  end
210
-
207
+
211
208
  def set(key,value)
212
209
  translation = Translation.new(key,value)
213
210
  validator.validate(key,translation.value)
@@ -216,4 +213,4 @@ module Lolita
216
213
 
217
214
  end
218
215
  end
219
- end
216
+ end
@@ -1,7 +1,7 @@
1
1
  module Lolita
2
2
  module I18n
3
3
  class Version
4
- VERSION = "0.4.3"
4
+ VERSION = "0.5.1"
5
5
 
6
6
  def self.to_s
7
7
  VERSION
data/lolita-i18n.gemspec CHANGED
@@ -18,12 +18,12 @@ Gem::Specification.new do |s|
18
18
  ]
19
19
  s.licenses = ["MIT"]
20
20
 
21
- s.add_runtime_dependency(%q<lolita>, ["~> 3.2.0.rc.9"])
22
- s.add_runtime_dependency(%q<hiredis>, ["~> 0.3.1"])
23
- s.add_runtime_dependency(%q<redis>, ["~> 2.2.2"])
24
- s.add_runtime_dependency(%q<yajl-ruby>,["~> 1.0.0"])
25
- s.add_runtime_dependency(%q<unicode_utils>,["~> 1.3.0"])
26
-
21
+ s.add_runtime_dependency(%q<lolita>, ["~> 3.2"])
22
+ s.add_runtime_dependency(%q<i18n>, ["= 0.6.4"])
23
+ #s.add_runtime_dependency(%q<hiredis>, ["~> 0.4.5"])
24
+ s.add_runtime_dependency(%q<redis>, ["~> 3.0.3"])
25
+ s.add_runtime_dependency(%q<yajl-ruby>,["~> 1.1.0"])
26
+ s.add_runtime_dependency(%q<unicode_utils>,["~> 1.4.0"])
27
27
  s.files = `git ls-files`.split("\n")
28
28
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
29
29
  s.require_paths = ["lib"]
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Lolita::I18nController, :rails => true do
3
+ describe Lolita::I18nController do
4
4
 
5
5
  describe "GET index" do
6
6
  it "should authorize resource" do
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Translating process", :rails => true do
3
+ describe "Translating process" do
4
4
  def translate_key(key)
5
5
  page.should have_selector("textarea[name='#{key}']")
6
6
  fill_in(key, :with => "translation for #{key}")
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Viewing all translations", :rails => true, :redis => true, :js => true do
3
+ describe "Viewing all translations", :redis => true, :js => true do
4
4
  before(:each) do
5
5
  visit "/lolita/i18n"
6
6
  end
@@ -1,57 +1,57 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Lolita::I18n::Configuration do
3
+ describe Lolita::I18n::Configuration do
4
4
  subject { described_class.new }
5
- let(:redis){ double("redis", :ping => true) }
5
+ let(:redis){ double("redis", :ping => true, client: double(disconnect: true, reconnect: true)) }
6
6
 
7
- it "should load rails if Rails is defined" do
7
+ it "should load rails if Rails is defined" do
8
8
  Lolita.stub(:rails3?).and_return(true)
9
9
  subject.should_receive(:require).with('lolita-i18n/rails')
10
10
  subject.load_rails!
11
11
  end
12
12
 
13
- it "should allow to assign store with Hash as connection options" do
13
+ it "should allow to assign store with Hash as connection options" do
14
14
  Redis.should_receive(:new).with({:key => "value"}).and_return(redis)
15
15
  subject.store = {:key => "value"}
16
16
  end
17
17
 
18
- it "should allow to assign store as store itself" do
19
- subject.store = redis
18
+ it "should allow to assign store as store itself" do
19
+ subject.store = redis
20
20
  subject.store.should eq(redis)
21
21
  end
22
22
 
23
- it "should return assigned store" do
23
+ it "should return assigned store" do
24
24
  subject.store = redis
25
25
  subject.store.should eq(redis)
26
26
  end
27
27
 
28
- it "should return new Redis connection and warn when no store is assigned" do
28
+ it "should return new Redis connection and warn when no store is assigned" do
29
29
  Redis.should_receive(:new).and_return(redis)
30
30
  subject.should_receive(:warn).with("Lolita::I18n No store specified. See Lolita::I18n")
31
31
  subject.store.should eq(redis)
32
32
  end
33
33
 
34
- it "should lazy create and return backend" do
34
+ it "should lazy create and return backend" do
35
35
  Redis.should_receive(:new).and_return(redis)
36
36
  ::I18n::Backend::KeyValue.should_receive(:new).with(redis)
37
37
  subject.backend
38
38
  end
39
39
 
40
- it "should load translations" do
40
+ it "should load translations" do
41
41
  yaml_backend = double("yaml_backend")
42
42
  subject.yaml_backend = yaml_backend
43
43
  yaml_backend.should_receive(:load_translations)
44
44
  subject.load_translations
45
45
  end
46
46
 
47
- it "should initialize chain" do
47
+ it "should initialize chain" do
48
48
  subject.yaml_backend = double("yaml backend")
49
49
  Redis.stub(:new).and_return(redis)
50
50
  ::I18n::Backend::Chain.should_receive(:new).with(subject.backend,subject.yaml_backend)
51
51
  subject.initialize_chain
52
52
  Redis.unstub(:new)
53
53
  end
54
-
54
+
55
55
  describe "#connect" do
56
56
  before(:each){ Redis.stub(:new).and_return(redis) }
57
57
  after(:each){ Redis.unstub(:new) }
@@ -71,7 +71,7 @@ describe Lolita::I18n::Configuration do
71
71
  subject.connect.should_not be_true
72
72
  end
73
73
  end
74
-
74
+
75
75
  describe "#reconnect" do
76
76
  it "should call init if not initialized jet" do
77
77
  subject.should_receive(:init).once
@@ -105,10 +105,10 @@ describe Lolita::I18n::Configuration do
105
105
  subject.reconnect
106
106
  end
107
107
  end
108
-
108
+
109
109
  describe "#disconnect" do
110
110
  it "should disconnect if connected" do
111
- subject.store.client.should_receive(:disconnect)
111
+ subject.store.client.should_receive(:disconnect).twice
112
112
  subject.connect
113
113
  subject.disconnect
114
114
  end
@@ -135,13 +135,12 @@ describe Lolita::I18n::Configuration do
135
135
  subject.init
136
136
  end
137
137
  end
138
-
138
+
139
139
  describe "#include_modules" do
140
- it "include module in ::I18n::Backend::Simple" do
140
+ it "include module in ::I18n::Backend::Simple" do
141
141
  subject.include_modules
142
142
  ::I18n::Backend::Simple.ancestors.should include(::I18n::Backend::Flatten)
143
143
  ::I18n::Backend::Simple.ancestors.should include(::I18n::Backend::Pluralization)
144
- ::I18n::Backend::Simple.ancestors.should include(::I18n::Backend::Metadata)
145
144
  ::I18n::Backend::Simple.ancestors.should include(::I18n::Backend::InterpolationCompiler)
146
145
  end
147
146
  end
data/spec/spec_helper.rb CHANGED
@@ -1,16 +1,10 @@
1
1
  require 'rubygems'
2
2
  require 'bundler'
3
- require 'cover_me'
4
3
 
5
- CoverMe.config do |c|
6
- # where is your project's root:
7
- c.project.root = File.expand_path("../lolita-i18n") # => "Rails.root" (default)
8
-
9
- # what files are you interested in coverage for:
10
- c.file_pattern = [
11
- /(#{CoverMe.config.project.root}\/app\/.+\.rb)/i,
12
- /(#{CoverMe.config.project.root}\/lib\/.+\.rb)/i
13
- ]
4
+ # run simplecov only wehen all tests are executed
5
+ if ARGV.empty? || ARGV.include?("spec")
6
+ require 'simplecov'
7
+ SimpleCov.start 'rails'
14
8
  end
15
9
 
16
10
  REQUIRE_RAILS = true # turn of to run lolita-i18n tests fast
@@ -28,15 +22,11 @@ if REQUIRE_RAILS
28
22
  require 'rails_spec_helper'
29
23
  end
30
24
  require File.expand_path('lib/lolita-i18n')
31
-
25
+
32
26
  RSpec.configure do |config|
33
27
  config.treat_symbols_as_metadata_keys_with_true_values = true
34
28
  config.mock_with :rspec
35
- config.before(:each,:redis) do
29
+ config.before(:each, :redis) do
36
30
  Lolita.i18n.store.flushdb
37
31
  end
38
- end
39
-
40
- at_exit do
41
- CoverMe.complete! if 1==1
42
32
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lolita-i18n
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
5
- prerelease:
4
+ version: 0.5.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - ITHouse (Latvia)
@@ -11,88 +10,78 @@ authors:
11
10
  autorequire:
12
11
  bindir: bin
13
12
  cert_chain: []
14
- date: 2012-11-21 00:00:00.000000000 Z
13
+ date: 2013-07-09 00:00:00.000000000 Z
15
14
  dependencies:
16
15
  - !ruby/object:Gem::Dependency
17
16
  name: lolita
18
17
  requirement: !ruby/object:Gem::Requirement
19
- none: false
20
18
  requirements:
21
19
  - - ~>
22
20
  - !ruby/object:Gem::Version
23
- version: 3.2.0.rc.9
21
+ version: '3.2'
24
22
  type: :runtime
25
23
  prerelease: false
26
24
  version_requirements: !ruby/object:Gem::Requirement
27
- none: false
28
25
  requirements:
29
26
  - - ~>
30
27
  - !ruby/object:Gem::Version
31
- version: 3.2.0.rc.9
28
+ version: '3.2'
32
29
  - !ruby/object:Gem::Dependency
33
- name: hiredis
30
+ name: i18n
34
31
  requirement: !ruby/object:Gem::Requirement
35
- none: false
36
32
  requirements:
37
- - - ~>
33
+ - - '='
38
34
  - !ruby/object:Gem::Version
39
- version: 0.3.1
35
+ version: 0.6.4
40
36
  type: :runtime
41
37
  prerelease: false
42
38
  version_requirements: !ruby/object:Gem::Requirement
43
- none: false
44
39
  requirements:
45
- - - ~>
40
+ - - '='
46
41
  - !ruby/object:Gem::Version
47
- version: 0.3.1
42
+ version: 0.6.4
48
43
  - !ruby/object:Gem::Dependency
49
44
  name: redis
50
45
  requirement: !ruby/object:Gem::Requirement
51
- none: false
52
46
  requirements:
53
47
  - - ~>
54
48
  - !ruby/object:Gem::Version
55
- version: 2.2.2
49
+ version: 3.0.3
56
50
  type: :runtime
57
51
  prerelease: false
58
52
  version_requirements: !ruby/object:Gem::Requirement
59
- none: false
60
53
  requirements:
61
54
  - - ~>
62
55
  - !ruby/object:Gem::Version
63
- version: 2.2.2
56
+ version: 3.0.3
64
57
  - !ruby/object:Gem::Dependency
65
58
  name: yajl-ruby
66
59
  requirement: !ruby/object:Gem::Requirement
67
- none: false
68
60
  requirements:
69
61
  - - ~>
70
62
  - !ruby/object:Gem::Version
71
- version: 1.0.0
63
+ version: 1.1.0
72
64
  type: :runtime
73
65
  prerelease: false
74
66
  version_requirements: !ruby/object:Gem::Requirement
75
- none: false
76
67
  requirements:
77
68
  - - ~>
78
69
  - !ruby/object:Gem::Version
79
- version: 1.0.0
70
+ version: 1.1.0
80
71
  - !ruby/object:Gem::Dependency
81
72
  name: unicode_utils
82
73
  requirement: !ruby/object:Gem::Requirement
83
- none: false
84
74
  requirements:
85
75
  - - ~>
86
76
  - !ruby/object:Gem::Version
87
- version: 1.3.0
77
+ version: 1.4.0
88
78
  type: :runtime
89
79
  prerelease: false
90
80
  version_requirements: !ruby/object:Gem::Requirement
91
- none: false
92
81
  requirements:
93
82
  - - ~>
94
83
  - !ruby/object:Gem::Version
95
- version: 1.3.0
84
+ version: 1.4.0
96
85
  description: Lolita plugin, that enables .yml files management from administrative
97
86
  interface. Also faster access to translations, that DB store
98
87
  email: support@ithouse.lv
@@ -130,6 +119,8 @@ files:
130
119
  - lib/lolita-i18n/version.rb
131
120
  - lolita-i18n.gemspec
132
121
  - spec/controllers/lolita/i18n_controller_spec.rb
122
+ - spec/features/translating_spec.rb
123
+ - spec/features/translation_list_spec.rb
133
124
  - spec/helpers/lolita/i18n_helper_spec.rb
134
125
  - spec/lolita-i18n/configuration_spec.rb
135
126
  - spec/lolita-i18n/exceptions_spec.rb
@@ -137,8 +128,6 @@ files:
137
128
  - spec/lolita-i18n/version_spec.rb
138
129
  - spec/lolita_i18n_spec.rb
139
130
  - spec/rails_spec_helper.rb
140
- - spec/requests/translating_spec.rb
141
- - spec/requests/translation_list_spec.rb
142
131
  - spec/routing/routes_spec.rb
143
132
  - spec/spec_helper.rb
144
133
  - spec/test_app/app/controllers/application_controller.rb
@@ -157,26 +146,50 @@ files:
157
146
  homepage: http://github.com/ithouse/lolita-i18n
158
147
  licenses:
159
148
  - MIT
149
+ metadata: {}
160
150
  post_install_message:
161
151
  rdoc_options: []
162
152
  require_paths:
163
153
  - lib
164
154
  required_ruby_version: !ruby/object:Gem::Requirement
165
- none: false
166
155
  requirements:
167
- - - ! '>='
156
+ - - '>='
168
157
  - !ruby/object:Gem::Version
169
158
  version: '0'
170
159
  required_rubygems_version: !ruby/object:Gem::Requirement
171
- none: false
172
160
  requirements:
173
- - - ! '>='
161
+ - - '>='
174
162
  - !ruby/object:Gem::Version
175
163
  version: '0'
176
164
  requirements: []
177
165
  rubyforge_project:
178
- rubygems_version: 1.8.24
166
+ rubygems_version: 2.0.3
179
167
  signing_key:
180
- specification_version: 3
168
+ specification_version: 4
181
169
  summary: Lolita plugin, that enables .yml management
182
- test_files: []
170
+ test_files:
171
+ - spec/controllers/lolita/i18n_controller_spec.rb
172
+ - spec/features/translating_spec.rb
173
+ - spec/features/translation_list_spec.rb
174
+ - spec/helpers/lolita/i18n_helper_spec.rb
175
+ - spec/lolita-i18n/configuration_spec.rb
176
+ - spec/lolita-i18n/exceptions_spec.rb
177
+ - spec/lolita-i18n/request_spec.rb
178
+ - spec/lolita-i18n/version_spec.rb
179
+ - spec/lolita_i18n_spec.rb
180
+ - spec/rails_spec_helper.rb
181
+ - spec/routing/routes_spec.rb
182
+ - spec/spec_helper.rb
183
+ - spec/test_app/app/controllers/application_controller.rb
184
+ - spec/test_app/config/application.rb
185
+ - spec/test_app/config/boot.rb
186
+ - spec/test_app/config/enviroment.rb
187
+ - spec/test_app/config/enviroments/test.rb
188
+ - spec/test_app/config/initializers/lolita_i18n.rb
189
+ - spec/test_app/config/initializers/token.rb
190
+ - spec/test_app/config/locales/en.yml
191
+ - spec/test_app/config/locales/lv.yml
192
+ - spec/test_app/config/locales/ru.yml
193
+ - spec/test_app/config/mongoid.yml
194
+ - spec/test_app/config/routes.rb
195
+ - spec/test_app/log/.gitkeep