tolk 1.6.0.alpha1 → 1.6.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ca7dad7fa94ddec0e5d929c9cf06e95af7b2ee6b
4
- data.tar.gz: 489d41d64a6a62a3699947467467fc20dce346e8
3
+ metadata.gz: 2f7b2a28f97a99af1b49df29efb4e65da9f5f819
4
+ data.tar.gz: 06dc422c8a9203b5aea8646e33929b05d27377a9
5
5
  SHA512:
6
- metadata.gz: 9a3be6fb7c98e14dccdb1f5bf9e32c8d956ec528f237626419641cb925012cecd8c622e7d58d3375b4e497d5129ca33c684c376e6fc80987d0f7855f23ead1e2
7
- data.tar.gz: 55fa32b0234ec09206e0ce054a6c151bfae8cb17ab22f48edda0360770e268320fa0b2d3201870c2e06349e69abc5a3eb0f2350859e8903492f650314b5666d2
6
+ metadata.gz: 66e7419915337fe0d1bfacce4401d7c1c9fb824c779dce354189c6c9cb58d3b956134fe7160e6741c41b96c828825d776cee23832a9375b85669f4796bca2fb7
7
+ data.tar.gz: 06c8167af0cae8c8a28d1b1ca532241704e2d0b6ab6a6875c7222d86a210dec020feb18d00aeee86a29b0e15a2ecbefc85936dec1c6aa52c2bcf41066feaf081
@@ -17,7 +17,7 @@ module Tolk
17
17
 
18
18
  format.yaml do
19
19
  data = @locale.to_hash
20
- render :text => data.respond_to?(:ya2yaml) ? data.ya2yaml(:syck_compatible => true) : YAML.dump(data).force_encoding("UTF-8")
20
+ render :text => Tolk::YAML.dump(data)
21
21
  end
22
22
 
23
23
  end
@@ -76,13 +76,9 @@ module Tolk
76
76
  params.require(:tolk_locale).permit(:name)
77
77
  end
78
78
 
79
- # TODO: whitelist incoming translation params
80
- # translation permitted params: :phrase_id, :locale_id, :text, :primary_updated, :previous_text, :locale, :phrase
81
- # test params: "translations"=>[{"id"=>"", "phrase_id"=>"8", "locale_id"=>"5", "text"=>"Dead men don't bite"}, {"id"=>"", "phrase_id"=>"7", "locale_id"=>"5", "text"=>""}]
82
79
  def translation_params
83
- params.require(:translations)
80
+ params.permit(translations: [:id, :phrase_id, :locale_id, :text])[:translations]
84
81
  end
85
82
 
86
-
87
83
  end
88
84
  end
@@ -21,7 +21,7 @@ module Tolk
21
21
  def yaml_value(value)
22
22
  if value.present?
23
23
  unless value.is_a?(String) || value.is_a?(TrueClass) || value.is_a?(FalseClass)
24
- value = value.respond_to?(:ya2yaml) ? value.ya2yaml(:syck_compatible => true) : value.to_yaml
24
+ value = Tolk::YAML.dump(value)
25
25
  end
26
26
  end
27
27
 
@@ -38,7 +38,7 @@ module Tolk
38
38
  @_primary_locale = nil if reload
39
39
  @_primary_locale ||= begin
40
40
  raise "Primary locale is not set. Please set Locale.primary_locale_name in your application's config file" unless self.primary_locale_name
41
- find_or_create_by(name: self.primary_locale_name)
41
+ where(name: self.primary_locale_name).first_or_create
42
42
  end
43
43
  end
44
44
 
@@ -55,7 +55,7 @@ module Tolk
55
55
  end
56
56
 
57
57
  def dump_yaml(name, *args)
58
- find_by_name(name).dump(*args)
58
+ where(name: name).first.dump(*args)
59
59
  end
60
60
 
61
61
  def special_key_or_prefix?(prefix, key)
@@ -75,7 +75,7 @@ module Tolk
75
75
  end
76
76
 
77
77
  def has_updated_translations?
78
- translations.count(:conditions => {:'tolk_translations.primary_updated' => true}) > 0
78
+ translations.where('tolk_translations.primary_updated' => true).count > 0
79
79
  end
80
80
 
81
81
  def phrases_with_translation(page = nil)
@@ -102,6 +102,12 @@ module Tolk
102
102
  phrases = phrases.where('tolk_phrases.id NOT IN (?)', existing_ids) if existing_ids.present?
