i18nliner 0.1.0 → 0.2.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
- SHA1:
3
- metadata.gz: 6bbc698173c1c8e33a96bff6fdd7d0ed5bd87f55
4
- data.tar.gz: 6035d9a25b869329386a8618521399a5d39401ef
2
+ SHA256:
3
+ metadata.gz: 7db05f72a6f74269e7600897f2910d08749e1e8d8a334cbd8678e5ed7fe3640b
4
+ data.tar.gz: 3ee6d0d8ed3bb20ed38f7d639d9b2a151c1a3ff1c3c09dc7379a8246fcbc6599
5
5
  SHA512:
6
- metadata.gz: 5e2e83793439b90a69a7e16db742bc9d385e53953a5872ce90987bf8507b5254594d4edf3ff637d36e30c6f02acf6fc4aaa6703197c430618f9254ca4edf82eb
7
- data.tar.gz: d239eb5dcea8c24fcdccad4870c3cd6b33c9a33898d13c20a1962a8387db64fbdc23aa71a907ac52049d3d6ecf1d49e52a20c38e852875c7a95369bcb3ef7fb7
6
+ metadata.gz: 59db484754a91d810436e65063f705026bbbfdf042a141ca053d0555616a97e83a89cd59cb9654f7d9243ee28a0f81169d1e82f7697b5f55333ea4f55ec71abd
7
+ data.tar.gz: 397e276a16b5fc43603de1abdeb1594ccb3a13ed2709809299f1a68d1b536983a66d37ed5d41684cfeb6eb1e3bda381c8e4e121fb6dbacc0e1903973a3ffc6ce
data/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'rake'
2
+ require 'bundler/gem_tasks'
2
3
 
3
4
  require 'rspec/core'
4
5
  require 'rspec/core/rake_task'
@@ -6,4 +7,4 @@ RSpec::Core::RakeTask.new(:spec) do |spec|
6
7
  spec.pattern = FileList['spec/**/*_spec.rb']
7
8
  end
8
9
 
9
- task :default => :spec
10
+ task :default => :spec
@@ -53,15 +53,24 @@ module I18nliner
53
53
  private
54
54
 
55
55
  def apply_wrappers(string, wrappers)
56
+ # In rails 6.1+ views, sometimes an Object is used for the default, and that object needs to remain
57
+ # an object or it won't be recognized if it comes back as a string
58
+ return string if string.instance_of?(Object)
59
+
56
60
  string = string.html_safe? ? string.dup : ERB::Util.h(string)
57
61
  unless wrappers.is_a?(Hash)
58
62
  wrappers = Array(wrappers)
59
63
  wrappers = Hash[wrappers.each_with_index.map{ |w, i| ['*' * (1 + i), w]}]
60
64
  end
65
+ # If you are actually using nonprintable characters in your source string, you should feel ashamed
66
+ string.gsub!("\\\\", 26.chr)
67
+ string.gsub!("\\*", 27.chr)
61
68
  wrappers.sort_by{ |k, v| -k.length }.each do |k, v|
62
69
  pattern = pattern_for(k)
63
70
  string.gsub!(pattern, v)
64
71
  end
72
+ string.gsub!(27.chr, '*')
73
+ string.gsub!(26.chr, "\\")
65
74
  string.html_safe
66
75
  end
67
76
 
@@ -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.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Jensen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-10 00:00:00.000000000 Z
11
+ date: 2022-08-09 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
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 1.7.1
89
+ version: '1.7'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 1.7.1
96
+ version: '1.7'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: ya2yaml
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -128,28 +128,28 @@ dependencies:
128
128
  requirements:
129
129
  - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: 3.6.0
131
+ version: '3.6'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: 3.6.0
138
+ version: '3.6'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: rspec-mocks
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: 3.6.0
145
+ version: '3.6'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: 3.6.0
152
+ version: '3.6'
153
153
  description: No .yml files. Inline defaults. Optional keys. Inferred interpolation
154
154
  values. Wrappers and blocks, so your templates look template-y and your translations
155
155
  stay HTML-free.
@@ -169,7 +169,6 @@ files:
169
169
  - lib/i18nliner/commands/color_formatter.rb
170
170
  - lib/i18nliner/commands/dump.rb
171
171
  - lib/i18nliner/commands/generic_command.rb
172
- - lib/i18nliner/commands/import.rb
173
172
  - lib/i18nliner/controller_scope.rb
174
173
  - lib/i18nliner/errors.rb
175
174
  - lib/i18nliner/erubi.rb
@@ -189,6 +188,7 @@ files:
189
188
  - lib/i18nliner/processors/erb_processor.rb
190
189
  - lib/i18nliner/processors/ruby_processor.rb
191
190
  - lib/i18nliner/railtie.rb
191
+ - lib/i18nliner/reserved_keys.rb
192
192
  - lib/i18nliner/scope.rb
193
193
  - lib/tasks/i18nliner.rake
194
194
  - spec/commands/check_spec.rb
@@ -206,6 +206,7 @@ files:
206
206
  - spec/pre_processors/erb_pre_processor_spec.rb
207
207
  - spec/processors/erb_processor_spec.rb
208
208
  - spec/processors/ruby_processor_spec.rb
209
+ - spec/reserved_keys_spec.rb
209
210
  homepage: http://github.com/jenseng/i18nliner
210
211
  licenses: []
211
212
  metadata: {}
@@ -217,15 +218,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
217
218
  requirements:
218
219
  - - ">="
219
220
  - !ruby/object:Gem::Version
220
- version: 1.9.3
221
+ version: '2.7'
221
222
  required_rubygems_version: !ruby/object:Gem::Requirement
222
223
  requirements:
223
224
  - - ">="
224
225
  - !ruby/object:Gem::Version
225
226
  version: 1.3.5
226
227
  requirements: []
227
- rubyforge_project:
228
- rubygems_version: 2.6.13
228
+ rubygems_version: 3.1.6
229
229
  signing_key:
230
230
  specification_version: 4
231
231
  summary: I18n made simple
@@ -1,30 +0,0 @@
1
- require 'i18nliner/commands/generic_command'
2
- require 'i18nliner/extractors/translation_hash'
3
- require 'active_support/core_ext/enumerable'
4
- Dir[File.join(File.dirname(__FILE__), "../processors/*.rb")].each do |file|
5
- require "i18nliner/processors/#{File.basename(file)}"
6
- end
7
-
8
- module I18nliner
9
- module Commands
10
- class Import < GenericCommand
11
- attr_reader :translations, :errors
12
-
13
- def initialize(options)
14
- super
15
- end
16
-
17
- def success?
18
- end
19
-
20
- def print_summary
21
- end
22
-
23
- def run
24
- print_summary unless @options[:silent]
25
- success?
26
- end
27
- end
28
- end
29
- end
30
-