tolk 1.7.0 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8edb38a512ec3f99ff77247e69aadc7165741877
4
- data.tar.gz: 7ce3e97f58f4f7d5572ea4f66c087fa10a8e5c4a
3
+ metadata.gz: 9abfb538fd5b1496c475291c76eb390219c6e9a1
4
+ data.tar.gz: 94333e34720a9a3120c9fa366b8f2d17147cfc91
5
5
  SHA512:
6
- metadata.gz: 590df61b41db838157c92acb7c54e6e24cfc0cdb23cd08e25df84e6230863d5e2a92638ec7036a09e550da25993ed63afdb3b942bac126e93194abe81a33f5bb
7
- data.tar.gz: d48e97823d6fec8131c65b2df05340ba9ed356a3d2f1a64c94279ab729e09992e0869c3aa34a593c4dc6d7d88ec695ba7ba95b56c6d20d62b4ed76d96fbec0a7
6
+ metadata.gz: 8334be8d312ce698cadaad7e4c184a51a88648eb3b08a29e530de859620ca45a9baeb0735943d1e32fe570401a0eb9f75726f0901ec6a9954cf4523bf4d42402
7
+ data.tar.gz: 021100519c121daee3f8f852d7529442e94ed03c3c4ceb1dfbf9613f348658df4b9b2dd433e70ac41deeddd537b100e36833ff60f85e6a1ed2b66c66297a3b74
@@ -1,7 +1,10 @@
1
1
  require 'tolk/application_controller'
2
+ require 'tolk/pagination'
2
3
 
3
4
  module Tolk
4
5
  class ApplicationController < ActionController::Base
6
+ include Tolk::Pagination::Methods
7
+
5
8
  helper :all
6
9
  protect_from_forgery
7
10
 
@@ -10,10 +10,10 @@ module Tolk
10
10
  def show
11
11
  respond_to do |format|
12
12
  format.html do
13
- @phrases = @locale.phrases_without_translation(params[:page])
13
+ @phrases = @locale.phrases_without_translation(params[pagination_param])
14
14
  end
15
15
 
16
- format.atom { @phrases = @locale.phrases_without_translation(params[:page], :per_page => 50) }
16
+ format.atom { @phrases = @locale.phrases_without_translation(params[pagination_param]).per(50) }
17
17
 
18
18
  format.yaml do
19
19
  data = @locale.to_hash
@@ -30,11 +30,11 @@ module Tolk
30
30
  end
31
31
 
32
32
  def all
33
- @phrases = @locale.phrases_with_translation(params[:page])
33
+ @phrases = @locale.phrases_with_translation(params[pagination_param])
34
34
  end
35
35
 
36
36
  def updated
37
- @phrases = @locale.phrases_with_updated_translation(params[:page])
37
+ @phrases = @locale.phrases_with_updated_translation(params[pagination_param])
38
38
  render :all
39
39
  end
40
40
 
@@ -3,7 +3,7 @@ module Tolk
3
3
  before_filter :find_locale
4
4
 
5
5
  def show
6
- @phrases = @locale.search_phrases(params[:q], params[:scope].to_sym, params[:k], params[:page])
6
+ @phrases = @locale.search_phrases(params[:q], params[:scope].to_sym, params[:k], params[pagination_param])
7
7
  end
8
8
 
9
9
  private
@@ -1,5 +1,9 @@
1
+ require 'tolk/pagination'
2
+
1
3
  module Tolk
2
4
  module ApplicationHelper
5
+ include Tolk::Pagination::ViewHelper
6
+
3
7
  def format_i18n_value(value)
4
8
  value = h(yaml_value(value))
5
9
  value = highlight_linebreaks(value)
@@ -1,7 +1,10 @@
1
1
  require 'tolk/config'
2
+ require 'tolk/pagination'
2
3
 
3
4
  module Tolk
4
5
  class Locale < ActiveRecord::Base
6
+ include Tolk::Pagination::Methods
7
+
5
8
  self.table_name = "tolk_locales"
6
9
 
7
10
  def self._dump_path
@@ -95,13 +98,13 @@ module Tolk
95
98
  find_phrases_with_translations(page, :'tolk_translations.primary_updated' => true).count
96
99
  end
97
100
 
98
- def phrases_without_translation(page = nil, options = {})
101
+ def phrases_without_translation(page = nil)
99
102
  phrases = Tolk::Phrase.all.order('tolk_phrases.key ASC')
100
103
 
101
104
  existing_ids = self.translations(:select => 'tolk_translations.phrase_id').map(&:phrase_id).uniq
102
105
  phrases = phrases.where('tolk_phrases.id NOT IN (?)', existing_ids) if existing_ids.present?
103
106
 
104
- result = phrases.paginate({:page => page, :per_page => Phrase.per_page}.merge(options))
107
+ result = phrases.public_send(pagination_method, page)
105
108
  if Rails.version =~ /^4\.0/
