i15r 0.4.4 → 0.5.0
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/.travis.yml +7 -0
- data/Gemfile.lock +1 -1
- data/README.markdown +31 -12
- data/bin/i15r +39 -4
- data/lib/i15r.rb +88 -3
- data/lib/i15r/console_printer.rb +13 -0
- data/lib/i15r/file_reader.rb +7 -0
- data/lib/i15r/file_writer.rb +7 -0
- data/lib/i15r/pattern_matcher.rb +154 -3
- data/lib/i15r/version.rb +2 -2
- data/spec/i15r_spec.rb +73 -71
- data/spec/pattern_matcher_spec.rb +190 -14
- data/spec/spec_helper.rb +37 -2
- data/spec/support/internationalize_matcher.rb +20 -0
- metadata +14 -47
- data/VERSION +0 -1
- data/lib/i15r/base.rb +0 -123
- data/lib/i15r/pattern_matchers/base.rb +0 -40
- data/lib/i15r/pattern_matchers/erb.rb +0 -10
- data/lib/i15r/pattern_matchers/erb/rails_helper_matcher.rb +0 -75
- data/lib/i15r/pattern_matchers/erb/tag_attribute_matcher.rb +0 -26
- data/lib/i15r/pattern_matchers/erb/tag_content_matcher.rb +0 -40
- data/lib/i15r/pattern_matchers/haml.rb +0 -9
- data/lib/i15r/pattern_matchers/haml/rails_helper_matcher.rb +0 -83
- data/lib/i15r/pattern_matchers/haml/tag_content_matcher.rb +0 -52
- data/spec/erb/rails_helper_matcher_spec.rb +0 -81
- data/spec/erb/tag_attribute_matcher_spec.rb +0 -19
- data/spec/erb/tag_content_matcher_spec.rb +0 -43
- data/spec/haml/rails_helper_matcher_spec.rb +0 -92
- data/spec/haml/tag_content_matcher_spec.rb +0 -82
@@ -1,83 +0,0 @@
|
|
1
|
-
module I15R
|
2
|
-
module PatternMatchers
|
3
|
-
module Haml
|
4
|
-
class RailsHelperMatcher < Base
|
5
|
-
|
6
|
-
def self.run(text, prefix)
|
7
|
-
super(text, prefix, :haml)
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.match_haml_tag_and_link_to_title
|
11
|
-
#TODO: allow parens around link_to arguments
|
12
|
-
patt = /^(.*%\w+=\s*)link_to\s+['"](.*?)['"]\s*,(.*)$/
|
13
|
-
matches(:haml) do |text, prefix|
|
14
|
-
if m = patt.match(text)
|
15
|
-
i18n_string = I15R::Base.get_i18n_message_string(m[2], prefix)
|
16
|
-
i18ned_row = %(#{m[1]}link_to I18n.t("#{i18n_string}"),#{m[3]})
|
17
|
-
[m[0], i18ned_row]
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
register_matcher :match_haml_tag_and_link_to_title
|
22
|
-
|
23
|
-
def self.match_haml_implicit_div_tag_and_link_to_title
|
24
|
-
#TODO: allow parens around link_to arguments
|
25
|
-
patt = /^(.*#[\w\d\-_]+=\s*)link_to\s+['"](.*?)['"]\s*,(.*)$/
|
26
|
-
matches(:haml) do |text, prefix|
|
27
|
-
if m = patt.match(text)
|
28
|
-
i18n_string = I15R::Base.get_i18n_message_string(m[2], prefix)
|
29
|
-
i18ned_row = %(#{m[1]}link_to I18n.t("#{i18n_string}"),#{m[3]})
|
30
|
-
[m[0], i18ned_row]
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
register_matcher :match_haml_implicit_div_tag_and_link_to_title
|
35
|
-
|
36
|
-
def self.match_haml_label_helper_text
|
37
|
-
patt = /^(.*=.*\.label.*,\s*)['"](.*?)['"](.*)$/
|
38
|
-
matches(:haml) do |text, prefix|
|
39
|
-
if m = patt.match(text)
|
40
|
-
i18n_string = I15R::Base.get_i18n_message_string(m[2], prefix)
|
41
|
-
i18ned_row = %(#{m[1]}I18n.t("#{i18n_string}"))
|
42
|
-
[m[0], i18ned_row]
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
register_matcher :match_haml_label_helper_text
|
47
|
-
|
48
|
-
def self.match_haml_text_and_link_to_with_parens
|
49
|
-
# that's good for the parentheses version
|
50
|
-
patt = /^(.*=)(.*)#\{link_to\(['"](.*?)['"],(\s*[\w_]+)\)\}.*$/
|
51
|
-
matches(:haml) do |text, prefix|
|
52
|
-
if m = patt.match(text)
|
53
|
-
pre_text = I15R::Base.get_i18n_message_string(m[2], prefix)
|
54
|
-
link_to_title = I15R::Base.get_i18n_message_string(m[3], prefix)
|
55
|
-
i18ned_row = %(#{m[1]} I18n.t("#{pre_text}", :link => link_to(I18n.t("#{link_to_title}"),#{m[4]})#{m[5]}))
|
56
|
-
[m[0], i18ned_row]
|
57
|
-
end
|
58
|
-
end
|
59
|
-
# %q(= "I accept the #{link_to 'terms and conditions', terms_and_conditions_path}"
|
60
|
-
# = I18n.t("users.new.i_accept_the", :link => link_to(I18n.t("users.new.terms_and_conditions"), terms_and_conditions_path))
|
61
|
-
end
|
62
|
-
register_matcher :match_haml_text_and_link_to_with_parens
|
63
|
-
|
64
|
-
def self.match_haml_text_and_link_to_without_parens
|
65
|
-
# that's good for the parentheses version
|
66
|
-
patt = /^(.*=)(.*)#\{link_to\s+['"](.*?)['"],(\s*[\w_]+)\}.*$/
|
67
|
-
matches(:haml) do |text, prefix|
|
68
|
-
if m = patt.match(text)
|
69
|
-
pre_text = I15R::Base.get_i18n_message_string(m[2], prefix)
|
70
|
-
link_to_title = I15R::Base.get_i18n_message_string(m[3], prefix)
|
71
|
-
i18ned_row = %(#{m[1]} I18n.t("#{pre_text}", :link => link_to(I18n.t("#{link_to_title}"),#{m[4]})#{m[5]}))
|
72
|
-
[m[0], i18ned_row]
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
register_matcher :match_haml_text_and_link_to_without_parens
|
77
|
-
|
78
|
-
|
79
|
-
end
|
80
|
-
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
module I15R
|
2
|
-
module PatternMatchers
|
3
|
-
module Haml
|
4
|
-
class TagContentMatcher < Base
|
5
|
-
|
6
|
-
def self.run(text, prefix)
|
7
|
-
super(text, prefix, :haml)
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.match_haml_implicit_div_tag_content
|
11
|
-
#TODO: really ugly. so many negative groups
|
12
|
-
# to prevent #new-user-link= link_to '...', new_user_path to match
|
13
|
-
patt = /^(.*#[^\s=]+)\s+([^\s=]+[^=]*)$/
|
14
|
-
matches(:haml) do |text, prefix|
|
15
|
-
if m = patt.match(text)
|
16
|
-
i18n_string = I15R::Base.get_i18n_message_string(m[2], prefix)
|
17
|
-
i18ned_row = %(#{m[1]}= I18n.t("#{i18n_string}"))
|
18
|
-
[m[0], i18ned_row]
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
register_matcher :match_haml_implicit_div_tag_content
|
23
|
-
|
24
|
-
def self.match_haml_explicit_tag_content
|
25
|
-
patt = /^(.*%[\w]+)\s+(.*)$/
|
26
|
-
matches(:haml) do |text, prefix|
|
27
|
-
if m = patt.match(text)
|
28
|
-
i18n_string = I15R::Base.get_i18n_message_string(m[2], prefix)
|
29
|
-
i18ned_row = %(#{m[1]}= I18n.t("#{i18n_string}"))
|
30
|
-
[m[0], i18ned_row]
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
register_matcher :match_haml_explicit_tag_content
|
35
|
-
|
36
|
-
def self.match_haml_tag_content_just_text_on_line
|
37
|
-
patt = /^(\s*)([^.#!%=\/\s][[:alpha:][:upper:]\s\d\!\-\.\?\/]+)$/
|
38
|
-
matches(:haml) do |text, prefix|
|
39
|
-
if m = patt.match(text)
|
40
|
-
i18n_string = I15R::Base.get_i18n_message_string(m[2], prefix)
|
41
|
-
i18ned_row = %(#{m[1]}= I18n.t("#{i18n_string}"))
|
42
|
-
[m[0], i18ned_row]
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
register_matcher :match_haml_tag_content_just_text_on_line
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,81 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require 'i15r/pattern_matcher'
|
3
|
-
|
4
|
-
# FIXME: since matcher blocks are added and executed in the Base class,
|
5
|
-
# tests are not independent: they are coupled through the Base's run method
|
6
|
-
describe I15R::PatternMatchers::Erb::RailsHelperMatcher do
|
7
|
-
it "should replace a title in a link_to helper" do
|
8
|
-
plain = %(<p class="highlighted"><%= link_to 'New user', new_user_path %>?</p>)
|
9
|
-
i18ned = %(<p class="highlighted"><%= link_to I18n.t("users.index.new_user"), new_user_path %>?</p>)
|
10
|
-
I15R::PatternMatchers::Erb::RailsHelperMatcher.run(plain, "users.index").should == i18ned
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should replace a title in a link_to helper with html attributes" do
|
14
|
-
plain = %(<p><%= link_to "Create a new user", new_user_path, { :class => "add" } -%></p>)
|
15
|
-
i18ned = %(<p><%= link_to I18n.t("users.index.create_a_new_user"), new_user_path, { :class => "add" } -%></p>)
|
16
|
-
I15R::PatternMatchers::Erb::RailsHelperMatcher.run(plain, "users.index").should == i18ned
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should replace the label text in a label helper" do
|
20
|
-
plain = %(<%= f.label :name, "Name" %>)
|
21
|
-
i18ned = %(<%= f.label :name, I18n.t("users.new.name") %>)
|
22
|
-
I15R::PatternMatchers::Erb::RailsHelperMatcher.run(plain, "users.new").should == i18ned
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should replace the label text of a label_tag helper" do
|
26
|
-
plain = %(<%= label_tag :name, "Name" %>)
|
27
|
-
i18ned = %(<%= label_tag :name, I18n.t("users.new.name") %>)
|
28
|
-
I15R::PatternMatchers::Erb::RailsHelperMatcher.run(plain, "users.new").should == i18ned
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should replace the title of a submit helper in a form builder" do
|
32
|
-
plain = %(<%= f.submit "Create user" %>)
|
33
|
-
i18ned = %(<%= f.submit I18n.t("users.new.create_user") %>)
|
34
|
-
I15R::PatternMatchers::Erb::RailsHelperMatcher.run(plain, "users.new").should == i18ned
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should replace the title of a submit_tag helper" do
|
38
|
-
plain = %(<%= submit_tag "Create user" %>)
|
39
|
-
i18ned = %(<%= submit_tag I18n.t("users.new.create_user") %>)
|
40
|
-
I15R::PatternMatchers::Erb::RailsHelperMatcher.run(plain, "users.new").should == i18ned
|
41
|
-
end
|
42
|
-
|
43
|
-
describe "when text has non-english characters" do
|
44
|
-
it "should replace a title in a link_to helper" do
|
45
|
-
plain = %(<p class="highlighted"><%= link_to 'Új felhasználó', new_user_path %>?</p>)
|
46
|
-
i18ned = %(<p class="highlighted"><%= link_to I18n.t("users.index.Új_felhasználó"), new_user_path %>?</p>)
|
47
|
-
I15R::PatternMatchers::Erb::RailsHelperMatcher.run(plain, "users.index").should == i18ned
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should replace a title in a link_to helper with html attributes" do
|
51
|
-
plain = %(<p><%= link_to "Új felhasználó létrehozása", new_user_path, { :class => "add" } -%></p>)
|
52
|
-
i18ned = %(<p><%= link_to I18n.t("users.index.Új_felhasználó_létrehozása"), new_user_path, { :class => "add" } -%></p>)
|
53
|
-
I15R::PatternMatchers::Erb::RailsHelperMatcher.run(plain, "users.index").should == i18ned
|
54
|
-
end
|
55
|
-
|
56
|
-
it "should replace the label text in a label helper" do
|
57
|
-
plain = %(<%= f.label :name, "Név" %>)
|
58
|
-
i18ned = %(<%= f.label :name, I18n.t("users.new.név") %>)
|
59
|
-
I15R::PatternMatchers::Erb::RailsHelperMatcher.run(plain, "users.new").should == i18ned
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should replace the label text that has non-english chars of a label_tag helper" do
|
63
|
-
plain = %(<%= label_tag :name, "Név" %>)
|
64
|
-
i18ned = %(<%= label_tag :name, I18n.t("users.new.név") %>)
|
65
|
-
I15R::PatternMatchers::Erb::RailsHelperMatcher.run(plain, "users.new").should == i18ned
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should replace the title of a submit helper in a form builder" do
|
69
|
-
plain = %(<%= f.submit "Új felhasználó" %>)
|
70
|
-
i18ned = %(<%= f.submit I18n.t("users.new.Új_felhasználó") %>)
|
71
|
-
I15R::PatternMatchers::Erb::RailsHelperMatcher.run(plain, "users.new").should == i18ned
|
72
|
-
end
|
73
|
-
|
74
|
-
it "should replace the title of a submit_tag helper" do
|
75
|
-
plain = %(<%= submit_tag "Új felhasználó" %>)
|
76
|
-
i18ned = %(<%= submit_tag I18n.t("users.new.Új_felhasználó") %>)
|
77
|
-
I15R::PatternMatchers::Erb::RailsHelperMatcher.run(plain, "users.new").should == i18ned
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require 'i15r/pattern_matcher'
|
3
|
-
|
4
|
-
# FIXME: since matcher blocks are added and executed in the Base class, that's what should be called
|
5
|
-
# in the tests. That's not elegant and tests are not independent: they are coupled through the Base's run method
|
6
|
-
describe I15R::PatternMatchers::Erb::TagAttributeMatcher do
|
7
|
-
it "should replace a link's title" do
|
8
|
-
plain = %(<a title="site root" href="/"><img src="site_logo.png" /></a>)
|
9
|
-
i18ned = %(<a title="<%= I18n.t("users.new.site_root") %>" href="/"><img src="site_logo.png" /></a>)
|
10
|
-
I15R::PatternMatchers::Erb::TagAttributeMatcher.run(plain, "users.new").should == i18ned
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should replace a link's title that has non-english characters" do
|
14
|
-
plain = %(<a title="raçine du site" href="/"><img src="site_logo.png" /></a>)
|
15
|
-
i18ned = %(<a title="<%= I18n.t("users.new.raçine_du_site") %>" href="/"><img src="site_logo.png" /></a>)
|
16
|
-
I15R::PatternMatchers::Erb::TagAttributeMatcher.run(plain, "users.new").should == i18ned
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require 'i15r/pattern_matcher'
|
3
|
-
|
4
|
-
describe I15R::PatternMatchers::Erb::TagContentMatcher do
|
5
|
-
|
6
|
-
it "should replace a single word" do
|
7
|
-
plain = %(<label for="user-name">Name</label>)
|
8
|
-
i18ned = %(<label for="user-name"><%= I18n.t("users.new.name") %></label>)
|
9
|
-
I15R::PatternMatchers::Erb::TagContentMatcher.run(plain, "users.new").should == i18ned
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should replace several words" do
|
13
|
-
plain = %(<label for="user-name">Earlier names</label>)
|
14
|
-
i18ned = %(<label for="user-name"><%= I18n.t("users.new.earlier_names") %></label>)
|
15
|
-
I15R::PatternMatchers::Erb::TagContentMatcher.run(plain, "users.new").should == i18ned
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should remove punctuation from plain strings" do
|
19
|
-
plain = %(<label for="user-name">Got friends? A friend's name</label>)
|
20
|
-
i18ned = %(<label for="user-name"><%= I18n.t("users.new.got_friends_a_friends_name") %></label>)
|
21
|
-
I15R::PatternMatchers::Erb::TagContentMatcher.run(plain, "users.new").should == i18ned
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should not remove punctuation outside plain strings" do
|
25
|
-
plain = %(<label for="user-name">A friend's name:</label>)
|
26
|
-
i18ned = %(<label for="user-name"><%= I18n.t("users.new.a_friends_name") %>:</label>)
|
27
|
-
I15R::PatternMatchers::Erb::TagContentMatcher.run(plain, "users.new").should == i18ned
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should preserve whitespace in the content part of the tag" do
|
31
|
-
plain = %(<label for="user-name"> Name </label>)
|
32
|
-
i18ned = %(<label for="user-name"> <%= I18n.t("users.new.name") %> </label>)
|
33
|
-
I15R::PatternMatchers::Erb::TagContentMatcher.run(plain, "users.new").should == i18ned
|
34
|
-
end
|
35
|
-
|
36
|
-
#1.8fail
|
37
|
-
it "should replace a word with non-ascii characters" do
|
38
|
-
plain = %(<label for="when">Mañana</label>)
|
39
|
-
i18ned = %(<label for="when"><%= I18n.t("users.new.mañana") %></label>)
|
40
|
-
I15R::PatternMatchers::Erb::TagContentMatcher.run(plain, "users.new").should == i18ned
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
@@ -1,92 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
4
|
-
|
5
|
-
describe I15R::PatternMatchers::Haml::RailsHelperMatcher do
|
6
|
-
it "should replace a title in a link_to helper in a %tag row" do
|
7
|
-
plain = %(%p= link_to 'New user', new_user_path)
|
8
|
-
i18ned = %(%p= link_to I18n.t("users.index.new_user"), new_user_path)
|
9
|
-
I15R::PatternMatchers::Haml::RailsHelperMatcher.run(plain, "users.index").should == i18ned
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should replace a title in a link_to helper in an implicit div row" do
|
13
|
-
plain = %(#new_user_link= link_to 'New user', new_user_path)
|
14
|
-
i18ned = %(#new_user_link= link_to I18n.t("users.index.new_user"), new_user_path)
|
15
|
-
I15R::PatternMatchers::Haml::RailsHelperMatcher.run(plain, "users.index").should == i18ned
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should replace the label text in a label helper" do
|
19
|
-
plain = %(= f.label :password, "Password")
|
20
|
-
i18ned = %(= f.label :password, I18n.t("users.new.password"))
|
21
|
-
I15R::PatternMatchers::Haml::RailsHelperMatcher.run(plain, "users.new").should == i18ned
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should preserve whitespace when replacing a label helper" do
|
25
|
-
plain = %( = f.label :password, "Password")
|
26
|
-
i18ned = %( = f.label :password, I18n.t("users.new.password"))
|
27
|
-
I15R::PatternMatchers::Haml::RailsHelperMatcher.run(plain, "users.new").should == i18ned
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should replace a title in a link_to helper that uses parens and other text in the same row in an implicit div row" do
|
31
|
-
plain = %q(= "I accept the #{link_to('terms and conditions', terms_and_conditions_path)}")
|
32
|
-
i15d = %q(= I18n.t("users.new.i_accept_the", :link => link_to(I18n.t("users.new.terms_and_conditions"), terms_and_conditions_path)))
|
33
|
-
I15R::PatternMatchers::Haml::RailsHelperMatcher.run(plain, "users.new").should == i15d
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should replace a title in a link_to helper that does not use parens and other text in the same row in an implicit div row" do
|
37
|
-
plain = %q(= "I accept the #{link_to 'terms and conditions', terms_and_conditions_path}")
|
38
|
-
i15d = %q(= I18n.t("users.new.i_accept_the", :link => link_to(I18n.t("users.new.terms_and_conditions"), terms_and_conditions_path)))
|
39
|
-
I15R::PatternMatchers::Haml::RailsHelperMatcher.run(plain, "users.new").should == i15d
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should replace a title in a link_to helper that uses the haml == operator" do
|
43
|
-
plain = %q(== I accept the #{link_to('terms and conditions', terms_and_conditions_path)})
|
44
|
-
i15d = %q(== I18n.t("users.new.i_accept_the", :link => link_to(I18n.t("users.new.terms_and_conditions"), terms_and_conditions_path)))
|
45
|
-
I15R::PatternMatchers::Haml::RailsHelperMatcher.run(plain, "users.new").should == i15d
|
46
|
-
end
|
47
|
-
|
48
|
-
describe "when text has non-english characters" do
|
49
|
-
it "should replace a title in a link_to helper in a %tag row" do
|
50
|
-
plain = %(%p= link_to 'Új felhasználó', new_user_path)
|
51
|
-
i18ned = %(%p= link_to I18n.t("users.index.Új_felhasználó"), new_user_path)
|
52
|
-
I15R::PatternMatchers::Haml::RailsHelperMatcher.run(plain, "users.index").should == i18ned
|
53
|
-
end
|
54
|
-
|
55
|
-
it "should replace a title in a link_to helper in an implicit div row" do
|
56
|
-
plain = %(#new_user_link= link_to 'Új felhasználó', new_user_path)
|
57
|
-
i18ned = %(#new_user_link= link_to I18n.t("users.index.Új_felhasználó"), new_user_path)
|
58
|
-
I15R::PatternMatchers::Haml::RailsHelperMatcher.run(plain, "users.index").should == i18ned
|
59
|
-
end
|
60
|
-
|
61
|
-
it "should replace the label text in a label helper" do
|
62
|
-
plain = %(= f.label :password, "Contraseña")
|
63
|
-
i18ned = %(= f.label :password, I18n.t("users.new.contraseña"))
|
64
|
-
I15R::PatternMatchers::Haml::RailsHelperMatcher.run(plain, "users.new").should == i18ned
|
65
|
-
end
|
66
|
-
|
67
|
-
it "should preserve whitespace when replacing a label helper" do
|
68
|
-
plain = %( = f.label :password, "Contraseña")
|
69
|
-
i18ned = %( = f.label :password, I18n.t("users.new.contraseña"))
|
70
|
-
I15R::PatternMatchers::Haml::RailsHelperMatcher.run(plain, "users.new").should == i18ned
|
71
|
-
end
|
72
|
-
|
73
|
-
it "should replace a title in a link_to helper that uses parens and other text in the same row in an implicit div row" do
|
74
|
-
plain = %q(= "Elfőgadom a #{link_to('feltételeket', terms_and_conditions_path)}")
|
75
|
-
i15d = %q(= I18n.t("users.new.elfőgadom_a", :link => link_to(I18n.t("users.new.feltételeket"), terms_and_conditions_path)))
|
76
|
-
I15R::PatternMatchers::Haml::RailsHelperMatcher.run(plain, "users.new").should == i15d
|
77
|
-
end
|
78
|
-
|
79
|
-
it "should replace a title in a link_to helper that does not use parens and other text in the same row in an implicit div row" do
|
80
|
-
plain = %q(= "Elfőgadom a #{link_to 'feltételeket', terms_and_conditions_path}")
|
81
|
-
i15d = %q(= I18n.t("users.new.elfőgadom_a", :link => link_to(I18n.t("users.new.feltételeket"), terms_and_conditions_path)))
|
82
|
-
I15R::PatternMatchers::Haml::RailsHelperMatcher.run(plain, "users.new").should == i15d
|
83
|
-
end
|
84
|
-
|
85
|
-
it "should replace a title in a link_to helper that uses the haml == operator" do
|
86
|
-
plain = %q(== Elfőgadom a #{link_to('feltételeket', terms_and_conditions_path)})
|
87
|
-
i15d = %q(== I18n.t("users.new.elfőgadom_a", :link => link_to(I18n.t("users.new.feltételeket"), terms_and_conditions_path)))
|
88
|
-
I15R::PatternMatchers::Haml::RailsHelperMatcher.run(plain, "users.new").should == i15d
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
end
|
@@ -1,82 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
4
|
-
|
5
|
-
describe I15R::PatternMatchers::Haml::TagContentMatcher do
|
6
|
-
it "should replace a tag's content where the tag is an implicit div" do
|
7
|
-
plain = %(#form_head My account)
|
8
|
-
i18ned = %(#form_head= I18n.t("users.edit.my_account"))
|
9
|
-
I15R::PatternMatchers::Haml::TagContentMatcher.run(plain, "users.edit").should == i18ned
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should replace a tag's content where the tag is an explicit one" do
|
13
|
-
plain = %(%p Please check your inbox and click on the activation link.)
|
14
|
-
i18ned = %(%p= I18n.t("users.show.please_check_your_inbox_and_click_on_the_activation_link"))
|
15
|
-
I15R::PatternMatchers::Haml::TagContentMatcher.run(plain, "users.show").should == i18ned
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should replace a tag's content which is simple text all by itself on a line" do
|
19
|
-
plain = %(please visit)
|
20
|
-
i18ned = %(= I18n.t("users.new.please_visit"))
|
21
|
-
I15R::PatternMatchers::Haml::TagContentMatcher.run(plain, "users.new").should == i18ned
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should replace /-s with an _" do
|
25
|
-
plain = %(%p Do not close/reload while loading)
|
26
|
-
i18ned = %(%p= I18n.t("users.new.do_not_close_reload_while_loading"))
|
27
|
-
I15R::PatternMatchers::Haml::TagContentMatcher.run(plain, "users.new").should == i18ned
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should not replace an implict div with an assigned class" do
|
31
|
-
plain = %( .field)
|
32
|
-
I15R::PatternMatchers::Haml::TagContentMatcher.run(plain, "users.new").should == plain
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should not replace a line with just an hmtl tag and no text" do
|
36
|
-
plain = "%p"
|
37
|
-
I15R::PatternMatchers::Haml::TagContentMatcher.run(plain, "users.new").should == plain
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should not include the %tag in the generated message string" do
|
41
|
-
plain = "%h2 Resend unlock instructions"
|
42
|
-
i18ned = %(%h2= I18n.t("users.new.resend_unlock_instructions"))
|
43
|
-
I15R::PatternMatchers::Haml::TagContentMatcher.run(plain, "users.new").should == i18ned
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should suppress ( and ) in the generated I18n message string" do
|
47
|
-
plain = "%i (we need your current password to confirm your changes)"
|
48
|
-
i18ned = %(%i= I18n.t("users.new.we_need_your_current_password_to_confirm_your_changes"))
|
49
|
-
I15R::PatternMatchers::Haml::TagContentMatcher.run(plain, "users.new").should == i18ned
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should not convert Ruby code to be evaluated" do
|
53
|
-
plain = "= yield"
|
54
|
-
I15R::PatternMatchers::Haml::TagContentMatcher.run(plain, "users.new").should == plain
|
55
|
-
end
|
56
|
-
|
57
|
-
it "should not convert comments" do
|
58
|
-
plain = "/ Do not remove the next line"
|
59
|
-
I15R::PatternMatchers::Haml::TagContentMatcher.run(plain, "users.new").should == plain
|
60
|
-
end
|
61
|
-
|
62
|
-
describe "when text has non-english characters" do
|
63
|
-
it "should replace a tag's content where the tag is an implicit div" do
|
64
|
-
plain = %(#form_head Türkçe)
|
65
|
-
i18ned = %(#form_head= I18n.t("users.edit.türkçe"))
|
66
|
-
I15R::PatternMatchers::Haml::TagContentMatcher.run(plain, "users.edit").should == i18ned
|
67
|
-
end
|
68
|
-
|
69
|
-
it "should replace a tag's content where the tag is an explicit one" do
|
70
|
-
plain = %(%p Egy, kettő, három, négy, öt.)
|
71
|
-
i18ned = %(%p= I18n.t("users.show.egy_kettő_három_négy_öt"))
|
72
|
-
I15R::PatternMatchers::Haml::TagContentMatcher.run(plain, "users.show").should == i18ned
|
73
|
-
end
|
74
|
-
|
75
|
-
#1.8fail
|
76
|
-
it "should replace a tag's content which is simple text all by itself on a line" do
|
77
|
-
plain = %(Türkçe)
|
78
|
-
i18ned = %(= I18n.t("users.new.türkçe"))
|
79
|
-
I15R::PatternMatchers::Haml::TagContentMatcher.run(plain, "users.new").should == i18ned
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|