Class: ExtractI18n::HTMLExtractor::Match::ErbDirectiveMatch
- Defined in:
- lib/extract_i18n/html_extractor/match/erb_directive_match.rb
Constant Summary collapse
- REGEXPS =
[ [/^([ \t]*link_to )(("[^"]+")|('[^']+'))/, '\1%s', 2], [/^([ \t]*link_to (.*),[ ]?title:[ ]?)(("[^"]+")|('[^']+'))/, '\1%s', 3], [/^([ \t]*[a-z_]+\.[a-z_]+_field (.*),[ ]?placeholder:[ ]?)(("[^"]+")|('[^']+'))/, '\1%s', 3], [/^([ \t]*[a-z_]+\.text_area (.*),[ ]?placeholder:[ ]?)(("[^"]+")|('[^']+'))/, '\1%s', 3], [/^([ \t]*[a-z_]+\.submit )(("[^"]+")|('[^']+'))/, '\1%s', 2], [/^([ \t]*[a-z_]+\.label\s+\:[a-z_]+\,\s+)(("[^"]+")|('[^']+'))/, '\1%s', 2] ].freeze
Instance Attribute Summary
Attributes inherited from NodeMatch
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(document, fragment_id, text, regexp) ⇒ ErbDirectiveMatch
constructor
A new instance of ErbDirectiveMatch.
- #replace_text!(key, i18n_t) ⇒ Object
Methods inherited from NodeMatch
Constructor Details
#initialize(document, fragment_id, text, regexp) ⇒ ErbDirectiveMatch
14 15 16 17 18 |
# File 'lib/extract_i18n/html_extractor/match/erb_directive_match.rb', line 14 def initialize(document, fragment_id, text, regexp) super(document, text) @fragment_id = fragment_id @regexp = regexp end |
Class Method Details
.create(document, fragment_id) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/extract_i18n/html_extractor/match/erb_directive_match.rb', line 24 def self.create(document, fragment_id) REGEXPS.map do |r| match = document.erb_directives[fragment_id].match(r[0]) new(document, fragment_id, match[r[2]][1...-1], r) if match && match[r[2]] end end |
Instance Method Details
#replace_text!(key, i18n_t) ⇒ Object
20 21 22 |
# File 'lib/extract_i18n/html_extractor/match/erb_directive_match.rb', line 20 def replace_text!(key, i18n_t) document.erb_directives[@fragment_id].gsub!(@regexp[0], @regexp[1] % i18n_t.strip) end |