103
103
 
104
104
  result = phrases.paginate({:page => page, :per_page => Phrase.per_page}.merge(options))
105
+ if Rails.version =~ /^4\.0/
106
+ ActiveRecord::Associations::Preloader.new result, :translations
107
+ else
108
+ ActiveRecord::Associations::Preloader.new().preload(result, :translations)
109
+ end
110
+
105
111
  result
106
112
  end
107
113
 
@@ -132,6 +138,12 @@ module Tolk
132
138
  # phrases = phrases.scoped(:conditions => ['tolk_phrases.id NOT IN (?) AND tolk_phrases.id IN(?)', existing_ids, found_translations_ids]) if existing_ids.present?
133
139
  phrases = phrases.where(['tolk_phrases.id NOT IN (?) AND tolk_phrases.id IN(?)', existing_ids, found_translations_ids]) if existing_ids.present?
134
140
  result = phrases.paginate({:page => page}.merge(options))
141
+ if Rails.version =~ /^4\.0/
142
+ ActiveRecord::Associations::Preloader.new result, :translations
143
+ else
144
+ ActiveRecord::Associations::Preloader.new().preload(result, :translations)
145
+ end
146
+
135
147
  result
136
148
  end
137
149
 
@@ -160,7 +172,7 @@ module Tolk
160
172
  end
161
173
 
162
174
  def get(key)
163
- if phrase = Tolk::Phrase.find_by_key(key)
175
+ if phrase = Tolk::Phrase.where(key: key).first
164
176
  t = self.translations.where(:phrase_id => phrase.id).first
165
177
  t.text if t
166
178
  end
@@ -169,6 +181,11 @@ module Tolk
169
181
  def translations_with_html
