haml-i18n-extractor 0.5.4 → 0.5.5
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.
- data/haml-i18n-extractor.gemspec +2 -0
- data/lib/haml-i18n-extractor.rb +4 -2
- data/lib/haml-i18n-extractor/extraction/extractor.rb +1 -1
- data/lib/haml-i18n-extractor/extraction/replacer/interpolation_helper.rb +1 -1
- data/lib/haml-i18n-extractor/extraction/replacer/text_replacer.rb +28 -11
- data/lib/haml-i18n-extractor/helpers.rb +1 -1
- data/lib/haml-i18n-extractor/version.rb +1 -1
- data/test/interpolation_helper_test.rb +2 -2
- data/test/support/ex2.output.haml +1 -1
- data/test/support/ex3.haml +2 -0
- data/test/support/ex3.output.haml +4 -2
- data/test/support/ex5.haml +2 -0
- data/test/support/ex5.output.haml +5 -3
- data/test/support/ex5.yml +1 -0
- data/test/text_replacer_test.rb +0 -10
- metadata +36 -8
data/haml-i18n-extractor.gemspec
CHANGED
@@ -26,6 +26,8 @@ Gem::Specification.new do |gem|
|
|
26
26
|
gem.add_development_dependency 'rbench'
|
27
27
|
gem.add_development_dependency 'm'
|
28
28
|
gem.add_development_dependency 'pry'
|
29
|
+
gem.add_development_dependency 'pry-remote'
|
30
|
+
gem.add_development_dependency 'pry-nav'
|
29
31
|
gem.add_development_dependency 'minitest'
|
30
32
|
gem.add_development_dependency 'nokogiri'
|
31
33
|
gem.add_development_dependency 'rake'
|
data/lib/haml-i18n-extractor.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
-
|
2
|
-
Encoding.
|
1
|
+
if defined?(Encoding)
|
2
|
+
Encoding.default_internal = Encoding::UTF_8 if Encoding.respond_to?(:default_internal)
|
3
|
+
Encoding.default_external = Encoding::UTF_8 if Encoding.respond_to?(:default_external)
|
4
|
+
end
|
3
5
|
|
4
6
|
require "trollop"
|
5
7
|
|
@@ -17,7 +17,7 @@ module Haml
|
|
17
17
|
class AbortFile < StandardError ; end
|
18
18
|
|
19
19
|
LINE_TYPES_ALL = [:plain, :script, :silent_script, :haml_comment, :tag, :comment, :doctype, :filter, :root]
|
20
|
-
LINE_TYPES_ADD_EVAL = [:plain, :tag]
|
20
|
+
LINE_TYPES_ADD_EVAL = [:plain, :tag, :script]
|
21
21
|
|
22
22
|
attr_reader :haml_reader, :haml_writer
|
23
23
|
attr_reader :info_for_yaml, :yaml_writer, :type
|
@@ -33,14 +33,18 @@ module Haml
|
|
33
33
|
Haml::I18n::Extractor::InterpolationHelper.new(@text_to_replace, t_name)
|
34
34
|
end
|
35
35
|
|
36
|
+
def orig_interpolated?
|
37
|
+
interpolated?(@orig_line)
|
38
|
+
end
|
39
|
+
|
36
40
|
# the new full line, including a `t()` replacement instead of the `text_to_replace` portion.
|
37
41
|
def modified_line
|
38
42
|
return @full_line if has_been_translated?(@full_line)
|
39
43
|
full_line = @full_line.dup
|
40
44
|
#puts t_method.inspect if Haml::I18n::Extractor.debug?
|
41
|
-
keyname =
|
42
|
-
gsub_replacement!(full_line, @text_to_replace,
|
43
|
-
apply_ruby_evaling(full_line)
|
45
|
+
keyname = orig_interpolated? ? interpolation_helper.keyname_with_vars : t_method
|
46
|
+
gsub_replacement!(full_line, @text_to_replace, keyname)
|
47
|
+
apply_ruby_evaling!(full_line, keyname)
|
44
48
|
full_line
|
45
49
|
end
|
46
50
|
|
@@ -71,32 +75,45 @@ module Haml
|
|
71
75
|
end
|
72
76
|
|
73
77
|
# adds the = to the right place in the string ... = t()
|
74
|
-
def apply_ruby_evaling(str)
|
78
|
+
def apply_ruby_evaling!(str, keyname)
|
75
79
|
if LINE_TYPES_ADD_EVAL.include?(@line_type)
|
76
80
|
if @line_type == :tag
|
77
|
-
match_keyname = Regexp.new('[\s\t]*' + Regexp.escape(
|
81
|
+
match_keyname = Regexp.new('[\s\t]*' + Regexp.escape(keyname))
|
78
82
|
str.match(/(.*?)(#{match_keyname})/)
|
79
83
|
elem = $1
|
80
84
|
if elem
|
81
85
|
str.gsub!(Regexp.new(Regexp.escape(elem)), "#{elem}=") unless already_evaled?(elem)
|
82
86
|
end
|
83
|
-
elsif @line_type == :plain
|
87
|
+
elsif @line_type == :plain || (@line_type == :script && !already_evaled?(full_line))
|
84
88
|
str.gsub!(str, "= "+str)
|
85
89
|
end
|
86
90
|
end
|
87
91
|
end
|
88
92
|
|
89
|
-
def already_evaled?(
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
+
def already_evaled?(str)
|
94
|
+
if @line_type == :tag
|
95
|
+
if orig_interpolated?
|
96
|
+
# for tags that come in interpolated we need to explicitly
|
97
|
+
# check that they aren't evaled alreay, the metadata lies
|
98
|
+
# %tag foo #{var} bar
|
99
|
+
str.split('').last == '='
|
100
|
+
else
|
101
|
+
@metadata[:value] && @metadata[:value][:parse]
|
102
|
+
end
|
103
|
+
elsif @line_type == :script
|
104
|
+
# we need this for tags that come in like :plain but have interpolation
|
105
|
+
str.match(/^[\s\t]*=/)
|
106
|
+
end
|
93
107
|
end
|
94
108
|
|
95
109
|
def has_been_translated?(str)
|
96
110
|
str.match T_REGEX
|
97
111
|
end
|
98
112
|
|
99
|
-
def gsub_replacement!(str, text_to_replace,
|
113
|
+
def gsub_replacement!(str, text_to_replace, keyname_method)
|
114
|
+
# FIXME refactor this method
|
115
|
+
text_to_replace = $1 if (orig_interpolated? && text_to_replace.match(/^['"](.*)['"]$/))
|
116
|
+
|
100
117
|
# if there are quotes surrounding the string, we want them removed as well...
|
101
118
|
unless str.gsub!('"' + text_to_replace + '"', keyname_method )
|
102
119
|
unless str.gsub!("'" + text_to_replace + "'", keyname_method)
|
@@ -6,7 +6,7 @@ module Haml
|
|
6
6
|
module StringHelpers
|
7
7
|
|
8
8
|
# do not pollute the key space it will make it invalid yaml
|
9
|
-
NOT_ALLOWED_IN_KEYNAME = %w( ~ ` ! @ # $ % ^ & * - ( ) , ? { } = ' " : ;
|
9
|
+
NOT_ALLOWED_IN_KEYNAME = %w( ~ ` ! @ # $ % ^ & * - ( ) , ? { } = ' " : ; \\ / . | )
|
10
10
|
# limit the number of chars
|
11
11
|
LIMIT_KEY_NAME = 30
|
12
12
|
|
@@ -15,7 +15,7 @@ module Haml
|
|
15
15
|
replace = "this may \#{be} the \#{dup}"
|
16
16
|
t_name = "this_may_be_the_dup"
|
17
17
|
helper = Haml::I18n::Extractor::InterpolationHelper.new(replace, t_name)
|
18
|
-
assert helper.keyname_with_vars == "t('.this_may_be_the_dup', :be => be, :dup => dup)",
|
18
|
+
assert helper.keyname_with_vars == "t('.this_may_be_the_dup', :be => (be), :dup => (dup))",
|
19
19
|
"returns custom t() with vars"
|
20
20
|
end
|
21
21
|
|
@@ -26,7 +26,7 @@ module Haml
|
|
26
26
|
assert helper.interpolations == ["is_this_hard?"], "can catch the interpolations"
|
27
27
|
x = helper.keyname_with_vars
|
28
28
|
#puts x.inspect
|
29
|
-
assert x == "t('.is_this_hard_what', :is_this_hard => is_this_hard?)",
|
29
|
+
assert x == "t('.is_this_hard_what', :is_this_hard => (is_this_hard?))",
|
30
30
|
"returns custom t() with vars"
|
31
31
|
end
|
32
32
|
|
@@ -8,7 +8,7 @@
|
|
8
8
|
%h3
|
9
9
|
= t('.all_invoices_billable')
|
10
10
|
%span{:style => (@billable_invoices == @active_invoices) ? "color: #090" : "color: #900"}
|
11
|
-
=t('.billable_invoices_out_of_activ', :billable_invoices => @billable_invoices, :active_invoices => @active_invoices)
|
11
|
+
=t('.billable_invoices_out_of_activ', :billable_invoices => (@billable_invoices), :active_invoices => (@active_invoices))
|
12
12
|
%h3
|
13
13
|
= t('.24_hours_past_end_of_billing_m')
|
14
14
|
%span{:style => (@billing_month.past_cutoff) ? "color: #090" : "color: #900"}
|
data/test/support/ex3.haml
CHANGED
@@ -6,8 +6,10 @@
|
|
6
6
|
|
7
7
|
%span.creator{:title => "This user is an= t('.owner') of this account"} t('.owner')
|
8
8
|
%span.title&= user.name
|
9
|
-
%strong
|
9
|
+
%strong= t('.accountname', :accountname => (@account.name))
|
10
10
|
|
11
11
|
%table(style="width:400px")
|
12
12
|
%td= t('.td')
|
13
|
-
%td
|
13
|
+
%td= t('.accountsendattr_none', :accountsendattr_none => (@account.send(attr) || '(none)'))
|
14
|
+
|
15
|
+
%p#brand= link_to t('.some_place'), '/'
|
data/test/support/ex5.haml
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
.class= t('.text_here')
|
2
|
-
.other-class#id= t('.script_with_quote_with_interpo', :with_interpolationbub => with_interpolation(bub))
|
2
|
+
.other-class#id= t('.script_with_quote_with_interpo', :with_interpolationbub => (with_interpolation(bub)))
|
3
3
|
|
4
|
-
=t('.this_may_be_the_dup', :be => be, :dup => dup)
|
5
|
-
= link_to t('.adnamefirst', :adnamefirst => ad.name.first), url_for([ad, :ok])
|
4
|
+
=t('.this_may_be_the_dup', :be => (be), :dup => (dup))
|
5
|
+
= link_to t('.adnamefirst', :adnamefirst => (ad.name.first)), url_for([ad, :ok])
|
6
|
+
|
7
|
+
= t('.no_quotes_some_var_with_text', :some_var => (some_var))
|
data/test/support/ex5.yml
CHANGED
data/test/text_replacer_test.rb
CHANGED
@@ -43,16 +43,6 @@ module Haml
|
|
43
43
|
:t_name => "admin_dashboard", :replaced_text => "t('.admin_dashboard')", :path => "/path/to/doesntmatter.haml" }
|
44
44
|
end
|
45
45
|
|
46
|
-
def test_it_can_replace_the_body_of_haml_with_t_characters_example_for_link_to_and_removes_surrounding_quotes_as_well
|
47
|
-
replacer = Haml::I18n::Extractor::TextReplacer.new(%{%p#brand= link_to 'Some Place', '/'}, "Some Place", :script, "/path/to/doesntmatter.haml")
|
48
|
-
assert_equal replacer.replace_hash, { :modified_line => %{%p#brand= link_to t('.some_place'), '/'} ,
|
49
|
-
:t_name => "some_place", :replaced_text => "Some Place", :path => "/path/to/doesntmatter.haml" }
|
50
|
-
|
51
|
-
replacer = Haml::I18n::Extractor::TextReplacer.new(%{%p#brand= link_to "Some Place", "/"}, "Some Place", :script, "/path/to/doesntmatter.haml")
|
52
|
-
assert_equal replacer.replace_hash, { :modified_line => %{%p#brand= link_to t('.some_place'), "/"} ,
|
53
|
-
:t_name => "some_place", :replaced_text => "Some Place", :path => "/path/to/doesntmatter.haml" }
|
54
|
-
end
|
55
|
-
|
56
46
|
# keyname restrictions
|
57
47
|
def test_it_limits_the_characters_of_the_t_namespace_it_provides_to_limit_key_name
|
58
48
|
replacer = Haml::I18n::Extractor::TextReplacer.new("this is whatever" * 80, "this is whatever" * 80, :plain, "/path/to/doesntmatter.haml")
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: haml-i18n-extractor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 1
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 5
|
9
|
-
-
|
10
|
-
version: 0.5.
|
9
|
+
- 5
|
10
|
+
version: 0.5.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Shai Rosenfeld
|
@@ -132,7 +132,7 @@ dependencies:
|
|
132
132
|
type: :development
|
133
133
|
version_requirements: *id008
|
134
134
|
- !ruby/object:Gem::Dependency
|
135
|
-
name:
|
135
|
+
name: pry-remote
|
136
136
|
prerelease: false
|
137
137
|
requirement: &id009 !ruby/object:Gem::Requirement
|
138
138
|
none: false
|
@@ -146,7 +146,7 @@ dependencies:
|
|
146
146
|
type: :development
|
147
147
|
version_requirements: *id009
|
148
148
|
- !ruby/object:Gem::Dependency
|
149
|
-
name:
|
149
|
+
name: pry-nav
|
150
150
|
prerelease: false
|
151
151
|
requirement: &id010 !ruby/object:Gem::Requirement
|
152
152
|
none: false
|
@@ -160,7 +160,7 @@ dependencies:
|
|
160
160
|
type: :development
|
161
161
|
version_requirements: *id010
|
162
162
|
- !ruby/object:Gem::Dependency
|
163
|
-
name:
|
163
|
+
name: minitest
|
164
164
|
prerelease: false
|
165
165
|
requirement: &id011 !ruby/object:Gem::Requirement
|
166
166
|
none: false
|
@@ -174,7 +174,7 @@ dependencies:
|
|
174
174
|
type: :development
|
175
175
|
version_requirements: *id011
|
176
176
|
- !ruby/object:Gem::Dependency
|
177
|
-
name:
|
177
|
+
name: nokogiri
|
178
178
|
prerelease: false
|
179
179
|
requirement: &id012 !ruby/object:Gem::Requirement
|
180
180
|
none: false
|
@@ -188,7 +188,7 @@ dependencies:
|
|
188
188
|
type: :development
|
189
189
|
version_requirements: *id012
|
190
190
|
- !ruby/object:Gem::Dependency
|
191
|
-
name:
|
191
|
+
name: rake
|
192
192
|
prerelease: false
|
193
193
|
requirement: &id013 !ruby/object:Gem::Requirement
|
194
194
|
none: false
|
@@ -201,6 +201,34 @@ dependencies:
|
|
201
201
|
version: "0"
|
202
202
|
type: :development
|
203
203
|
version_requirements: *id013
|
204
|
+
- !ruby/object:Gem::Dependency
|
205
|
+
name: actionpack
|
206
|
+
prerelease: false
|
207
|
+
requirement: &id014 !ruby/object:Gem::Requirement
|
208
|
+
none: false
|
209
|
+
requirements:
|
210
|
+
- - ">="
|
211
|
+
- !ruby/object:Gem::Version
|
212
|
+
hash: 3
|
213
|
+
segments:
|
214
|
+
- 0
|
215
|
+
version: "0"
|
216
|
+
type: :development
|
217
|
+
version_requirements: *id014
|
218
|
+
- !ruby/object:Gem::Dependency
|
219
|
+
name: rails
|
220
|
+
prerelease: false
|
221
|
+
requirement: &id015 !ruby/object:Gem::Requirement
|
222
|
+
none: false
|
223
|
+
requirements:
|
224
|
+
- - ">="
|
225
|
+
- !ruby/object:Gem::Version
|
226
|
+
hash: 3
|
227
|
+
segments:
|
228
|
+
- 0
|
229
|
+
version: "0"
|
230
|
+
type: :development
|
231
|
+
version_requirements: *id015
|
204
232
|
description: Parse the texts out of the haml files into localization files
|
205
233
|
email:
|
206
234
|
- shaiguitar@gmail.com
|