106
109
  ActiveRecord::Associations::Preloader.new result, :translations
107
110
  else
@@ -111,7 +114,7 @@ module Tolk
111
114
  result
112
115
  end
113
116
 
114
- def search_phrases(query, scope, key_query, page = nil, options = {})
117
+ def search_phrases(query, scope, key_query, page = nil)
115
118
  return [] unless query.present? || key_query.present?
116
119
 
117
120
  translations = case scope
@@ -125,11 +128,11 @@ module Tolk
125
128
  phrases = phrases.containing_text(key_query)
126
129
 
127
130
  phrases = phrases.where('tolk_phrases.id IN(?)', translations.map(&:phrase_id).uniq)
128
- phrases.paginate({:page => page}.merge(options))
131
+ phrases.public_send(pagination_method, page)
129
132
  end
130
133
 
131
- def search_phrases_without_translation(query, page = nil, options = {})
132
- return phrases_without_translation(page, options) unless query.present?
134
+ def search_phrases_without_translation(query, page = nil)
135
+ return phrases_without_translation(page) unless query.present?
133
136
 
134
137
  phrases = Tolk::Phrase.all.order('tolk_phrases.key ASC')
135
138
 
@@ -137,7 +140,7 @@ module Tolk
137
140
  existing_ids = self.translations.select('tolk_translations.phrase_id').to_a.map(&:phrase_id).uniq
138
141
  # phrases = phrases.scoped(:conditions => ['tolk_phrases.id NOT IN (?) AND tolk_phrases.id IN(?)', existing_ids, found_translations_ids]) if existing_ids.present?
139
142
  phrases = phrases.where(['tolk_phrases.id NOT IN (?) AND tolk_phrases.id IN(?)', existing_ids, found_translations_ids]) if existing_ids.present?
140
- result = phrases.paginate({:page => page}.merge(options))
143
+ result = phrases.public_send(pagination_method, page)
141
144
  if Rails.version =~ /^4\.0/
142
145
  ActiveRecord::Associations::Preloader.new result, :translations
143
146
  else
@@ -219,7 +222,7 @@ module Tolk
219
222
  end
220
223
 
221
224
  def find_phrases_with_translations(page, conditions = {})
222
- result = Tolk::Phrase.where({ :'tolk_translations.locale_id' => self.id }.merge(conditions)).joins(:translations).order('tolk_phrases.key ASC').paginate(:page => page)
225
+ result = Tolk::Phrase.where({ :'tolk_translations.locale_id' => self.id }.merge(conditions)).joins(:translations).order('tolk_phrases.key ASC').public_send(pagination_method, page)
223
226
 
224
227
  result.each do |phrase|
225
228
  phrase.translation = phrase.translations.for(self)
@@ -4,8 +4,7 @@ module Tolk
4
4
 
5
5
  validates_uniqueness_of :key
6
6
 
7
- cattr_accessor :per_page
8
- self.per_page = 30
7
+ paginates_per 30
9
8
 
10
9
  has_many :translations, :class_name => 'Tolk::Translation', :dependent => :destroy do
11
10
  def primary
@@ -58,7 +58,7 @@
58
58
  <p><%= locale_form.submit "Save changes", :class => 'save' %></p>
59
59
  </div>
60
60
  <div class="paginate">
61
- <%= will_paginate @phrases %>
61
+ <%= tolk_paginate @phrases %>
62
62
  </div>
63
63
  <% end %>
64
64
  <% else %>
@@ -54,7 +54,7 @@
54
54
  </div>
55
55
  <% end %>
56
56
  <div class="paginate">
57
- <%= will_paginate @phrases %>
57
+ <%= tolk_paginate @phrases %>
58
58
  </div>
59
59
  <% else %>
60
60
  <p style="text-align: left">There aren't any missing or updated phrases that need translation.</p>
@@ -54,7 +54,7 @@
54
54
  </div>
55
55
  <% end %>
56
56
  <div class="paginate">
57
- <%= will_paginate @phrases %>
57
+ <%= tolk_paginate @phrases %>
58
58
  </div>
59
59
  <% else %>
60
60
  <p style="text-align: left">No search results.</p>
data/lib/tolk.rb CHANGED
@@ -1,4 +1,3 @@
1
- require 'will_paginate'
2
1
  require 'safe_yaml/load'
3
2
  require 'tolk/config'
4
3
  require 'tolk/engine'
data/lib/tolk/config.rb CHANGED
@@ -14,7 +14,12 @@ module Tolk
14
14
  # primary locale to not be overriden by default locale in development mode
15
15
  attr_accessor :primary_locale_name
16
16
 
17
+ # exclude locales tokens from gems
18
+ attr_accessor :exclude_gems_token
19
+
17
20
  def reset
