lit 0.3.1 → 0.3.3

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: 0c57fed1785a83aafbf202508c1e7ef19bace46e
4
- data.tar.gz: b82b1ed7715c0dc5e240742ff74555c2fc52cdbf
3
+ metadata.gz: 4c4bb066b08ec7f1bb1cbd9992dca9e572acde0e
4
+ data.tar.gz: 704bb8463f8f8f6ff83bd5f0c5b63937323db920
5
5
  SHA512:
6
- metadata.gz: 262e34d65d5a9b15fafbeec7dc791ee51d2d134a91fabd0824cbd8270ada54bd708d1f65f4d54cd9886a3d4e32662edb9c13b4d09a86f0973cb3382981c0b1c6
7
- data.tar.gz: f58f715c589870c276ced4ede59e619320afed3f07290a32f01345c40816a7f252a6ef0d9e0505bfb9c04877cae7a9690982726f26c760d116ff21fafe5bdfe0
6
+ metadata.gz: 63086561d6b158cbe8ae12a97cc3c6a29d78f1905a4bec3378247f9bb12a13a0cae19d5c0cdcbf4edcb2cfb626058feceb13199a7e290a43b05fdafdb6da9c15
7
+ data.tar.gz: 8413129a9c31d0c01cd2b6c97dd497d4a018f46848833685e4b27cd77fb5fc6872fe55da123e08c761edc2b0bab264af0ece86052bc159a7bb6a315dd6a632bc
data/README.md CHANGED
@@ -82,7 +82,7 @@ $ LOCALES=en,de rake lit:export
82
82
  ### On-site live translations
83
83
 
84
84
  1. Add `Lit::FrontendHelper` to your `ApplicationController`
85
- 2.
85
+
86
86
  ```ruby
87
87
  helper Lit::FrontendHelper
88
88
  ```
@@ -97,8 +97,9 @@ $ LOCALES=en,de rake lit:export
97
97
 
98
98
  3. You're good to go - now log in to lit (if required) and open your frontend in separate tab (to have session persisted). On the bottom-right of your page you should see "Enable / disable lit highlight" - after enabling it you'll be able to click and translate phrases directly in your frontend
99
99
 
