Class: ExtractI18n::HTMLExtractor::Match::ErbDirectiveMatch

Inherits:
NodeMatch
  • Object
show all
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

#document, #key, #text

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from NodeMatch

#to_s, #translation_key_object

Constructor Details

#initialize(document, fragment_id, text, regexp) ⇒ ErbDirectiveMatch

Returns a new instance of 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