i18nliner 0.1.1 → 0.2.1

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
  SHA256:
3
- metadata.gz: b2db12d6bdf711b5e95c9a5d4ad41b9f89099090bcb3be1555d0487beaf643cb
4
- data.tar.gz: c8f147f4df24fca4cd39f5960d168431947ef2b3963a67b771394ff86a5d5cdc
3
+ metadata.gz: 49a54d15655300760797d011db9521a123b23892478badcee8cfab3c7c890e25
4
+ data.tar.gz: 97409ad1106e9ed7c68567038bca41495e204545fce5b605b2b30e591072c399
5
5
  SHA512:
6
- metadata.gz: 668686f434bf422b7eea80e953274702946f3698c56f3a5d3f74fb8f679230d52babb1454a7722c4df3c4dcbe48fed09a1b0dc662bc5fab744f8b14ce618c916
7
- data.tar.gz: a953fff2982e2266056f065c0375b5c5631d005092bdd6f5a07f631e83eda27d3e8bae1a2cf5d21f34f734950b42654cad8396262c53faa507731045b54e089e
6
+ metadata.gz: d81cc7123036ef5a7f19224d2400b384f4049bee9be1ea9a99d40b12ea2db8739f547861e93bff7c51f7639c1877c0ae672a850325e85a59817ba678b455d31a
7
+ data.tar.gz: 0b465bc13a850bd61ffdbc2459d698f55719cc5cc5cab1bd55ca8e8bfabba8a12a7214def2c95a0fd682b50d4fd4af03092fd4815702081524f1fe92e468a18c
@@ -18,9 +18,19 @@ module I18nliner
18
18
 
19
19
  wrappers = options.delete(:wrappers) || options.delete(:wrapper)
20
20
  result = super(key, options)
21
+
22
+ # In rails 6.1+ views, sometimes an Object is used for the default, and that object needs to remain
23
+ # an object or it won't be recognized if it comes back as a string
24
+ return result if result.nil? || result.instance_of?(Object)
25
+
26
+ # If you are actually using nonprintable characters in your source string, you should feel ashamed
27
+ result = result.gsub("\\\\", "\uE124").gsub("\\*", "\uE123")
21
28
  if wrappers
22
29
  result = apply_wrappers(result, wrappers)
23
30
  end
31
+ was_html_safe = result.html_safe?
32
+ result = result.gsub("\uE123", '*').gsub("\uE124", "\\")
33
+ result = result.html_safe if was_html_safe
24
34
 
25
35
  result
26
36
  rescue ArgumentError
@@ -58,10 +68,15 @@ module I18nliner
58
68
  wrappers = Array(wrappers)
59
69
  wrappers = Hash[wrappers.each_with_index.map{ |w, i| ['*' * (1 + i), w]}]
60
70
  end
71
+ # If you are actually using nonprintable characters in your source string, you should feel ashamed
72
+ string.gsub!("\\\\", 26.chr)
73
+ string.gsub!("\\*", 27.chr)
61
74
  wrappers.sort_by{ |k, v| -k.length }.each do |k, v|
62
75
  pattern = pattern_for(k)
63
76
  string.gsub!(pattern, v)
64
77
  end
78
+ string.gsub!(27.chr, '*')
79
+ string.gsub!(26.chr, "\\")
65
80
  string.html_safe
66
81
  end
67
82
 
@@ -23,7 +23,7 @@ module I18nliner
23
23
  File.read(file)
24
24
  end
25
25
 
26
- if defined?(::Rails) && ::Rails.version > '4'
26
+ if defined?(::Rails)
27
27
  CONTROLLER_PATH = %r{\A(.*/)?app/controllers/(.*)_controller\.rb\z}
28
28
  def scope_for(path)
29
29
  scope = path.dup
@@ -0,0 +1,4 @@
1
+ keys = I18n::RESERVED_KEYS.dup
2
+ keys << :i18nliner_scope << :i18nliner_inferred_key
3
+ I18n.send(:remove_const, :RESERVED_KEYS)
4
+ I18n.const_set(:RESERVED_KEYS, keys)
data/lib/i18nliner.rb CHANGED
@@ -3,6 +3,6 @@ require 'i18nliner/base'
3
3
 
4
4
  require 'i18nliner/extensions/core'
5
5
  I18n.send :extend, I18nliner::Extensions::Core
6
- I18n::RESERVED_KEYS << :i18nliner_scope << :i18nliner_inferred_key
6
+ require 'i18nliner/reserved_keys'
7
7
 
8
8
  require 'i18nliner/railtie' if defined?(Rails)
@@ -77,6 +77,11 @@ describe I18nliner::Extensions::Core do
77
77
  expect(i18n.translate("*bacon* > narwhals", :wrappers => ['<b>\1</b>'])).
78
78
  to eq "<b>bacon</b> &gt; narwhals"
79
79
  end
80
+
81
+ it "should allow escaping asterisks and backslashes" do
82
+ result = i18n.translate("Hello \\\\*b\\*b*.", :wrapper => '<b>\1</b>')
83
+ expect(result).to eq 'Hello \<b>b*b</b>.'
84
+ end
80
85
  end
81
86
  end
82
87
 
@@ -9,7 +9,7 @@ describe I18nliner::Processors::RubyProcessor do
9
9
  end
10
10
 
11
11
  describe "#scope_for" do
12
- if defined?(::Rails) && ::Rails.version > '4'
12
+ if defined?(::Rails)
13
13
  context "with a controller" do
14
14
  subject { @processor.scope_for("app/controllers/foos/bars_controller.rb") }
15
15
 
@@ -0,0 +1,8 @@
1
+ require 'i18nliner/reserved_keys'
2
+
3
+ describe I18n do
4
+ it "adds new reserved keys" do
5
+ expect(I18n::RESERVED_KEYS).to include(:i18nliner_scope)
6
+ expect(I18n::RESERVED_KEYS).to include(:i18nliner_inferred_key)
7
+ end
8
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18nliner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Jensen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-07 00:00:00.000000000 Z
11
+ date: 2022-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '3.0'
19
+ version: '6.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '3.0'
26
+ version: '6.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: ruby_parser
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -188,6 +188,7 @@ files:
188
188
  - lib/i18nliner/processors/erb_processor.rb
189
189
  - lib/i18nliner/processors/ruby_processor.rb
190
190
  - lib/i18nliner/railtie.rb
191
+ - lib/i18nliner/reserved_keys.rb
191
192
  - lib/i18nliner/scope.rb
192
193
  - lib/tasks/i18nliner.rake
193
194
  - spec/commands/check_spec.rb
@@ -205,6 +206,7 @@ files:
205
206
  - spec/pre_processors/erb_pre_processor_spec.rb
206
207
  - spec/processors/erb_processor_spec.rb
207
208
  - spec/processors/ruby_processor_spec.rb
209
+ - spec/reserved_keys_spec.rb
208
210
  homepage: http://github.com/jenseng/i18nliner
209
211
  licenses: []
210
212
  metadata: {}
@@ -216,14 +218,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
216
218
  requirements:
217
219
  - - ">="
218
220
  - !ruby/object:Gem::Version
219
- version: 1.9.3
221
+ version: '2.7'
220
222
  required_rubygems_version: !ruby/object:Gem::Requirement
221
223
  requirements:
222
224
  - - ">="
223
225
  - !ruby/object:Gem::Version
224
226
  version: 1.3.5
225
227
  requirements: []
226
- rubygems_version: 3.0.3
228
+ rubygems_version: 3.1.6
227
229
  signing_key:
228
230
  specification_version: 4
229
231
  summary: I18n made simple