21
+ @exclude_gems_token = false
22
+
18
23
  @dump_path = Proc.new { "#{Rails.application.root}/config/locales" }
19
24
 
20
25
  @mapping = {
data/lib/tolk/engine.rb CHANGED
@@ -7,5 +7,19 @@ module Tolk
7
7
  initializer :assets do |app|
8
8
  app.config.assets.precompile += ['tolk/libraries.js']
9
9
  end
10
+
11
+ # We need one of the two pagination engines loaded by this point.
12
+ # We don't care which one, just one of them will do.
13
+ begin
14
+ require 'kaminari'
15
+ rescue LoadError
16
+ begin
17
+ require 'will_paginate'
18
+ rescue LoadError
19
+ puts "Please add the kaminari or will_paginate gem to your application's Gemfile."
20
+ puts "The Tolk engine needs either kaminari or will_paginate in order to paginate."
21
+ exit
22
+ end
23
+ end
10
24
  end
11
25
  end
@@ -0,0 +1,28 @@
1
+ module Tolk
2
+ module Pagination
3
+ module Methods
4
+ # Kaminari defaults page_method_name to :page, will_paginate always uses
5
+ # :page
6
+ def pagination_method
7
+ defined?(Kaminari) ? Kaminari.config.page_method_name : :page
8
+ end
9
+
10
+ # Kaminari defaults param_name to :page, will_paginate always uses :page
11
+ def pagination_param
12
+ defined?(Kaminari) ? Kaminari.config.param_name : :page
13
+ end
14
+ end
15
+
16
+ module ViewHelper
17
+ def tolk_paginate(collection, options = {})
18
+ if respond_to?(:will_paginate)
19
+ # If parent app is using Will Paginate, we need to use it also
20
+ will_paginate collection, options
21
+ else
22
+ # Otherwise use Kaminari
23
+ paginate collection, options
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
data/lib/tolk/sync.rb CHANGED
@@ -10,7 +10,14 @@ module Tolk
10
10
  end
11
11
 
12
12
  def load_translations
13
- I18n.backend.send :init_translations unless I18n.backend.initialized? # force load
13
+ if Tolk.config.exclude_gems_token
14
+ # bypass default init_translations
15
+ I18n.backend.reload! if I18n.backend.initialized?
16
+ I18n.backend.instance_variable_set(:@initialized, true)
17
+ I18n.backend.load_translations(Dir[Rails.root.join('config', 'locales', "*.{rb,yml}")])
18
+ else
19
+ I18n.backend.send :init_translations unless I18n.backend.initialized? # force load
20
+ end
14
21
  translations = flat_hash(I18n.backend.send(:translations)[primary_locale.name.to_sym])
15
22
  filter_out_i18n_keys(translations.merge(read_primary_locale_file))
16
23
  end
data/lib/tolk/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tolk
2
- VERSION = "1.7.0"
2
+ VERSION = "1.8.0"
3
3
  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.7.0
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2014-11-12 00:00:00.000000000 Z
15
+ date: 2015-03-28 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rails
@@ -34,20 +34,6 @@ dependencies:
34
34
  - - "<"
35
35
  - !ruby/object:Gem::Version
36
36
  version: '4.3'
37
- - !ruby/object:Gem::Dependency
38
- name: will_paginate
39
- requirement: !ruby/object:Gem::Requirement
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- version: '0'
44
- type: :runtime
45
- prerelease: false
46
- version_requirements: !ruby/object:Gem::Requirement
47
- requirements:
48
- - - ">="
49
- - !ruby/object:Gem::Version
50
- version: '0'
51
37
  - !ruby/object:Gem::Dependency
52
38
  name: safe_yaml
53
39
  requirement: !ruby/object:Gem::Requirement
@@ -118,6 +104,20 @@ dependencies:
118
104
  - - ">="
119
105
  - !ruby/object:Gem::Version
120
106
  version: '0'
107
+ - !ruby/object:Gem::Dependency
108
+ name: will_paginate
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
121
  description: Tolk is a web interface for doing i18n translations packaged as an engine
122
122
  for Rails applications.
123
123
  email: david@loudthinking.com
@@ -160,6 +160,7 @@ files:
160
160
  - lib/tolk/engine.rb
161
161
  - lib/tolk/export.rb
162
162
  - lib/tolk/import.rb
163
+ - lib/tolk/pagination.rb
163
164
  - lib/tolk/sync.rb
164
165
  - lib/tolk/version.rb
165
166
  - lib/tolk/yaml.rb
@@ -183,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
183
184
  version: '0'
184
185
  requirements: []
185
186
  rubyforge_project:
186
- rubygems_version: 2.4.2
187
+ rubygems_version: 2.4.5
187
188
  signing_key:
188
189
  specification_version: 4
189
190
  summary: Rails engine providing web interface for managing i18n yaml files