170
182
  translations = self.translations.all(:conditions => "tolk_translations.text LIKE '%>%' AND
171
183
  tolk_translations.text LIKE '%<%' AND tolk_phrases.key NOT LIKE '%_html'", :joins => :phrase)
184
+ if Rails.version =~ /^4\.0/
185
+ ActiveRecord::Associations::Preloader.new translations, :phrase
186
+ else
187
+ ActiveRecord::Associations::Preloader.new().preload(translations, :phrase)
188
+ end
172
189
  translations
173
190
  end
174
191
 
@@ -176,7 +193,7 @@ module Tolk
176
193
  if old_name.blank? || new_name.blank?
177
194
  "You need to provide both names, aborting."
178
195
  else
179
- if locale = find_by_name(old_name)
196
+ if locale = where(name: old_name).first
180
197
  locale.name = new_name
181
198
  locale.save
182
199
  "Locale ' #{old_name}' was renamed '#{new_name}'"
@@ -208,6 +225,11 @@ module Tolk
208
225
  phrase.translation = phrase.translations.for(self)
209
226
  end
210
227
 
228
+ if Rails.version =~ /^4\.0/
229
+ ActiveRecord::Associations::Preloader.new result, :translations
230
+ else
231
+ ActiveRecord::Associations::Preloader.new().preload(result, :translations)
232
+ end
211
233
 
212
234
  result
213
235
  end
@@ -112,7 +112,7 @@ module Tolk
112
112
  if primary_translation.present?
113
113
  if self.text.is_a?(String) && !primary_translation.text.is_a?(String)
114
114
  self.text = begin
115
- YAML.safe_load(self.text.strip)
115
+ YAML.load(self.text.strip)
116
116
  rescue ArgumentError
117
117
  nil
118
118
  end
@@ -19,7 +19,7 @@
19
19
  </tr>
20
20
  <% @phrases.each do |phrase| %>
21
21
 
22
- <% if translation = phrase.translations.find_by_locale_id(@locale.id) || Tolk::Translation.new(:locale => @locale, :phrase => phrase) %>
22
+ <% if translation = phrase.translations.where(locale_id: @locale.id).first || Tolk::Translation.new(:locale => @locale, :phrase => phrase) %>
23
23
  <tr>
24
24
  <td class="translation">
25
25
  <%= hidden_field_tag :"translations[][id]", translation.id, :id => "#{translation.object_id}_id" %>
@@ -40,7 +40,7 @@
40
40
  <%= format_i18n_value(phrase.translations.primary.text) -%>
41
41
  <% end -%>
42
42
  <%= boolean_warning if phrase.translations.primary.boolean? -%>
43
-
43
+
44
44
  <span class="key" title="<%= phrase.key %>"><%= params[:k].present? ?
45
45
  highlight(h(truncate(phrase.key, :length => 100)), params[:k]) :
46
46
  h(truncate(phrase.key, :length => 100)) %></span>
@@ -1,10 +1,11 @@
1
1
  require 'will_paginate'
2
- require 'safe_yaml'
2
+ require 'safe_yaml/load'
3
3
  require 'tolk/config'
4
4
  require 'tolk/engine'
5
5
  require 'tolk/sync'
6
6
  require 'tolk/import'
7
7
  require 'tolk/export'
8
+ require 'tolk/yaml'
8
9
 
9
10
  module Tolk
10
11
  # Setup Tolk
@@ -2,15 +2,10 @@ require 'rails'
2
2
 
3
3
  module Tolk
4
4
  class Engine < Rails::Engine
5
- SafeYAML::OPTIONS[:default_mode] = :safe
6
- SafeYAML::OPTIONS[:deserialize_symbols] = true
7
-
8
5
  isolate_namespace Tolk
9
6
 
10
- if Rails.version >= '3.1'
11
- initializer :assets do |app|
12
- app.config.assets.precompile += ['tolk/libraries.js']
13
- end
7
+ initializer :assets do |app|
8
+ app.config.assets.precompile += ['tolk/libraries.js']
14
9
  end
15
10
  end
16
11
  end
@@ -10,12 +10,7 @@ module Tolk
10
10
 
11
11
  def dump
12
12
  File.open("#{destination}/#{name}.yml", "w+") do |file|
13
- yml = if data.respond_to?(:ya2yaml)
14
- data.ya2yaml(:syck_compatible => true)
15
- else
16
- YAML.dump(data).force_encoding(file.external_encoding.name)
17
- end
18
- file.write(yml)
13
+ file.write(Tolk::YAML.dump(data))
19
14
  end
20
15
  end
21
16
 
@@ -20,7 +20,7 @@ module Tolk
20
20
  end
21
21
 
22
22
  def import_locale(locale_name)
23
- locale = Tolk::Locale.find_or_create_by_name(locale_name)
23
+ locale = Tolk::Locale.where(name: locale_name).first_or_create
24
24
  data = locale.read_locale_file
25
25
  return unless data
26
26
 
@@ -53,7 +53,7 @@ module Tolk
53
53
 
54
54
  puts "[INFO] Reading #{locale_file} for locale #{self.name}"
55
55
  begin
56
- self.class.flat_hash(YAML::safe_load(IO.read(locale_file))[self.name])
56
+ self.class.flat_hash(Tolk::YAML.load_file(locale_file)[self.name])
57
57
  rescue
58
58
  puts "[ERROR] File #{locale_file} expected to declare #{self.name} locale, but it does not. Skipping this file."
59
59
  nil
@@ -17,7 +17,11 @@ module Tolk
17
17
 
18
18
  def read_primary_locale_file
19
19
  primary_file = "#{self.locales_config_path}/#{self.primary_locale_name}.yml"
20
- File.exists?(primary_file) ? flat_hash(YAML::safe_load(IO.read(primary_file))[self.primary_locale_name]) : {}
20
+ if File.exists?(primary_file)
21
+ flat_hash(Tolk::YAML.load_file(primary_file)[self.primary_locale_name])
22
+ else
23
+ {}
24
+ end
21
25
  end
22
26
 
23
27
  def flat_hash(data, prefix = '', result = {})
@@ -1,3 +1,3 @@
1
1
  module Tolk
2
- VERSION = "1.6.0.alpha1"
2
+ VERSION = "1.6.0"
3
3
  end
@@ -0,0 +1,29 @@
1
+ module Tolk
2
+ module YAML
3
+ SAFE_YAML_OPTIONS = SafeYAML::Deep.freeze({
4
+ :default_mode => :safe,
5
+ :deserialize_symbols => true
6
+ })
7
+
8
+ def self.load(yaml)
9
+ # SafeYAML.load has different arity depending on the YAML engine used.
10
+ if SafeYAML::YAML_ENGINE == "psych"
11
+ SafeYAML.load(yaml, nil, SAFE_YAML_OPTIONS)
12
+ else # syck
13
+ SafeYAML.load(yaml, SAFE_YAML_OPTIONS)
14
+ end
15
+ end
16
+
17
+ def self.load_file(filename)
18
+ SafeYAML.load_file(filename, SAFE_YAML_OPTIONS)
19
+ end
20
+
21
+ def self.dump(payload)
22
+ if payload.respond_to?(:ya2yaml)
23
+ payload.ya2yaml(:syck_compatible => true)
24
+ else
25
+ ::YAML.dump(payload)
26
+ end
27
+ end
28
+ end
29
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tolk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0.alpha1
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
@@ -12,8 +12,28 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2014-05-28 00:00:00.000000000 Z
15
+ date: 2014-09-24 00:00:00.000000000 Z
16
16
  dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: rails
19
+ requirement: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: '4.0'
24
+ - - "<"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.2'
27
+ type: :runtime
28
+ prerelease: false
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '4.0'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '4.2'
17
37
  - !ruby/object:Gem::Dependency
18
38
  name: will_paginate
19
39
  requirement: !ruby/object:Gem::Requirement
@@ -34,14 +54,98 @@ dependencies:
34
54
  requirements:
35
55
  - - ">="
36
56
  - !ruby/object:Gem::Version
37
- version: '0.8'
57
+ version: 0.8.6
38
58
  type: :runtime
39
59
  prerelease: false
40
60
  version_requirements: !ruby/object:Gem::Requirement
41
61
  requirements:
42
62
  - - ">="
43
63
  - !ruby/object:Gem::Version
44
- version: '0.8'
64
+ version: 0.8.6
65
+ - !ruby/object:Gem::Dependency
66
+ name: capybara
67
+ requirement: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - '='
70
+ - !ruby/object:Gem::Version
71
+ version: 2.2.1
72
+ type: :development
73
+ prerelease: false
74
+ version_requirements: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - '='
77
+ - !ruby/object:Gem::Version
78
+ version: 2.2.1
79
+ - !ruby/object:Gem::Dependency
80
+ name: factory_girl_rails
81
+ requirement: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ - !ruby/object:Gem::Dependency
94
+ name: sqlite3
95
+ requirement: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ type: :development
101
+ prerelease: false
102
+ version_requirements: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ - !ruby/object:Gem::Dependency
108
+ name: mocha
109
+ requirement: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ type: :development
115
+ prerelease: false
116
+ version_requirements: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ - !ruby/object:Gem::Dependency
122
+ name: launchy
123
+ requirement: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ type: :development
129
+ prerelease: false
130
+ version_requirements: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ - !ruby/object:Gem::Dependency
136
+ name: selenium-webdriver
137
+ requirement: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ type: :development
143
+ prerelease: false
144
+ version_requirements: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
45
149
  description: Tolk is a web interface for doing i18n translations packaged as an engine
46
150
  for Rails applications.
47
151
  email: david@loudthinking.com
@@ -74,7 +178,6 @@ files:
74
178
  - app/views/tolk/searches/_form.html.erb
75
179
  - app/views/tolk/searches/show.html.erb
76
180
  - config/routes.rb
77
- - init.rb
78
181
  - lib/generators/tolk/install_generator.rb
79
182
  - lib/generators/tolk/templates/initializer.erb
80
183
  - lib/generators/tolk/templates/migration.rb
@@ -87,6 +190,7 @@ files:
87
190
  - lib/tolk/import.rb
88
191
  - lib/tolk/sync.rb
89
192
  - lib/tolk/version.rb
193
+ - lib/tolk/yaml.rb
90
194
  homepage: http://github.com/tolk/tolk
91
195
  licenses:
92
196
  - MIT
@@ -99,12 +203,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
99
203
  requirements:
100
204
  - - ">="
101
205
  - !ruby/object:Gem::Version
102
- version: '0'
206
+ version: 1.9.3
103
207
  required_rubygems_version: !ruby/object:Gem::Requirement
104
208
  requirements:
105
- - - ">"
209
+ - - ">="
106
210
  - !ruby/object:Gem::Version
107
- version: 1.3.1
211
+ version: '0'
108
212
  requirements: []
109
213
  rubyforge_project:
110
214
  rubygems_version: 2.2.2
data/init.rb DELETED
@@ -1,8 +0,0 @@
1
- Mime::Type.register_alias "text/yaml", :yml
2
-
3
- $KCODE = 'UTF8'
4
- begin
5
- require 'ya2yaml'
6
- rescue LoadError => e
7
- Rails.logger.debug "[Tolk] Could not load ya2yaml"
8
- end