Class: Haml::I18n::Extractor::TextReplacer

Inherits:
Object
  • Object
show all
Includes:
Helpers::StringHelpers
Defined in:
lib/haml-i18n-extractor/extraction/replacer/text_replacer.rb

Constant Summary

Constants included from Helpers::StringHelpers

Helpers::StringHelpers::LIMIT_KEY_NAME, Helpers::StringHelpers::NOT_ALLOWED_IN_KEYNAME

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::StringHelpers

#change_one_interpolation, #could_match_script?, #html_comment?, #interpolated?, #link_to?, #normalize_interpolation, #normalized_name

Constructor Details

#initialize(full_line, text_to_replace, line_type, path, metadata = {}) ⇒ TextReplacer

Returns a new instance of TextReplacer.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/haml-i18n-extractor/extraction/replacer/text_replacer.rb', line 11

def initialize(full_line, text_to_replace,line_type, path,  = {})
  @path = path
  @orig_line = @full_line = full_line
  @text_to_replace = text_to_replace
  @metadata = 
  if LINE_TYPES_ALL.include?(line_type)
    @line_type = line_type
  else
    raise Extractor::NotDefinedLineType, "line type #{line_type} for #{full_line} does not make sense!"
  end
end

Instance Attribute Details

#full_lineObject (readonly)

Returns the value of attribute full_line.



8
9
10
# File 'lib/haml-i18n-extractor/extraction/replacer/text_replacer.rb', line 8

def full_line
  @full_line
end

#line_typeObject (readonly)

Returns the value of attribute line_type.



8
9
10
# File 'lib/haml-i18n-extractor/extraction/replacer/text_replacer.rb', line 8

def line_type
  @line_type
end

#text_to_replaceObject (readonly)

Returns the value of attribute text_to_replace.



8
9
10
# File 'lib/haml-i18n-extractor/extraction/replacer/text_replacer.rb', line 8

def text_to_replace
  @text_to_replace
end

Instance Method Details

#interpolation_helperObject



32
33
34
# File 'lib/haml-i18n-extractor/extraction/replacer/text_replacer.rb', line 32

def interpolation_helper
  Haml::I18n::Extractor::InterpolationHelper.new(@text_to_replace, t_name)
end

#modified_lineObject

the new full line, including a ‘t()` replacement instead of the `text_to_replace` portion.



41
42
43
44
45
46
47
48
49
# File 'lib/haml-i18n-extractor/extraction/replacer/text_replacer.rb', line 41

def modified_line
  return @full_line if has_been_translated?(@full_line)
  full_line = @full_line.dup
  #puts t_method.inspect if Haml::I18n::Extractor.debug?
  keyname = orig_interpolated? ? interpolation_helper.keyname_with_vars : t_method
  gsub_replacement!(full_line, @text_to_replace, keyname)
  apply_ruby_evaling!(full_line, keyname)
  full_line
end

#orig_interpolated?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/haml-i18n-extractor/extraction/replacer/text_replacer.rb', line 36

def orig_interpolated?
  interpolated?(@orig_line)
end

#replace_hashObject



27
28
29
30
# File 'lib/haml-i18n-extractor/extraction/replacer/text_replacer.rb', line 27

def replace_hash
  #legacy
  result.info
end

#resultObject



23
24
25
# File 'lib/haml-i18n-extractor/extraction/replacer/text_replacer.rb', line 23

def result
  @result ||= Haml::I18n::Extractor::ReplacerResult.new(modified_line, t_name, @text_to_replace, true, @path)
end