100
- 4. Once enabled, all translations called via `t` helper function be rendered inside `<span />` tag, what may break your layout (ie if you're using translated values as button values or
101
- as placeholders, etc). To avoid that add `skip_lit: true` to `t()` call or use `I18n.t`.
100
+ 4. Once enabled, all translations called via `t` helper function be rendered inside `<span />` tag, what may break your layout (ie if you're using translated values as button values or as placeholders, etc). To avoid that add `skip_lit: true` to `t()` call or use `I18n.t`.
101
+
102
+ 5. This feature requires jQuery! (at least for now)
102
103
 
103
104
  ### Storing request info
104
105
 
@@ -139,7 +140,7 @@ Lit.store_request_info = true
139
140
 
140
141
  4. From now on you'll be able to see all translation keys that were used to render current page. This feature works great with on-site live translations!
141
142
 
142
- 5. Lit authorized user must be signed in for this feature to work!
143
+ 5. Lit authorized user must be signed in for this feature to work! This feature requires jQuery!
143
144
 
144
145
 
145
146
 
@@ -23,5 +23,17 @@ module Lit
23
23
  def restore_hits_counter
24
24
  Lit.init.cache.restore_hits_counter
25
25
  end
26
+
27
+ def redirect_to_back_or_default(fallback_location: lit.localization_keys_path)
28
+ if respond_to?(:redirect_back)
29
+ redirect_back fallback_location: fallback_location
30
+ else
31
+ if request.env["HTTP_REFERER"].present? and request.env["HTTP_REFERER"] != request.env["REQUEST_URI"]
32
+ redirect_to :back
33
+ else
34
+ redirect_to fallback_location
35
+ end
36
+ end
37
+ end
26
38
  end
27
39
  end
@@ -13,7 +13,7 @@ module Lit
13
13
  @incomming_localization.accept
14
14
  Lit.init.cache.refresh_key @incomming_localization.full_key
15
15
  respond_to do |format|
16
- format.html { redirect_to :back }
16
+ format.html { redirect_to_back_or_default(fallback_location: source_incomming_localizations_path(@source)) }
17
17
  format.js
18
18
  end
19
19
  end
@@ -23,12 +23,12 @@ module Lit
23
23
  li.accept
24
24
  Lit.init.cache.refresh_key li.full_key
25
25
  end
26
- redirect_to :back
26
+ redirect_to_back_or_default(fallback_location: source_incomming_localizations_path(@source))
27
27
  end
28
28
 
29
29
  def reject_all
30
30
  @source.incomming_localizations.destroy_all
31
- redirect_to :back
31
+ redirect_to_back_or_default(fallback_location: source_incomming_localizations_path(@source))
32
32
  end
33
33
 
34
34
  def destroy
@@ -70,13 +70,13 @@ module Lit
70
70
  s = self
71
71
  if options[:order] && order_options.include?(options[:order])
72
72
  column, order = options[:order].split(' ')
73
- s = s.order("#{Lit::LocalizationKey.quoted_table_name}.#{connection.quote_column_name(column)} #{order}")
73
+ s = s.order(FakeLocalizationKey.arel_table[column.to_sym].send(order.to_sym))
74
74
  else
75
75
  s = s.ordered
76
76
  end
77
- localization_key_col = Lit::LocalizationKey.arel_table[:localization_key]
78
- default_value_col = Lit::Localization.arel_table[:default_value]
79
- translated_value_col = Lit::Localization.arel_table[:translated_value]
77
+ localization_key_col = FakeLocalizationKey.arel_table[:localization_key]
78
+ default_value_col = FakeLocalization.arel_table[:default_value]
79
+ translated_value_col = FakeLocalization.arel_table[:translated_value]
80
80
  if options[:key_prefix].present?
81
81
  q = "#{options[:key_prefix]}%"
82
82
  s = s.where(localization_key_col.matches(q))
@@ -96,5 +96,12 @@ module Lit
96
96
  end
97
97
  s
98
98
  end
99
+
100
+ class FakeLocalizationKey < ActiveRecord::Base
101
+ self.table_name = 'lit_localization_keys'
102
+ end
103
+ class FakeLocalization < ActiveRecord::Base
104
+ self.table_name = 'lit_localizations'
105
+ end
99
106
  end
100
107
  end
data/lib/lit/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Lit
2
- VERSION = '0.3.1'.freeze
2
+ VERSION = '0.3.3'.freeze
3
3
  end
@@ -8,7 +8,7 @@ namespace :lit do
8
8
  end
9
9
  end
10
10
 
11
- desc 'Reads config/locales/#{ENV["FILES"]} files and calls I18n.t() on keys forcing Lit to import given LOCALE to cache / to display them in UI'
11
+ desc 'Reads config/locales/#{ENV["FILES"]} files and calls I18n.t() on keys forcing Lit to import given LOCALE to cache / to display them in UI. Skips nils by default (change by setting ENV["SKIP_NIL"] = false'
12
12
  task raw_import: :environment do
13
13
  return 'you need to define FILES env' if ENV['FILES'].blank?
14
14
  return 'you need to define LOCALE env' if ENV['LOCALE'].blank?
@@ -19,6 +19,7 @@ namespace :lit do
19
19
  locale_file = File.open(Rails.root.join('config', 'locales', file))
20
20
  yml = YAML.load(locale_file)[locale]
21
21
  Hash[*Lit::Cache.flatten_hash(yml)].each do |key, default_translation|
22
+ next if default_translation.nil? && ENV.fetch('SKIP_NIL', 'true') == 'true'
22
23
  puts key
23
24
  I18n.t(key, default: default_translation)
24
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maciej Litwiniuk
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2018-02-21 00:00:00.000000000 Z
13
+ date: 2018-04-05 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: i18n