tolk 1.1.0 → 1.2.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.
@@ -0,0 +1,2 @@
1
+ # =require 'tolk/reset.css'
2
+ # =require 'tolk/screen.css'
@@ -1,3 +1,5 @@
1
+ require 'tolk/application_controller'
2
+
1
3
  module Tolk
2
4
  class ApplicationController < ActionController::Base
3
5
  helper :all
@@ -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[:page])
6
+ @phrases = @locale.search_phrases(params[:q], params[:scope].to_sym, params[:k], params[:page])
7
7
  end
8
8
 
9
9
  private
@@ -57,6 +57,7 @@ module Tolk
57
57
  accepts_nested_attributes_for :translations, :reject_if => proc { |attributes| attributes['text'].blank? }
58
58
  before_validation :remove_invalid_translations_from_target, :on => :update
59
59
 
60
+ attr_accessible :name
60
61
  cattr_accessor :locales_config_path
61
62
  self.locales_config_path = "#{Rails.root}/config/locales"
62
63
 
@@ -140,8 +141,8 @@ module Tolk
140
141
  result
141
142
  end
142
143
 
143
- def search_phrases(query, scope, page = nil, options = {})
144
- return [] unless query.present?
144
+ def search_phrases(query, scope, key_query, page = nil, options = {})
145
+ return [] unless query.present? || key_query.present?
145
146
 
146
147
  translations = case scope
147
148
  when :origin
@@ -151,6 +152,8 @@ module Tolk
151
152
  end
152
153
 
153
154
  phrases = Tolk::Phrase.scoped(:order => 'tolk_phrases.key ASC')
155
+ phrases = phrases.containing_text(key_query)
156
+
154
157
  phrases = phrases.scoped(:conditions => ['tolk_phrases.id IN(?)', translations.map(&:phrase_id).uniq])
155
158
  phrases.paginate({:page => page}.merge(options))
156
159
  end
@@ -2,6 +2,8 @@ module Tolk
2
2
  class Phrase < ActiveRecord::Base
3
3
  self.table_name = "tolk_phrases"
4
4
 
5
+ attr_accessible :key
6
+
5
7
  validates_uniqueness_of :key
6
8
 
7
9
  cattr_accessor :per_page
@@ -18,5 +20,9 @@ module Tolk
18
20
  end
19
21
 
20
22
  attr_accessor :translation
23
+
24
+ scope :containing_text, lambda { |query|
25
+ { :conditions => ["tolk_phrases.key LIKE ?", "%#{query}%"] }
26
+ }
21
27
  end
22
28
  end
@@ -14,6 +14,7 @@ module Tolk
14
14
  belongs_to :locale, :class_name => 'Tolk::Locale'
15
15
  validates_presence_of :locale_id
16
16
 
17
+ attr_accessible :phrase_id, :locale_id, :text, :primary_updated, :previous_text, :locale, :phrase
17
18
 
18
19
  attr_accessor :force_set_primary_update
19
20
  before_save :set_primary_updated
@@ -6,14 +6,8 @@
6
6
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
7
7
  <title>Tolk</title>
8
8
 
9
- <% if respond_to?(:sprockets_include_tag) %>
10
- <%= sprockets_include_tag %>
11
- <% else %>
12
- <%= javascript_include_tag :defaults %>
13
- <% end %>
14
-
15
- <%= stylesheet_link_tag "tolk/reset" %>
16
- <%= stylesheet_link_tag "tolk/screen" %>
9
+ <%= javascript_include_tag "tolk/application" %>
10
+ <%= stylesheet_link_tag "tolk/application" %>
17
11
  <%= yield :head %>
18
12
  </head>
19
13
 
@@ -4,5 +4,7 @@
4
4
  <%= scope_selector_for(@locale) %>
5
5
  phrase:
6
6
  <%= text_field_tag :q, params[:q] %>
7
+ within key:
8
+ <%= text_field_tag :k, params[:k] %>
7
9
  <%= submit_tag "Search", :name => nil %>
8
10
  <% end %>
@@ -36,7 +36,9 @@
36
36
  <% else -%>
37
37
  <%= format_i18n_value(phrase.translations.primary.text) -%>
38
38
  <% end -%>
39
- <span class="key" title="<%= phrase.key %>"><%= truncate(phrase.key, :length => 100) %></span>
39
+ <span class="key" title="<%= phrase.key %>"><%= params[:k].present? ?
40
+ highlight(h(truncate(phrase.key, :length => 100)), params[:k]) :
41
+ h(truncate(phrase.key, :length => 100)) %></span>
40
42
  </td>
41
43
  </tr>
42
44
  <% end %>
data/lib/tolk/sync.rb CHANGED
@@ -46,6 +46,7 @@ module Tolk
46
46
  phrases = Tolk::Phrase.all
47
47
 
48
48
  translations.each do |key, value|
49
+ next if value.is_a?(Proc)
49
50
  # Create phrase and primary translation if missing
50
51
  existing_phrase = phrases.detect {|p| p.key == key} || Tolk::Phrase.create!(:key => key)
51
52
  translation = existing_phrase.translations.primary || primary_locale.translations.build(:phrase_id => existing_phrase.id)
@@ -0,0 +1,3 @@
1
+ module Tolk
2
+ VERSION = "1.2.0"
3
+ end
metadata CHANGED
@@ -1,17 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tolk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - David Heinemeier Hansson
9
+ - Piotr Sarnacki
9
10
  - Emilio Tagua
10
11
  - Thomas Darde
11
12
  autorequire:
12
13
  bindir: bin
13
14
  cert_chain: []
14
- date: 2012-05-15 00:00:00.000000000 Z
15
+ date: 2012-05-16 00:00:00.000000000 Z
15
16
  dependencies:
16
17
  - !ruby/object:Gem::Dependency
17
18
  name: will_paginate
@@ -61,7 +62,14 @@ files:
61
62
  - lib/tolk/engine.rb
62
63
  - lib/tolk/import.rb
63
64
  - lib/tolk/sync.rb
65
+ - lib/tolk/version.rb
64
66
  - lib/tolk.rb
67
+ - app/assets/javascripts/tolk/application.js
68
+ - app/assets/javascripts/tolk/controls.js
69
+ - app/assets/javascripts/tolk/dragdrop.js
70
+ - app/assets/javascripts/tolk/effects.js
71
+ - app/assets/javascripts/tolk/prototype.js
72
+ - app/assets/stylesheets/tolk/application.css
65
73
  - app/assets/stylesheets/tolk/reset.css
66
74
  - app/assets/stylesheets/tolk/screen.css
67
75
  - app/controllers/tolk/application_controller.rb