i18nliner 0.1.2 → 0.2.2

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: cfc705d5ce5735092cebbf57dd2d4241e0f9c29565163a7a300659b7b8fb39a1
4
- data.tar.gz: e477d3007a6ecfa1914bc2acf0798f84ca00d0f75a18450e793fc47743b3a45a
3
+ metadata.gz: f9f3816293c70dfd95ca1cd66cb80d611f283c416e2dc0bd9eec08723d33f32e
4
+ data.tar.gz: e41ce0ba376064862cc64d063b2ac2cdf48002136446079f403255e9cb6a69b9
5
5
  SHA512:
6
- metadata.gz: c9b27ba1617c266b3b627848ba465beb66674e55733274c5a850069845bea80c60acdddaea07cad3ed5de8c36ff432f159ffae7595cef4d94ba181f6f742a351
7
- data.tar.gz: 736d2e7a69ededb1cc61d2cc6e6538c4ce1d187e58ea54a6c7dde845b6c22ac03d86b2677fdcd58d30e01c6dcdd39a79e00f1d83d608d510bbf571c66bb309d6
6
+ metadata.gz: b31d8fdd70c548e770d92584e9c35f6ce15ca60a6bc8a1d835cb2b90653b6de63029d35fcd2465245d473f1cab5914634a290faa344c8a5ec0e115dfcb4947b1
7
+ data.tar.gz: 90a338c6438b59dfa6b0f51af4f4c97b747b068390e975f68e8a6af9ba5ddf3b0c735ffc2e46ca7fe63effc8c5ce2f037e6a808b6a50ae197a9d5110a5088895
@@ -18,9 +18,20 @@ module I18nliner
18
18
 
19
19
  wrappers = options.delete(:wrappers) || options.delete(:wrapper)
20
20
  result = super(key, options)
21
+
22
+ # Exit now unless we have a string or a thing that delegates to a string
23
+ return result unless result.respond_to?(:gsub)
24
+
25
+ was_html_safe = result.html_safe?
26
+ # If you are actually using nonprintable characters in your source string, you should feel ashamed
27
+ result = result.gsub("\\\\", "\uE124").gsub("\\*", "\uE123")
28
+ result = result.html_safe if was_html_safe
21
29
  if wrappers
22
30
  result = apply_wrappers(result, wrappers)
23
31
  end
32
+ was_html_safe = result.html_safe?
33
+ result = result.gsub("\uE123", '*').gsub("\uE124", "\\")
34
+ result = result.html_safe if was_html_safe
24
35
 
25
36
  result
26
37
  rescue ArgumentError
@@ -58,10 +69,15 @@ module I18nliner
58
69
  wrappers = Array(wrappers)
59
70
  wrappers = Hash[wrappers.each_with_index.map{ |w, i| ['*' * (1 + i), w]}]
60
71
  end
72
+ # If you are actually using nonprintable characters in your source string, you should feel ashamed
73
+ string.gsub!("\\\\", 26.chr)
74
+ string.gsub!("\\*", 27.chr)
61
75
  wrappers.sort_by{ |k, v| -k.length }.each do |k, v|
62
76
  pattern = pattern_for(k)
63
77
  string.gsub!(pattern, v)
64
78
  end
79
+ string.gsub!(27.chr, '*')
80
+ string.gsub!(26.chr, "\\")
65
81
  string.html_safe
66
82
  end
67
83
 
@@ -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
@@ -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
 
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.2
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Jensen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-25 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
@@ -218,14 +218,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
218
218
  requirements:
219
219
  - - ">="
220
220
  - !ruby/object:Gem::Version
221
- version: 1.9.3
221
+ version: '2.7'
222
222
  required_rubygems_version: !ruby/object:Gem::Requirement
223
223
  requirements:
224
224
  - - ">="
225
225
  - !ruby/object:Gem::Version
226
226
  version: 1.3.5
227
227
  requirements: []
228
- rubygems_version: 3.0.3
228
+ rubygems_version: 3.1.6
229
229
  signing_key:
230
230
  specification_version: 4
231
231
  summary: I18n made simple