i15r 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## Summary
4
4
 
5
- I15r (Internationalizer) searches for all the non-i18n texts in erb views in the given files/directory and replaces them with I18n messages. The message string is based on the file in which the text was found and the text itself that was replaced.
5
+ I15r (Internationalizer) searches for all the non-i18n texts in your views in the given files/directory and replaces them with I18n messages. The message string is based on the file in which the text was found and the text itself that was replaced.
6
6
 
7
7
  E.g
8
8
 
@@ -28,6 +28,8 @@ will be replaced by
28
28
  <label for="user-name"><%= I18n.t("member.users.edit.name") %></label>
29
29
  <input type="text" id="user-name" name="user[name]" />
30
30
 
31
+ It can process erb and haml files.
32
+
31
33
  ## Installation
32
34
 
33
35
  gem install i15r --source http://gemcutter.org
@@ -42,7 +44,7 @@ will be replaced by
42
44
 
43
45
  i15r path/leading/to/directory
44
46
 
45
- All files with an erb suffix will be converted.
47
+ All files with an erb or haml suffix in that directory or somewhere in the hierarchy below will be converted.
46
48
 
47
49
  ### Dry run
48
50
 
@@ -50,6 +52,32 @@ By default, i15r overwrites all the source files with the i18n message strings i
50
52
 
51
53
  i15r app/views/users -p
52
54
 
55
+ or
56
+
57
+ i15r app/views/users --pretend
58
+
59
+ ### Custom prefix
60
+
61
+ If you don't want the filename to appear in the i18n message string, you can pass a prefix parameter that will be used to generate the message strings. For example if you have the following in a file called app/views/users/new.html.erb:
62
+
63
+ <label for="user-name">Name</label>
64
+ <input type="text" id="user-name" name="user[name]" />
65
+
66
+ And then call:
67
+
68
+ i15r app/views/users/new.html.erb --prefix my_project
69
+
70
+ The file will then contain:
71
+
72
+ <label for="user-name"><%= I18n.t("my_project.name") %></label>
73
+ <input type="text" id="user-name" name="user[name]" />
74
+
75
+ ## Disclaimer (sort of)
76
+
77
+ Please note that this is an early version mainly built up of examples I've come through doing client work. I am pretty sure there are a number of cases which i15r -at the moment- does not handle well (or at all). If you find such an example, please [let me know][issue_tracker] or if you feel motivated, submit a patch. Oh, yes, to prevent unwanted changes to your view files, you should use a SCM (that goes without saying, of course) and probably use the --pretend option.
78
+
79
+ [issue_tracker]: http://github.com/balinterdi/i15r/issues
80
+
53
81
  ## Licensing, contribution
54
82
 
55
83
  The source code of this gem can be found at [http://github.com/balinterdi/i15r/](http://github.com/balinterdi/i15r/). It is released under the MIT-LICENSE, so you can basically do anything with it. However, if you think your modifications only make the tool better, please send a pull request or patch and I will consider merging in your changes. Any suggestions or feedback are welcome to <balint@bucionrails.com>.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{i15r}
8
- s.version = "0.3.0"
8
+ s.version = "0.3.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Balint Erdi"]
12
- s.date = %q{2009-12-08}
12
+ s.date = %q{2009-12-14}
13
13
  s.default_executable = %q{i15r}
14
14
  s.description = %q{ The internationalizer. Replaces plain text strings in your views and replaces them with I18n message strings so you only have to provide the translations.
15
15
  }
@@ -33,15 +33,24 @@ Gem::Specification.new do |s|
33
33
  "lib/i15r/base.rb",
34
34
  "lib/i15r/pattern_matcher.rb",
35
35
  "lib/i15r/pattern_matchers/base.rb",
36
- "lib/i15r/pattern_matchers/rails_helper_matcher.rb",
37
- "lib/i15r/pattern_matchers/tag_attribute_matcher.rb",
38
- "lib/i15r/pattern_matchers/tag_content_matcher.rb",
36
+ "lib/i15r/pattern_matchers/erb.rb",
37
+ "lib/i15r/pattern_matchers/erb/rails_helper_matcher.rb",
38
+ "lib/i15r/pattern_matchers/erb/tag_attribute_matcher.rb",
39
+ "lib/i15r/pattern_matchers/erb/tag_content_matcher.rb",
40
+ "lib/i15r/pattern_matchers/haml.rb",
41
+ "lib/i15r/pattern_matchers/haml/rails_helper_matcher.rb",
42
+ "lib/i15r/pattern_matchers/haml/tag_content_matcher.rb",
43
+ "spec/erb/rails_helper_matcher_spec.rb",
44
+ "spec/erb/tag_attribute_matcher_spec.rb",
45
+ "spec/erb/tag_content_matcher_spec.rb",
46
+ "spec/haml/rails_helper_matcher_spec.rb",
47
+ "spec/haml/tag_content_matcher_spec.rb",
39
48
  "spec/i15r_spec.rb",
40
49
  "spec/pattern_matcher_spec.rb",
41
- "spec/rails_helper_matcher_spec.rb",
42
50
  "spec/spec.opts",
43
- "spec/tag_attribute_matcher_spec.rb",
44
- "spec/tag_content_matcher_spec.rb",
51
+ "spec/spec_helper.rb",
52
+ "spec/support/new_flight.html.erb",
53
+ "spec/support/new_user.html.haml",
45
54
  "tasks/i15r.rake",
46
55
  "todos.markdown"
47
56
  ]
@@ -51,11 +60,14 @@ Gem::Specification.new do |s|
51
60
  s.rubygems_version = %q{1.3.5}
52
61
  s.summary = %q{The internationalizer. Makes your Ruby app international}
