rails-i18nterface 0.1.3 → 0.1.4

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.
@@ -46,7 +46,7 @@ describe RailsI18nterface::Keys do
46
46
  describe "missing_keys" do
47
47
  before(:each) do
48
48
  @file_path = File.join(i18n_files_dir, "config", "locales", "en.yml")
49
- RailsI18nterface::File.new(@file_path).write({
49
+ RailsI18nterface::Yamlfile.new(@file_path).write({
50
50
  :en => {
51
51
  :home => {
52
52
  :page_title => false,
data/spec/lib/log_spec.rb CHANGED
@@ -19,7 +19,7 @@ describe RailsI18nterface::Log do
19
19
  File.exists?(file_path).should be_false
20
20
  @log.write_to_file
21
21
  File.exists?(file_path).should be_true
22
- RailsI18nterface::File.new(file_path).read.should == RailsI18nterface::File.deep_stringify_keys(from_texts)
22
+ RailsI18nterface::Yamlfile.new(file_path).read.should == RailsI18nterface::Yamlfile.new(nil).deep_stringify_keys(from_texts)
23
23
  end
24
24
 
25
25
  it "merges from texts with current texts in log file and re-writes the log file" do
@@ -27,7 +27,7 @@ describe RailsI18nterface::Log do
27
27
  I18n.backend.store_translations(:sv, {:category => "Kategori ny"})
28
28
  @log.keys = ['category']
29
29
  @log.write_to_file
30
- RailsI18nterface::File.new(file_path).read['category'].should == "Kategori ny"
30
+ RailsI18nterface::Yamlfile.new(file_path).read['category'].should == "Kategori ny"
31
31
  end
32
32
 
33
33
  def file_path
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe RailsI18nterface::Sourcefiles do
4
+
5
+ it "grabs field from schema.rb" do
6
+ expected = {
7
+ "activerecord.models.article"=>"db/schema.rb",
8
+ "activerecord.attributes.article.title"=>"db/schema.rb",
9
+ "activerecord.attributes.article.body"=>"db/schema.rb",
10
+ "activerecord.attributes.article.created_at"=>"db/schema.rb",
11
+ "activerecord.attributes.article.updated_at"=>"db/schema.rb",
12
+ "activerecord.attributes.article.active"=>"db/schema.rb",
13
+ "activerecord.models.topics"=>"db/schema.rb",
14
+ "activerecord.attributes.topics.title"=>"db/schema.rb",
15
+ "activerecord.attributes.topics.created_at"=>"db/schema.rb",
16
+ "activerecord.attributes.topics.updated_at"=>"db/schema.rb"
17
+ }
18
+
19
+ hash = RailsI18nterface::Sourcefiles.extract_activerecords
20
+ hash.should == expected
21
+ end
22
+
23
+ end
@@ -11,7 +11,7 @@ describe RailsI18nterface::Storage do
11
11
  @storage.stub!(:file_path).and_return(file_path)
12
12
  file = mock(:file)
13
13
  file.should_receive(:write).with(translations)
14
- RailsI18nterface::File.should_receive(:new).with(file_path).and_return(file)
14
+ RailsI18nterface::Yamlfile.should_receive(:new).with(file_path).and_return(file)
15
15
  @storage.write_to_file
16
16
  end
17
17
 
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe RailsI18nterface::Utils do
4
+ include RailsI18nterface::Utils
5
+
6
+ it "Removes blanks from a hash" do
7
+ hash = { a: 'a', b: { ba: '', bb: 'bb'}, c: '', d: { }, e: { ea: 'ee', eb: { } } }
8
+ expected = { a: 'a', b: { bb: 'bb'}, e: { ea: 'ee' } }
9
+ remove_blanks(hash).should == expected
10
+ end
11
+
12
+ it 'set nested transform a split of dotted flat string to a nested hash' do
13
+ hash = { a: { aa: 'aa' }, b: '', c: { ca: { caa: 'caa' } }, d: 'd' }
14
+ expected = { a: { aa: 'aa' }, b: '', c: { ca: { caa: 'caa', cab: 'cab' } }, d: 'd' }
15
+ set_nested(hash, [:c, :ca, :cab], 'cab')
16
+ hash.should == expected
17
+ end
18
+
19
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe RailsI18nterface::Yamlfile do
4
+
5
+ before :each do
6
+ @translations = { en: { a: { aa: 'aa' }, b: 'b' } }
7
+ end
8
+
9
+ describe "write" do
10
+ before(:each) do
11
+ @file_path = File.join(File.dirname(__FILE__), "files", "en.yml")
12
+ @file = RailsI18nterface::Yamlfile.new(@file_path)
13
+ end
14
+
15
+ after(:each) do
16
+ FileUtils.rm(@file_path)
17
+ end
18
+
19
+ it "writes all I18n messages for a locale to YAML file" do
20
+ @file.write(@translations)
21
+ @file.read.should == RailsI18nterface::Yamlfile.new(nil).deep_stringify_keys(@translations)
22
+ end
23
+
24
+ end
25
+
26
+ describe "deep_stringify_keys" do
27
+ it "should convert all keys in a hash to strings" do
28
+ expected = { 'en' => { 'a' => { 'aa' => 'aa' }, 'b' => 'b' } }
29
+ RailsI18nterface::Yamlfile.new(nil).deep_stringify_keys(@translations).should == expected
30
+ end
31
+ end
32
+
33
+ end
metadata CHANGED
@@ -1,46 +1,52 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-i18nterface
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Mose
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-04-16 00:00:00.000000000 Z
12
+ date: 2013-04-21 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: rails
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
- - - '>='
19
+ - - ! '>='
18
20
  - !ruby/object:Gem::Version
19
21
  version: 3.1.0
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
- - - '>='
27
+ - - ! '>='
25
28
  - !ruby/object:Gem::Version
26
29
  version: 3.1.0
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: sqlite3
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
- - - '>='
35
+ - - ! '>='
32
36
  - !ruby/object:Gem::Version
33
37
  version: '0'
34
38
  type: :development
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
- - - '>='
43
+ - - ! '>='
39
44
  - !ruby/object:Gem::Version
40
45
  version: '0'
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: combustion
43
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
44
50
  requirements:
45
51
  - - ~>
46
52
  - !ruby/object:Gem::Version
@@ -48,6 +54,7 @@ dependencies:
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
51
58
  requirements:
52
59
  - - ~>
53
60
  - !ruby/object:Gem::Version
@@ -55,6 +62,7 @@ dependencies:
55
62
  - !ruby/object:Gem::Dependency
56
63
  name: rspec
57
64
  requirement: !ruby/object:Gem::Requirement
65
+ none: false
58
66
  requirements:
59
67
  - - ~>
60
68
  - !ruby/object:Gem::Version
@@ -62,6 +70,7 @@ dependencies:
62
70
  type: :development
63
71
  prerelease: false
64
72
  version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
65
74
  requirements:
66
75
  - - ~>
67
76
  - !ruby/object:Gem::Version
@@ -69,6 +78,7 @@ dependencies:
69
78
  - !ruby/object:Gem::Dependency
70
79
  name: rspec-rails
71
80
  requirement: !ruby/object:Gem::Requirement
81
+ none: false
72
82
  requirements:
73
83
  - - ~>
74
84
  - !ruby/object:Gem::Version
@@ -76,6 +86,7 @@ dependencies:
76
86
  type: :development
77
87
  prerelease: false
78
88
  version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
79
90
  requirements:
80
91
  - - ~>
81
92
  - !ruby/object:Gem::Version
@@ -83,15 +94,17 @@ dependencies:
83
94
  - !ruby/object:Gem::Dependency
84
95
  name: capybara
85
96
  requirement: !ruby/object:Gem::Requirement
97
+ none: false
86
98
  requirements:
87
- - - '>='
99
+ - - ! '>='
88
100
  - !ruby/object:Gem::Version
89
101
  version: '0'
90
102
  type: :development
91
103
  prerelease: false
92
104
  version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
93
106
  requirements:
94
- - - '>='
107
+ - - ! '>='
95
108
  - !ruby/object:Gem::Version
96
109
  version: '0'
97
110
  description: A rails 3.1/4 engine adding an interface for translating and writing
@@ -104,97 +117,104 @@ extra_rdoc_files: []
104
117
  files:
105
118
  - app/helpers/rails_i18nterface/application_helper.rb
106
119
  - app/helpers/rails_i18nterface/translate_helper.rb
107
- - app/models/translation.rb
108
120
  - app/views/layouts/rails_i18nterface/translate.html.erb
121
+ - app/views/rails_i18nterface/translate/_namespaces.html.erb
109
122
  - app/views/rails_i18nterface/translate/index.html.erb
110
123
  - app/views/rails_i18nterface/translate/_pagination.html.erb
111
- - app/views/rails_i18nterface/translate/_namespaces.html.erb
112
- - app/assets/stylesheets/rails_i18nterface/application.css
113
- - app/assets/javascripts/rails_i18nterface/application.js
114
- - app/assets/javascripts/rails_i18nterface/ender.min.js
124
+ - app/models/translation.rb
115
125
  - app/assets/javascripts/rails_i18nterface/ender.js
116
126
  - app/assets/javascripts/rails_i18nterface/base.js
127
+ - app/assets/javascripts/rails_i18nterface/application.js
128
+ - app/assets/javascripts/rails_i18nterface/ender.min.js
129
+ - app/assets/stylesheets/rails_i18nterface/application.css
117
130
  - app/controllers/rails_i18nterface/application_controller.rb
118
131
  - app/controllers/rails_i18nterface/translate_controller.rb
119
132
  - config/routes.rb
120
133
  - db/migrate/20110921112044_create_translations.rb
121
134
  - lib/tasks/rails-i18nterface.rake
122
- - lib/rails-i18nterface/storage.rb
123
- - lib/rails-i18nterface/engine.rb
135
+ - lib/rails-i18nterface.rb
136
+ - lib/rails-i18nterface/keys.rb
137
+ - lib/rails-i18nterface/sourcefiles.rb
124
138
  - lib/rails-i18nterface/log.rb
139
+ - lib/rails-i18nterface/utils.rb
140
+ - lib/rails-i18nterface/engine.rb
141
+ - lib/rails-i18nterface/storage.rb
142
+ - lib/rails-i18nterface/yamlfile.rb
125
143
  - lib/rails-i18nterface/version.rb
126
- - lib/rails-i18nterface/keys.rb
127
- - lib/rails-i18nterface/file.rb
128
- - lib/rails-i18nterface.rb
129
144
  - MIT-LICENSE
130
145
  - Rakefile
131
146
  - README.md
132
- - spec/spec_helper.rb
133
- - spec/internal/log/test.log
134
- - spec/internal/app/models/article.rb
135
- - spec/internal/app/views/application/index.html.erb
136
- - spec/internal/app/views/categories/category.erb
137
- - spec/internal/app/views/categories/category.rhtml
138
- - spec/internal/app/views/categories/category.html.erb
147
+ - spec/internal/public/favicon.ico
139
148
  - spec/internal/app/views/categories/category.html
140
- - spec/internal/app/assets/stylesheets/application.css
149
+ - spec/internal/app/views/categories/category.html.erb
150
+ - spec/internal/app/views/categories/category.rhtml
151
+ - spec/internal/app/views/categories/category.erb
152
+ - spec/internal/app/views/application/index.html.erb
153
+ - spec/internal/app/models/article.rb
141
154
  - spec/internal/app/assets/javascripts/application.js
155
+ - spec/internal/app/assets/stylesheets/application.css
142
156
  - spec/internal/app/controllers/application_controller.rb
143
- - spec/internal/config/database.yml
157
+ - spec/internal/log/test.log
144
158
  - spec/internal/config/routes.rb
159
+ - spec/internal/config/database.yml
145
160
  - spec/internal/db/schema.rb
146
161
  - spec/internal/db/combustion_test.sqlite
147
- - spec/internal/public/favicon.ico
162
+ - spec/requests/search_spec.rb
163
+ - spec/lib/utils_spec.rb
164
+ - spec/lib/storage_spec.rb
165
+ - spec/lib/yamlfile_spec.rb
148
166
  - spec/lib/log_spec.rb
149
167
  - spec/lib/keys_spec.rb
150
- - spec/lib/file_spec.rb
151
- - spec/lib/storage_spec.rb
152
- - spec/requests/search_spec.rb
168
+ - spec/lib/sourcefiles_spec.rb
169
+ - spec/spec_helper.rb
153
170
  - spec/controllers/translate_controller_spec.rb
154
171
  homepage: https://github.com/mose/rails-i18nterface
155
172
  licenses:
156
173
  - MIT
157
- metadata: {}
158
174
  post_install_message:
159
175
  rdoc_options: []
160
176
  require_paths:
161
177
  - lib
162
178
  required_ruby_version: !ruby/object:Gem::Requirement
179
+ none: false
163
180
  requirements:
164
- - - '>='
181
+ - - ! '>='
165
182
  - !ruby/object:Gem::Version
166
183
  version: '0'
167
184
  required_rubygems_version: !ruby/object:Gem::Requirement
185
+ none: false
168
186
  requirements:
169
- - - '>='
187
+ - - ! '>='
170
188
  - !ruby/object:Gem::Version
171
189
  version: '0'
172
190
  requirements: []
173
191
  rubyforge_project:
174
- rubygems_version: 2.0.0.rc.2
192
+ rubygems_version: 1.8.25
175
193
  signing_key:
176
- specification_version: 4
194
+ specification_version: 3
177
195
  summary: A rails 3.1/4 engine for translating in a web page.
178
196
  test_files:
179
- - spec/spec_helper.rb
180
- - spec/internal/log/test.log
181
- - spec/internal/app/models/article.rb
182
- - spec/internal/app/views/application/index.html.erb
183
- - spec/internal/app/views/categories/category.erb
184
- - spec/internal/app/views/categories/category.rhtml
185
- - spec/internal/app/views/categories/category.html.erb
197
+ - spec/internal/public/favicon.ico
186
198
  - spec/internal/app/views/categories/category.html
187
- - spec/internal/app/assets/stylesheets/application.css
199
+ - spec/internal/app/views/categories/category.html.erb
200
+ - spec/internal/app/views/categories/category.rhtml
201
+ - spec/internal/app/views/categories/category.erb
202
+ - spec/internal/app/views/application/index.html.erb
203
+ - spec/internal/app/models/article.rb
188
204
  - spec/internal/app/assets/javascripts/application.js
205
+ - spec/internal/app/assets/stylesheets/application.css
189
206
  - spec/internal/app/controllers/application_controller.rb
190
- - spec/internal/config/database.yml
207
+ - spec/internal/log/test.log
191
208
  - spec/internal/config/routes.rb
209
+ - spec/internal/config/database.yml
192
210
  - spec/internal/db/schema.rb
193
211
  - spec/internal/db/combustion_test.sqlite
194
- - spec/internal/public/favicon.ico
212
+ - spec/requests/search_spec.rb
213
+ - spec/lib/utils_spec.rb
214
+ - spec/lib/storage_spec.rb
215
+ - spec/lib/yamlfile_spec.rb
195
216
  - spec/lib/log_spec.rb
196
217
  - spec/lib/keys_spec.rb
197
- - spec/lib/file_spec.rb
198
- - spec/lib/storage_spec.rb
199
- - spec/requests/search_spec.rb
218
+ - spec/lib/sourcefiles_spec.rb
219
+ - spec/spec_helper.rb
200
220
  - spec/controllers/translate_controller_spec.rb
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 5b88e2c4e5270456757b8c9a9b998f5ddb7def00
4
- data.tar.gz: 64757f096941c68ed2ffa7862379a76a9f9c04e7
5
- SHA512:
6
- metadata.gz: 70d0037c6d3ffc3386801e895de0843a8560cb39b2d861abfd6de87e8553233940da641f9e4c89b7116bc5675292aab1a625a381ece2dbe725773e12eba4d2ed
7
- data.tar.gz: cc9315ef2a375204dba6cb998125f12b42cb1d94bc71fd3353f3fab79264854b7c45a971cf5c3ae1aafbfd7382a2b1734c5e069d63d7fe86b6cf9f3983f53c43
@@ -1,35 +0,0 @@
1
- require 'fileutils'
2
-
3
- class RailsI18nterface::File
4
- attr_accessor :path
5
-
6
- def initialize(path)
7
- self.path = path
8
- end
9
-
10
- def write(keys)
11
- FileUtils.mkdir_p File.dirname(path)
12
- File.open(path, "w") do |file|
13
- file.puts keys_to_yaml(self.class.deep_stringify_keys(keys))
14
- end
15
- end
16
-
17
- def read
18
- File.exists?(path) ? YAML::load(IO.read(path)) : {}
19
- end
20
-
21
- # Stringifying keys for prettier YAML
22
- def self.deep_stringify_keys(hash)
23
- hash.inject({}) { |result, (key, value)|
24
- value = deep_stringify_keys(value) if value.is_a? Hash
25
- result[(key.to_s rescue key) || key] = value
26
- result
27
- }
28
- end
29
-
30
- private
31
- def keys_to_yaml(keys)
32
- # Using ya2yaml, if available, for UTF8 support
33
- keys.respond_to?(:ya2yaml) ? keys.ya2yaml(:escape_as_utf8 => true) : keys.to_yaml
34
- end
35
- end
@@ -1,53 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RailsI18nterface::File do
4
- describe "write" do
5
- before(:each) do
6
- @file = RailsI18nterface::File.new(file_path)
7
- end
8
-
9
- after(:each) do
10
- FileUtils.rm(file_path)
11
- end
12
-
13
- it "writes all I18n messages for a locale to YAML file" do
14
- @file.write(translations)
15
- @file.read.should == RailsI18nterface::File.deep_stringify_keys(translations)
16
- end
17
-
18
- def translations
19
- {
20
- :en => {
21
- :article => {
22
- :title => "One Article"
23
- },
24
- :category => "Category"
25
- }
26
- }
27
- end
28
- end
29
-
30
- describe "deep_stringify_keys" do
31
- it "should convert all keys in a hash to strings" do
32
- RailsI18nterface::File.deep_stringify_keys({
33
- :en => {
34
- :article => {
35
- :title => "One Article"
36
- },
37
- :category => "Category"
38
- }
39
- }).should == {
40
- "en" => {
41
- "article" => {
42
- "title" => "One Article"
43
- },
44
- "category" => "Category"
45
- }
46
- }
47
- end
48
- end
49
-
50
- def file_path
51
- File.join(File.dirname(__FILE__), "files", "en.yml")
52
- end
53
- end