i18n-tools 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/i18n/keys/index.rb +2 -2
- data/lib/i18n/parser/erb_parser.rb +5 -5
- data/test/erb_parser_test.rb +23 -6
- data/test/fixtures/template.html.erb +15 -12
- metadata +1 -1
data/lib/i18n/keys/index.rb
CHANGED
@@ -174,8 +174,8 @@ module I18n
|
|
174
174
|
|
175
175
|
def find_occurences(options)
|
176
176
|
files.inject([]) do |result, file|
|
177
|
-
|
178
|
-
|
177
|
+
code = parse(file) || Sexp.new
|
178
|
+
code.find_by_type(:call).select { |call| call[2] == :t }.inject(result) do |result, node|
|
179
179
|
node.each_key_node { |key| result << Occurence.from_sexp(key, file) }
|
180
180
|
result
|
181
181
|
end
|
@@ -7,7 +7,7 @@ $KCODE = 'u'
|
|
7
7
|
|
8
8
|
class String
|
9
9
|
def to_whitespace
|
10
|
-
gsub(
|
10
|
+
gsub(/[^\s;]/, ' ')
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
@@ -15,8 +15,8 @@ module I18n
|
|
15
15
|
class ErbParser
|
16
16
|
class Scanner < ERB::Compiler::Scanner
|
17
17
|
def scan
|
18
|
-
stag_reg = /(.*?)(^[ \t]
|
19
|
-
etag_reg = /(.*?)(
|
18
|
+
stag_reg = /(.*?)(^[ \t]*<%%|<%=|<%#|<%-|<%|\z)/m
|
19
|
+
etag_reg = /(.*?)(%%>|\-%>|%>|\z)/m
|
20
20
|
scanner = StringScanner.new(@src)
|
21
21
|
while !scanner.eos?
|
22
22
|
scanner.scan(@stag ? etag_reg : stag_reg)
|
@@ -35,9 +35,9 @@ module I18n
|
|
35
35
|
comment = true if token == '<%#'
|
36
36
|
if scanner.stag.nil?
|
37
37
|
result << token.to_whitespace
|
38
|
-
scanner.stag = token if ['<%', '<%-', '<%=', '<%#'
|
38
|
+
scanner.stag = token if ['<%', '<%-', '<%=', '<%#'].include?(token)
|
39
39
|
elsif ['%>', '-%>'].include?(token)
|
40
|
-
result << token.to_whitespace
|
40
|
+
result << token.gsub(/>/, ';').to_whitespace
|
41
41
|
scanner.stag = nil
|
42
42
|
else
|
43
43
|
result << (comment ? token.to_whitespace : token) # so, this is the ruby code, then
|
data/test/erb_parser_test.rb
CHANGED
@@ -2,13 +2,30 @@ require File.dirname(__FILE__) + '/test_helper'
|
|
2
2
|
require 'erb'
|
3
3
|
|
4
4
|
class ErbParserTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@erb = File.read("#{File.dirname(__FILE__)}/fixtures/template.html.erb")
|
7
|
+
@ruby = I18n::ErbParser.new.to_ruby(@erb)
|
8
|
+
@expected = <<-src
|
9
|
+
f.field_set do
|
10
|
+
column do
|
11
|
+
[:foo].each do |foo|
|
12
|
+
t(:erb_1)
|
13
|
+
end
|
14
|
+
t(:erb_2)
|
15
|
+
t(:'foo.erb_3')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
src
|
19
|
+
end
|
20
|
+
|
5
21
|
def test_sexp_filename
|
6
|
-
erb
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
22
|
+
assert_equal @erb.length, @ruby.length
|
23
|
+
%w(erb_1 erb_2 foo.erb_3).each do |token|
|
24
|
+
assert @ruby.index(token)
|
25
|
+
assert_equal @erb.index(token), @ruby.index(token)
|
26
|
+
end
|
27
|
+
@expected.split("\n").each do |token|
|
28
|
+
assert @ruby.index(token)
|
12
29
|
end
|
13
30
|
end
|
14
31
|
end
|
@@ -1,19 +1,22 @@
|
|
1
1
|
<html>
|
2
2
|
<ul>
|
3
|
-
<%
|
4
|
-
|
3
|
+
<% f.field_set do %>
|
4
|
+
<% column do %>
|
5
|
+
<% [:foo].each do |foo| %>
|
6
|
+
<li>
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
<% end %>
|
12
|
-
<br>
|
13
|
-
|
14
|
-
<%- t(:erb_2) -%>
|
8
|
+
<span><%= t(:erb_1) %></span>
|
9
|
+
<%#= comment
|
10
|
+
comment
|
11
|
+
comment %>
|
12
|
+
</li>
|
13
|
+
<% end %>
|
14
|
+
<br>
|
15
15
|
|
16
|
-
<%- t(:
|
16
|
+
<%- t(:erb_2) -%>
|
17
17
|
|
18
|
+
<% t(:'foo.erb_3') %> <% bar %>
|
19
|
+
<% end %>
|
20
|
+
<% end %>
|
18
21
|
</ul>
|
19
22
|
</html>
|