53
62
  s.test_files = [
54
- "spec/i15r_spec.rb",
63
+ "spec/erb/rails_helper_matcher_spec.rb",
64
+ "spec/erb/tag_attribute_matcher_spec.rb",
65
+ "spec/erb/tag_content_matcher_spec.rb",
66
+ "spec/haml/rails_helper_matcher_spec.rb",
67
+ "spec/haml/tag_content_matcher_spec.rb",
68
+ "spec/i15r_spec.rb",
55
69
  "spec/pattern_matcher_spec.rb",
56
- "spec/rails_helper_matcher_spec.rb",
57
- "spec/tag_attribute_matcher_spec.rb",
58
- "spec/tag_content_matcher_spec.rb"
70
+ "spec/spec_helper.rb"
59
71
  ]
60
72
 
61
73
  if s.respond_to? :specification_version then
@@ -81,22 +81,24 @@ module I15R
81
81
  File.read(File.expand_path(file))
82
82
  end
83
83
 
84
- def write_content_to(file, content)
85
- open(File.expand_path(file), "w") { |f| f.write(content) }
84
+ def write_content_to(path, content)
85
+ open(File.expand_path(path), "w") { |f| f.write(content) }
86
86
  end
87
87
 
88
88
  def show_diff(plain_row, i9l_row)
89
89
  silenced_if_testing do
90
90
  $stdout.puts "- #{plain_row}"
91
91
  $stdout.puts "+ #{i9l_row}"
92
+ $stdout.puts
92
93
  end
93
94
  end
94
95
 
95
- def internationalize_file(file)
96
- text = get_content_from(file)
97
- prefix = self.prefix || file_path_to_message_prefix(file)
98
- i18ned_text = sub_plain_strings(text, prefix)
99
- write_content_to(file, i18ned_text) unless dry_run?
96
+ def internationalize_file(path)
97
+ text = get_content_from(path)
98
+ prefix = self.prefix || file_path_to_message_prefix(path)
99
+ template_type = path[/(?:.*)\.(.*)$/, 1]
100
+ i18ned_text = sub_plain_strings(text, prefix, template_type.to_sym)
101
+ write_content_to(path, i18ned_text) unless dry_run?
100
102
  end
101
103
 
102
104
  def display_indented_header(prefix)
@@ -112,15 +114,15 @@ module I15R
112
114
  end
113
115
  end
114
116
 
115
- def sub_plain_strings(text, prefix)
116
- #TODO: find out how to display diff rows
117
- I15R::PatternMatchers::Base.run(text, prefix) do |plain_row, i9l_row|
117
+ def sub_plain_strings(text, prefix, file_type)
118
+ i15d = I15R::PatternMatchers::Base.run(text, prefix, file_type) do |plain_row, i9l_row|
118
119
  show_diff(plain_row, i9l_row)
119
120
  end
121
+ i15d + "\n"
120
122
  end
121
123
 
122
124
  def internationalize!(path)
123
- files = path =~ /.erb$/ ? [path] : Dir.glob("#{path}/**/*.erb")
125
+ files = File.directory?(path) ? Dir.glob("#{path}/**/*.{erb,haml}") : [path]
124
126
  files.each { |file| internationalize_file(file) }
125
127
  end
126
128
 
@@ -1,4 +1,3 @@
1
1
  require 'i15r/pattern_matchers/base'
2
- require 'i15r/pattern_matchers/tag_attribute_matcher'
3
- require 'i15r/pattern_matchers/rails_helper_matcher'
4
- require 'i15r/pattern_matchers/tag_content_matcher'
2
+ require 'i15r/pattern_matchers/erb'
3
+ require 'i15r/pattern_matchers/haml'
@@ -7,22 +7,27 @@ module I15R
7
7
  # end
8
8
  # end
9
9
 
10
- def self.matches(&block)
11
- @@matchers ||= []
12
- @@matchers.push(block)
10
+ def self.matches(file_type, &block)
11
+ @@matchers ||= {}
12
+ @@matchers[file_type] ||= []
13
+ @@matchers[file_type].push(block)
13
14
  end
14
15
 
15
- def self.run(text, prefix)
16
- i18ned_text = text
17
- @@matchers.each do |matcher|
18
- m = matcher.call(text, prefix)
19
- unless m.nil?
20
- plain_row, i18ned_row = m
21
- yield plain_row, i18ned_row if block_given?
22
- i18ned_text.gsub!(plain_row, i18ned_row)
16
+ def self.run(text, prefix, file_type)
17
+ lines = text.split("\n")
18
+ i18ned_lines = lines.map do |line|
19
+ @@matchers[file_type].inject(line) do |i18ned_line, matcher|
20
+ m = matcher.call(i18ned_line, prefix)
21
+ unless m.nil?
22
+ row_before_match, row_after_match = m
23
+ yield row_before_match, row_after_match if block_given?
24
+ row_after_match
25
+ else
26
+ i18ned_line
27
+ end
23
28
  end
24
29
  end
25
- i18ned_text
30
+ i18ned_lines.join("\n")
26
31
  end
27
32
 
28
33
  #TODO: use method_added to add to matchers so that
@@ -0,0 +1,10 @@
1
+ module I15R
2
+ module PatternMatchers
3
+ module Erb
4
+ end
5
+ end
6
+ end
7
+
8
+ require "i15r/pattern_matchers/erb/rails_helper_matcher"
9
+ require "i15r/pattern_matchers/erb/tag_content_matcher"
10
+ require "i15r/pattern_matchers/erb/tag_attribute_matcher"
@@ -0,0 +1,75 @@
1
+ require 'i15r/base'
2
+
3
+ module I15R
4
+ module PatternMatchers
5
+ module Erb
6
+ class RailsHelperMatcher < Base
7
+
8
+ def self.run(text, prefix)
9
+ super(text, prefix, :erb)
10
+ end
11
+
12
+ def self.match_link_to_title
13
+ patt = /^(.*)<%=\s*link_to\s+['"](.*?)['"]\s*,(.*)%>(.*)$/
14
+ matches(:erb) 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]}<%= link_to I18n.t("#{i18n_string}"),#{m[3]}%>#{m[4]})
18
+ [m[0], i18ned_row]
19
+ end
20
+ end
21
+ end
22
+ register_matcher :match_link_to_title
23
+
24
+ def self.match_label_helper_text
25
+ patt = /^(.*)<%=(.*)\.label(.*),\s*['"](.*?)['"]\s*%>(.*)$/
26
+ matches(:erb) do |text, prefix|
27
+ if m = patt.match(text)
28
+ i18n_string = I15R::Base.get_i18n_message_string(m[4], prefix)
29
+ i18ned_row = %(#{m[1]}<%=#{m[2]}.label#{m[3]}, I18n.t("#{i18n_string}") %>#{m[5]})
30
+ [m[0], i18ned_row]
31
+ end
32
+ end
33
+ end
34
+ register_matcher :match_label_helper_text
35
+
36
+ def self.match_label_tag_helper_text
37
+ patt = /^(.*)<%=(.*)label_tag (.*),\s*['"](.*?)['"]\s*%>(.*)$/
38
+ matches(:erb) do |text, prefix|
39
+ if m = patt.match(text)
40
+ i18n_string = I15R::Base.get_i18n_message_string(m[4], prefix)
41
+ i18ned_row = %(#{m[1]}<%=#{m[2]}label_tag #{m[3]}, I18n.t("#{i18n_string}") %>#{m[5]})
42
+ [m[0], i18ned_row]
43
+ end
44
+ end
45
+ end
46
+ register_matcher :match_label_tag_helper_text
47
+
48
+ def self.match_submit_helper_text
49
+ patt = /^(.*)<%=(.*)\.submit\s*['"](.*?)['"]\s*%>(.*)$/
50
+ matches(:erb) do |text, prefix|
51
+ if m = patt.match(text)
52
+ i18n_string = I15R::Base.get_i18n_message_string(m[3], prefix)
53
+ i18ned_row = %(#{m[1]}<%=#{m[2]}.submit I18n.t("#{i18n_string}") %>#{m[4]})
54
+ [m[0], i18ned_row]
55
+ end
56
+ end
57
+ end
58
+ register_matcher :match_submit_helper_text
59
+
60
+ def self.match_submit_tag_helper_text
61
+ patt = /^(.*)<%=\s*submit_tag\s*['"](.*?)['"]\s*%>(.*)$/
62
+ matches(:erb) do |text, prefix|
63
+ if m = patt.match(text)
64
+ i18n_string = I15R::Base.get_i18n_message_string(m[2], prefix)
65
+ i18ned_row = %(#{m[1]}<%= submit_tag I18n.t("#{i18n_string}") %>#{m[3]})
66
+ [m[0], i18ned_row]
67
+ end
68
+ end
69
+ end
70
+ register_matcher :match_submit_tag_helper_text
71
+
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,26 @@
1
+ require 'i15r/base'
2
+
3
+ module I15R
4
+ module PatternMatchers
5
+ module Erb
6
+ class TagAttributeMatcher < Base
7
+
8
+ def self.run(text, prefix)
9
+ super(text, prefix, :erb)
10
+ end
11
+
12
+ def self.match_title_attribute
13
+ patt = /^(.*)(<a\s+.*title=)['"](.*?)['"](.*)/
14
+ matches(:erb) do |text, prefix|
15
+ if m = patt.match(text)
16
+ i18n_string = I15R::Base.get_i18n_message_string(m[3], prefix)
17
+ i18ned_row = %(#{m[1]}#{m[2]}"<%= I18n.t("#{i18n_string}") %>"#{m[4]})
18
+ [m[0], i18ned_row]
19
+ end
20
+ end
21
+ end
22
+ register_matcher :match_title_attribute
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,40 @@
1
+ require 'i15r/base'
2
+
3
+ module I15R
4
+ module PatternMatchers
5
+ module Erb
6
+ class TagContentMatcher < Base
7
+
8
+ def self.run(text, prefix)
9
+ super(text, prefix, :erb)
10
+ end
11
+
12
+ def self.match_tag_content_on_one_line
13
+ patt = /^(.*)>(\s*)(\w[\s\w:'"!?\.,]+)\s*<\/(.*)$/
14
+ matches(:erb) do |text, prefix|
15
+ if m = patt.match(text)
16
+ i18n_string = I15R::Base.get_i18n_message_string(m[3], prefix)
17
+ ending_punctuation = m[3][/([?.!:\s]*)$/, 1]
18
+ i15d_row = %(#{m[1]}>#{m[2]}<%= I18n.t("#{i18n_string}") %>#{ending_punctuation.to_s}</#{m[4]})
19
+ [m[0], i15d_row]
20
+ end
21
+ end
22
+ end
23
+ register_matcher :match_tag_content_on_one_line
24
+
25
+ def self.match_tag_content_multiline
26
+ patt = /^(\s*)(\w[\w\s,]*)(.*)$/
27
+ matches(:erb) do |text, prefix|
28
+ if m = patt.match(text)
29
+ i18n_string = I15R::Base.get_i18n_message_string(m[2], prefix)
30
+ i15d_row = %(#{m[1]}<%= I18n.t("#{i18n_string}") %>#{m[3]})
31
+ [m[0], i15d_row]
32
+ end
33
+ end
34
+ end
35
+ register_matcher :match_tag_content_multiline
36
+
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,9 @@
1
+ module I15R
2
+ module PatternMatchers
3
+ module Haml
4
+ end
5
+ end
6
+ end
7
+
8
+ require "i15r/pattern_matchers/haml/rails_helper_matcher"
9
+ require "i15r/pattern_matchers/haml/tag_content_matcher"
@@ -0,0 +1,83 @@
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
@@ -0,0 +1,52 @@
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][\w\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,45 +1,43 @@
1
- $:.unshift File.join(File.expand_path(File.dirname(__FILE__)), "..", "lib")
2
-
3
1
  require 'i15r/pattern_matcher'
4
2
  require "spec"
5
3
 
6
4
  # FIXME: since matcher blocks are added and executed in the Base class,
7
5
  # tests are not independent: they are coupled through the Base's run method
8
- describe I15R::PatternMatchers::RailsHelperMatcher do
6
+ describe I15R::PatternMatchers::Erb::RailsHelperMatcher do
9
7
  it "should replace a title in a link_to helper" do
10
- plain = %(want a <p class="highlighted"><%= link_to 'New user', new_user_path %>?</p>)
11
- i18ned = %(want a <p class="highlighted"><%= link_to I18n.t("users.index.new_user"), new_user_path %>?</p>)
12
- I15R::PatternMatchers::RailsHelperMatcher.run(plain, "users.index").should == i18ned
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
13
11
  end
14
12
 
15
13
  it "should replace a title in a link_to helper with html attributes" do
16
14
  plain = %(<p><%= link_to "Create a new user", new_user_path, { :class => "add" } -%></p>)
17
15
  i18ned = %(<p><%= link_to I18n.t("users.index.create_a_new_user"), new_user_path, { :class => "add" } -%></p>)
18
- I15R::PatternMatchers::RailsHelperMatcher.run(plain, "users.index").should == i18ned
16
+ I15R::PatternMatchers::Erb::RailsHelperMatcher.run(plain, "users.index").should == i18ned
19
17
  end
20
18
 
21
19
  it "should replace the label text in a label helper" do
22
20
  plain = %(<%= f.label :name, "Name" %>)
23
21
  i18ned = %(<%= f.label :name, I18n.t("users.new.name") %>)
24
- I15R::PatternMatchers::RailsHelperMatcher.run(plain, "users.new").should == i18ned
22
+ I15R::PatternMatchers::Erb::RailsHelperMatcher.run(plain, "users.new").should == i18ned
25
23
  end
26
24
 
27
25
  it "should replace the label text of a label_tag helper" do
28
26
  plain = %(<%= label_tag :name, "Name" %>)
29
27
  i18ned = %(<%= label_tag :name, I18n.t("users.new.name") %>)
30
- I15R::PatternMatchers::RailsHelperMatcher.run(plain, "users.new").should == i18ned
28
+ I15R::PatternMatchers::Erb::RailsHelperMatcher.run(plain, "users.new").should == i18ned
31
29
  end
32
30
 
33
31
  it "should replace the title of a submit helper in a form builder" do
34
32
  plain = %(<%= f.submit "Create user" %>)
35
33
  i18ned = %(<%= f.submit I18n.t("users.new.create_user") %>)
36
- I15R::PatternMatchers::RailsHelperMatcher.run(plain, "users.new").should == i18ned
34
+ I15R::PatternMatchers::Erb::RailsHelperMatcher.run(plain, "users.new").should == i18ned
37
35
  end
38
36
 
39
37
  it "should replace the title of a submit_tag helper" do
40
38
  plain = %(<%= submit_tag "Create user" %>)
41
39
  i18ned = %(<%= submit_tag I18n.t("users.new.create_user") %>)
42
- I15R::PatternMatchers::RailsHelperMatcher.run(plain, "users.new").should == i18ned
40
+ I15R::PatternMatchers::Erb::RailsHelperMatcher.run(plain, "users.new").should == i18ned
43
41
  end
44
42
 
45
43
  end
@@ -0,0 +1,13 @@
1
+ require 'i15r/pattern_matcher'
2
+ require "spec"
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
+ end
@@ -1,38 +1,36 @@
1
- $:.unshift File.join(File.expand_path(File.dirname(__FILE__)), "..", "lib")
2
-
3
1
  require 'i15r/pattern_matcher'
4
2
  require "spec"
5
3
 
6
- describe I15R::PatternMatchers::TagContentMatcher do
4
+ describe I15R::PatternMatchers::Erb::TagContentMatcher do
7
5
 
8
6
  it "should replace a single word" do
9
7
  plain = %(<label for="user-name">Name</label>)
10
8
  i18ned = %(<label for="user-name"><%= I18n.t("users.new.name") %></label>)
11
- I15R::PatternMatchers::TagContentMatcher.run(plain, "users.new").should == i18ned
9
+ I15R::PatternMatchers::Erb::TagContentMatcher.run(plain, "users.new").should == i18ned
12
10
  end
13
11
 
14
12
  it "should replace several words" do
15
13
  plain = %(<label for="user-name">Earlier names</label>)
16
14
  i18ned = %(<label for="user-name"><%= I18n.t("users.new.earlier_names") %></label>)
17
- I15R::PatternMatchers::TagContentMatcher.run(plain, "users.new").should == i18ned
15
+ I15R::PatternMatchers::Erb::TagContentMatcher.run(plain, "users.new").should == i18ned
18
16
  end
19
17
 
20
18
  it "should remove punctuation from plain strings" do
21
19
  plain = %(<label for="user-name">Got friends? A friend's name</label>)
22
20
  i18ned = %(<label for="user-name"><%= I18n.t("users.new.got_friends_a_friends_name") %></label>)
23
- I15R::PatternMatchers::TagContentMatcher.run(plain, "users.new").should == i18ned
21
+ I15R::PatternMatchers::Erb::TagContentMatcher.run(plain, "users.new").should == i18ned
24
22
  end
25
23
 
26
24
  it "should not remove punctuation outside plain strings" do
27
25
  plain = %(<label for="user-name">A friend's name:</label>)
28
26
  i18ned = %(<label for="user-name"><%= I18n.t("users.new.a_friends_name") %>:</label>)
29
- I15R::PatternMatchers::TagContentMatcher.run(plain, "users.new").should == i18ned
27
+ I15R::PatternMatchers::Erb::TagContentMatcher.run(plain, "users.new").should == i18ned
30
28
  end
31
29
 
32
30
  it "should preserve whitespace in the content part of the tag" do
33
31
  plain = %(<label for="user-name"> Name </label>)
34
32
  i18ned = %(<label for="user-name"> <%= I18n.t("users.new.name") %> </label>)
35
- I15R::PatternMatchers::TagContentMatcher.run(plain, "users.new").should == i18ned
33
+ I15R::PatternMatchers::Erb::TagContentMatcher.run(plain, "users.new").should == i18ned
36
34
  end
37
35
 
38
36
  end
@@ -0,0 +1,46 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ describe I15R::PatternMatchers::Haml::RailsHelperMatcher do
4
+ it "should replace a title in a link_to helper in a %tag row" do
5
+ plain = %(%p= link_to 'New user', new_user_path)
6
+ i18ned = %(%p= link_to I18n.t("users.index.new_user"), new_user_path)
7
+ I15R::PatternMatchers::Haml::RailsHelperMatcher.run(plain, "users.index").should == i18ned
8
+ end
9
+
10
+ it "should replace a title in a link_to helper in an implicit div row" do
11
+ plain = %(#new_user_link= link_to 'New user', new_user_path)
12
+ i18ned = %(#new_user_link= link_to I18n.t("users.index.new_user"), new_user_path)
13
+ I15R::PatternMatchers::Haml::RailsHelperMatcher.run(plain, "users.index").should == i18ned
14
+ end
15
+
16
+ it "should replace the label text in a label helper" do
17
+ plain = %(= f.label :password, "Password")
18
+ i18ned = %(= f.label :password, I18n.t("users.new.password"))
19
+ I15R::PatternMatchers::Haml::RailsHelperMatcher.run(plain, "users.new").should == i18ned
20
+ end
21
+
22
+ it "should preserve whitespace when replacing a label helper" do
23
+ plain = %( = f.label :password, "Password")
24
+ i18ned = %( = f.label :password, I18n.t("users.new.password"))
25
+ I15R::PatternMatchers::Haml::RailsHelperMatcher.run(plain, "users.new").should == i18ned
26
+ end
27
+
28
+ 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
29
+ plain = %q(= "I accept the #{link_to('terms and conditions', terms_and_conditions_path)}")
30
+ i15d = %q(= I18n.t("users.new.i_accept_the", :link => link_to(I18n.t("users.new.terms_and_conditions"), terms_and_conditions_path)))
31
+ I15R::PatternMatchers::Haml::RailsHelperMatcher.run(plain, "users.new").should == i15d
32
+ end
33
+
34
+ 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
35
+ plain = %q(= "I accept the #{link_to 'terms and conditions', terms_and_conditions_path}")
36
+ i15d = %q(= I18n.t("users.new.i_accept_the", :link => link_to(I18n.t("users.new.terms_and_conditions"), terms_and_conditions_path)))
37
+ I15R::PatternMatchers::Haml::RailsHelperMatcher.run(plain, "users.new").should == i15d
38
+ end
39
+
40
+ it "should replace a title in a link_to helper that uses the haml == operator" do
41
+ plain = %q(== I accept the #{link_to('terms and conditions', terms_and_conditions_path)})
42
+ i15d = %q(== I18n.t("users.new.i_accept_the", :link => link_to(I18n.t("users.new.terms_and_conditions"), terms_and_conditions_path)))
43
+ I15R::PatternMatchers::Haml::RailsHelperMatcher.run(plain, "users.new").should == i15d
44
+ end
45
+
46
+ end
@@ -0,0 +1,26 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ describe I15R::PatternMatchers::Haml::TagContentMatcher do
4
+ it "should replace a tag's content where the tag is an implicit div" do
5
+ plain = %(#form_head My account)
6
+ i18ned = %(#form_head= I18n.t("users.edit.my_account"))
7
+ I15R::PatternMatchers::Haml::TagContentMatcher.run(plain, "users.edit").should == i18ned
8
+ end
9
+
10
+ it "should replace a tag's content where the tag is an explicit one" do
11
+ plain = %(%p Please check your inbox and click on the activation link.)
12
+ i18ned = %(%p I18n.t("users.show.please_check_your_inbox_and_click_on_the_activation_link"))
13
+ I15R::PatternMatchers::Haml::TagContentMatcher.run(plain, "users.show").should == i18ned
14
+ end
15
+
16
+ it "should replace a tag's content which is simple text all by itself on a line" do
17
+ plain = %(please visit)
18
+ i18ned = %(= I18n.t("users.new.please_visit"))
19
+ I15R::PatternMatchers::Haml::TagContentMatcher.run(plain, "users.new").should == i18ned
20
+ end
21
+
22
+ it "should not replace an implict div with an assigned class" do
23
+ plain = %( .field)
24
+ I15R::PatternMatchers::Haml::TagContentMatcher.run(plain, "users.new").should == plain
25
+ end
26
+ end
@@ -52,7 +52,6 @@ describe I15R::Base do
52
52
  end
53
53
 
54
54
  describe "turning plain messages into i18n message strings" do
55
-
56
55
  it "should downcase a single word" do
57
56
  I15R::Base.get_i18n_message_string("Name", "users.new").should == "users.new.name"
58
57
  end
@@ -60,9 +59,8 @@ describe I15R::Base do
60
59
  it "should replace spaces with underscores" do
61
60
  I15R::Base.get_i18n_message_string("New name", "users.index").should == "users.index.new_name"
62
61
  end
63
-
64
62
  end
65
-
63
+
66
64
  describe "when substituting the plain contents with i18n message strings" do
67
65
  before do
68
66
  @i15r.options.prefix = nil
@@ -106,7 +104,7 @@ describe I15R::Base do
106
104
  <label for="user-name"><%= I18n.t("#{message_prefix}.name") %></label>
107
105
  <input type="text" id="user-name" name="user[name]" />
108
106
  EOS
109
- @i15r.sub_plain_strings(plain_snippet, message_prefix).should == i18ned_snippet
107
+ @i15r.sub_plain_strings(plain_snippet, message_prefix, :erb).should == i18ned_snippet
110
108
  end
111
109
  end # "when no prefix option was given"
112
110
 
@@ -122,9 +120,22 @@ describe I15R::Base do
122
120
  <input type="text" id="user-name" name="user[name]" />
123
121
  EOS
124
122
 
125
- @i15r.sub_plain_strings(plain_snippet, prefix_option).should == i18ned_snippet
123
+ @i15r.sub_plain_strings(plain_snippet, prefix_option, :erb).should == i18ned_snippet
126
124
  end
127
-
128
125
  end # "when an explicit prefix option was given"
129
126
 
127
+ describe "when running the internationalization for an ERB file" do
128
+ before do
129
+ #TODO: this is not necessary once fakefs correctly fakes open, I think
130
+ @i15r.stub!(:write_content_to).and_return(true)
131
+ @file_path = "app/views/users/new.html.erb"
132
+ File.open(@file_path, "w") { |f| f.write("<label for=\"user-name\">Name</label>") }
133
+ end
134
+
135
+ it "should only run ERB matchers" do
136
+ @i15r.should_receive(:sub_plain_strings).with(anything, anything, :erb)
137
+ @i15r.internationalize_file(@file_path)
138
+ end
139
+ end
140
+
130
141
  end
@@ -4,5 +4,14 @@ require 'i15r/pattern_matcher'
4
4
  require "spec"
5
5
 
6
6
  describe I15R::PatternMatchers::Base do
7
-
7
+ it "should not replace a simple haml div tag with an id" do
8
+ plain = %(#main)
9
+ I15R::PatternMatchers::Base.run(plain, "users.new", :haml).should == plain
10
+ end
11
+ it "should properly replace a line with two matches" do
12
+ plain = %(This is it: <a title="site root" href="/"><img src="site_logo.png" /></a>)
13
+ i18ned = %(<%= I18n.t("users.new.this_is_it") %>: <a title="<%= I18n.t("users.new.site_root") %>" href="/"><img src="site_logo.png" /></a>)
14
+ I15R::PatternMatchers::Base.run(plain, "users.new", :erb).should == i18ned
15
+ end
16
+
8
17
  end
@@ -1,4 +1,5 @@
1
1
  --colour
2
2
  --format profile
3
3
  --timeout 20
4
- --diff
4
+ --diff
5
+ --debugger
@@ -0,0 +1,4 @@
1
+ $:.unshift File.join(File.expand_path(File.dirname(__FILE__)), "..", "lib")
2
+
3
+ require 'i15r'
4
+ require 'i15r/pattern_matchers/haml'
@@ -0,0 +1,31 @@
1
+ <h1>New flight</h1>
2
+
3
+ <% form_for(@flight) do |f| %>
4
+ <%= f.error_messages %>
5
+
6
+ <p>
7
+ <%= f.label :name %><br />
8
+ <%= f.text_field :name %>
9
+ </p>
10
+ <p>
11
+ <%= f.label :capacity %><br />
12
+ <%= f.text_field :capacity %>
13
+ </p>
14
+ <p>
15
+ <%= f.label :duration %><br />
16
+ <%= f.text_field :duration %>
17
+ </p>
18
+ <p>
19
+ <%= f.label :from_id, "From" %><br />
20
+ <%= f.select :from_id, @airport_options %>
21
+ </p>
22
+ <p>
23
+ <%= f.label :to_id, "To" %><br />
24
+ <%= f.select :to_id, @airport_options %>
25
+ </p>
26
+ <p>
27
+ <%= f.submit 'Create' %>
28
+ </p>
29
+ <% end %>
30
+
31
+ <%= link_to 'Back', flights_path %>
@@ -0,0 +1,37 @@
1
+ - @page_title = "Register"
2
+ #main
3
+ = render :partial => "layouts/short_terms_and_conditions"
4
+ #form
5
+ = render :partial => "layouts/flash", :locals => { :flash => flash }
6
+ = my_error_messages_for :user
7
+ #form_head Register
8
+ #form_body
9
+ - form_for @user do |f|
10
+ = f.hidden_field :invitation_id
11
+ .field
12
+ = f.label :email, "Email"
13
+ = f.text_field :email
14
+ .field
15
+ = f.label :password, "Password"
16
+ = f.password_field :password
17
+ .field
18
+ = f.label :password_confirmation, "Re-enter your password"
19
+ = f.password_field :password_confirmation
20
+ %div{ :class => "field option", :style => "float:left" }
21
+ %label{ :for => "user_wants_newsletter" }
22
+ = f.check_box :wants_newsletter, :class => "checkbox"
23
+ Subscribe to the Quaestorial newsletter
24
+ %div{ :class => "field option", :style => "float:left" }
25
+ %label{ :for => "user_accept_t_and_c" }
26
+ = f.check_box :accept_t_and_c, :class => "checkbox"
27
+ == I accept the #{link_to('terms and conditions', terms_and_conditions_path)}
28
+ %button{ :type => "submit" }
29
+ Register
30
+ .clear
31
+ #form_bottom
32
+ = "Already a user? Log in #{link_to('here', login_path)}"
33
+ #info
34
+ If you are looking for our valuations services
35
+ %br/
36
+ please visit
37
+ = link_to "www.quaestorial-valuations.com", "http://www.quaestorial-valuations.com", :target => "_blank"
@@ -26,9 +26,17 @@ This is easy to fix, the whitespace has to be readded just like the punctuation
26
26
  * DONE suppress printing of yaml strings (change by Alberto) when running the specs
27
27
  * DONE make it possible to run i15r on several files
28
28
 
29
+ ### 0.3.0
30
+
31
+ * DONE dry-run option: only show the diffs but do not actually overwrite the files
32
+
29
33
  ### 0.?
30
34
 
31
- * dry-run option: only show the diffs but do not actually overwrite the files
35
+ * haml matchers
36
+ * DONE nothing is replaced in haml files although specs pass. Probably something related to receiving the whole file content as one blob of text and not as lines. It works with erb, though.
37
+ * sort out the ugly hierarchy, make it consistent (e.g add "erb" directory as there is a haml one), do not require files in lib by full path (e.g instead of require 'i15r/pattern\_matchers\_/haml/rails\_helper_matcher' => require 'haml/rails\_helper_matcher'), etc.
38
+ * make a PatternMatcher::Erb (and Haml) class that implements the run method and make the classes that now exist modules that these classes include/extend
39
+ * make the haml matchers nicer (was thrown together very hastily for a client project)
32
40
  * make prefix not replace the inferred message string prefix, but really act as a prefix. (e.g if anetcom is given as a prefix, and the inferred message string is 'users.new' it should not be 'anetcom.name', but 'anetcom.users.new.name')
33
41
  * handle non-ascii characters properly (UTF-8 support) when replacing them. Mañana should become I18n.t("prefix.manana"), for instance. That is, regular expressions should be utf-8 aware.
34
42
  * write the necessary i18n strings back into the yaml file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i15r
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Balint Erdi
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-08 00:00:00 +01:00
12
+ date: 2009-12-14 00:00:00 +01:00
13
13
  default_executable: i15r
14
14
  dependencies: []
15
15
 
@@ -36,15 +36,24 @@ files:
36
36
  - lib/i15r/base.rb
37
37
  - lib/i15r/pattern_matcher.rb
38
38
  - lib/i15r/pattern_matchers/base.rb
39
- - lib/i15r/pattern_matchers/rails_helper_matcher.rb
40
- - lib/i15r/pattern_matchers/tag_attribute_matcher.rb
41
- - lib/i15r/pattern_matchers/tag_content_matcher.rb
39
+ - lib/i15r/pattern_matchers/erb.rb
40
+ - lib/i15r/pattern_matchers/erb/rails_helper_matcher.rb
41
+ - lib/i15r/pattern_matchers/erb/tag_attribute_matcher.rb
42
+ - lib/i15r/pattern_matchers/erb/tag_content_matcher.rb
43
+ - lib/i15r/pattern_matchers/haml.rb
44
+ - lib/i15r/pattern_matchers/haml/rails_helper_matcher.rb
45
+ - lib/i15r/pattern_matchers/haml/tag_content_matcher.rb
46
+ - spec/erb/rails_helper_matcher_spec.rb
47
+ - spec/erb/tag_attribute_matcher_spec.rb
48
+ - spec/erb/tag_content_matcher_spec.rb
49
+ - spec/haml/rails_helper_matcher_spec.rb
50
+ - spec/haml/tag_content_matcher_spec.rb
42
51
  - spec/i15r_spec.rb
43
52
  - spec/pattern_matcher_spec.rb
44
- - spec/rails_helper_matcher_spec.rb
45
53
  - spec/spec.opts
46
- - spec/tag_attribute_matcher_spec.rb
47
- - spec/tag_content_matcher_spec.rb
54
+ - spec/spec_helper.rb
55
+ - spec/support/new_flight.html.erb
56
+ - spec/support/new_user.html.haml
48
57
  - tasks/i15r.rake
49
58
  - todos.markdown
50
59
  has_rdoc: true
@@ -76,8 +85,11 @@ signing_key:
76
85
  specification_version: 3
77
86
  summary: The internationalizer. Makes your Ruby app international
78
87
  test_files:
88
+ - spec/erb/rails_helper_matcher_spec.rb
89
+ - spec/erb/tag_attribute_matcher_spec.rb
90
+ - spec/erb/tag_content_matcher_spec.rb
91
+ - spec/haml/rails_helper_matcher_spec.rb
92
+ - spec/haml/tag_content_matcher_spec.rb
79
93
  - spec/i15r_spec.rb
80
94
  - spec/pattern_matcher_spec.rb
81
- - spec/rails_helper_matcher_spec.rb
82
- - spec/tag_attribute_matcher_spec.rb
83
- - spec/tag_content_matcher_spec.rb
95
+ - spec/spec_helper.rb
@@ -1,69 +0,0 @@
1
- require 'i15r/base'
2
-
3
- module I15R
4
- module PatternMatchers
5
- class RailsHelperMatcher < Base
6
-
7
- def self.match_link_to_title
8
- patt = /^(.*)<%=\s*link_to\s+['"](.*?)['"]\s*,(.*)%>(.*)$/
9
- matches do |text, prefix|
10
- if m = patt.match(text)
11
- i18n_string = I15R::Base.get_i18n_message_string(m[2], prefix)
12
- i18ned_row = %(#{m[1]}<%= link_to I18n.t("#{i18n_string}"),#{m[3]}%>#{m[4]})
13
- [m[0], i18ned_row]
14
- end
15
- end
16
- end
17
- register_matcher :match_link_to_title
18
-
19
- def self.match_label_helper_text
20
- patt = /^(.*)<%=(.*)\.label(.*),\s*['"](.*?)['"]\s*%>(.*)$/
21
- matches do |text, prefix|
22
- if m = patt.match(text)
23
- i18n_string = I15R::Base.get_i18n_message_string(m[4], prefix)
24
- i18ned_row = %(#{m[1]}<%=#{m[2]}.label#{m[3]}, I18n.t("#{i18n_string}") %>#{m[5]})
25
- [m[0], i18ned_row]
26
- end
27
- end
28
- end
29
- register_matcher :match_label_helper_text
30
-
31
- def self.match_label_tag_helper_text
32
- patt = /^(.*)<%=(.*)label_tag (.*),\s*['"](.*?)['"]\s*%>(.*)$/
33
- matches do |text, prefix|
34
- if m = patt.match(text)
35
- i18n_string = I15R::Base.get_i18n_message_string(m[4], prefix)
36
- i18ned_row = %(#{m[1]}<%=#{m[2]}label_tag #{m[3]}, I18n.t("#{i18n_string}") %>#{m[5]})
37
- [m[0], i18ned_row]
38
- end
39
- end
40
- end
41
- register_matcher :match_label_tag_helper_text
42
-
43
- def self.match_submit_helper_text
44
- patt = /^(.*)<%=(.*)\.submit\s*['"](.*?)['"]\s*%>(.*)$/
45
- matches do |text, prefix|
46
- if m = patt.match(text)
47
- i18n_string = I15R::Base.get_i18n_message_string(m[3], prefix)
48
- i18ned_row = %(#{m[1]}<%=#{m[2]}.submit I18n.t("#{i18n_string}") %>#{m[4]})
49
- [m[0], i18ned_row]
50
- end
51
- end
52
- end
53
- register_matcher :match_submit_helper_text
54
-
55
- def self.match_submit_tag_helper_text
56
- patt = /^(.*)<%=\s*submit_tag\s*['"](.*?)['"]\s*%>(.*)$/
57
- matches do |text, prefix|
58
- if m = patt.match(text)
59
- i18n_string = I15R::Base.get_i18n_message_string(m[2], prefix)
60
- i18ned_row = %(#{m[1]}<%= submit_tag I18n.t("#{i18n_string}") %>#{m[3]})
61
- [m[0], i18ned_row]
62
- end
63
- end
64
- end
65
- register_matcher :match_submit_tag_helper_text
66
-
67
- end
68
- end
69
- end
@@ -1,21 +0,0 @@
1
- require 'i15r/base'
2
-
3
- module I15R
4
- module PatternMatchers
5
- class TagAttributeMatcher < Base
6
-
7
- def self.match_title_attribute
8
- patt = /^(.*)(<a\s+.*title=)['"](.*?)['"](.*)/
9
- matches do |text, prefix|
10
- if m = patt.match(text)
11
- i18n_string = I15R::Base.get_i18n_message_string(m[3], prefix)
12
- i18ned_row = %(#{m[1]}#{m[2]}"<%= I18n.t("#{i18n_string}") %>"#{m[4]})
13
- [m[0], i18ned_row]
14
- end
15
- end
16
- end
17
- register_matcher :match_title_attribute
18
-
19
- end
20
- end
21
- end
@@ -1,20 +0,0 @@
1
- require 'i15r/base'
2
-
3
- module I15R
4
- module PatternMatchers
5
- class TagContentMatcher < Base
6
- def self.match_tag_content
7
- patt = /^(.*)>(\s*)(\w[\s\w:'"!?\.,]+)\s*<\/(.*)$/
8
- matches do |text, prefix|
9
- if m = patt.match(text)
10
- i18n_string = I15R::Base.get_i18n_message_string(m[3], prefix)
11
- ending_punctuation = m[3][/([?.!:\s]*)$/, 1]
12
- i18ned_row = %(#{m[1]}>#{m[2]}<%= I18n.t("#{i18n_string}") %>#{ending_punctuation.to_s}</#{m[4]})
13
- [m[0], i18ned_row]
14
- end
15
- end
16
- end
17
- register_matcher :match_tag_content
18
- end
19
- end
20
- end
@@ -1,15 +0,0 @@
1
- $:.unshift File.join(File.expand_path(File.dirname(__FILE__)), "..", "lib")
2
-
3
- require 'i15r/pattern_matcher'
4
- require "spec"
5
-
6
- # FIXME: since matcher blocks are added and executed in the Base class, that's what should be called
7
- # in the tests. That's not elegant and tests are not independent: they are coupled through the Base's run method
8
- describe I15R::PatternMatchers::TagAttributeMatcher do
9
- it "should replace a link's title" do
10
- plain = %(Site root\nThis is it: <a title="site root" href="/"><img src="site_logo.png" /></a>)
11
- i18ned = %(Site root\nThis is it: <a title="<%= I18n.t("users.new.site_root") %>" href="/"><img src="site_logo.png" /></a>)
12
- I15R::PatternMatchers::TagAttributeMatcher.run(plain, "users.new").should == i18ned
13
- end
14
-
15
- end