Class: Haml::I18n::Extractor::ExceptionFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/haml-i18n-extractor/extraction/finder/exception_finder.rb

Constant Summary collapse

/link_to\s*\(?\s*["](.*?)["]\s*,\s*(.*)\)?/
/link_to\s*\(?\s*['](.*?)[']\s*,\s*(.*)\)?/
/link_to\s*\(?['](.*?)[']\)?.*\sdo\s*$/
/link_to\s*\(?["](.*?)["]\)?.*\sdo\s*$/
/link_to\s*\(?([^'"]*?)\)?.*/
FORM_SUBMIT_BUTTON_SINGLE_Q =
/[a-z]\.submit\s?['](.*?)['].*$/
FORM_SUBMIT_BUTTON_DOUBLE_Q =
/[a-z]\.submit\s?["](.*?)["].*$/
EXCEPTION_MATCHES =

this class simply returns text except for anything that matches these regexes. returns first match.

[ LINK_TO_BLOCK_FORM_DOUBLE_Q, LINK_TO_BLOCK_FORM_SINGLE_Q,
LINK_TO_REGEX_DOUBLE_Q, LINK_TO_REGEX_SINGLE_Q , LINK_TO_NO_QUOTES,
FORM_SUBMIT_BUTTON_SINGLE_Q, FORM_SUBMIT_BUTTON_DOUBLE_Q]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ ExceptionFinder

Returns a new instance of ExceptionFinder.



22
23
24
# File 'lib/haml-i18n-extractor/extraction/finder/exception_finder.rb', line 22

def initialize(text)
  @text = text
end

Class Method Details

.could_match_script?(txt) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/haml-i18n-extractor/extraction/finder/exception_finder.rb', line 26

def self.could_match_script?(txt)
  # want to match:
  # = 'foo'
  # = "foo"
  # = link_to 'bla'
  #
  # but not match:
  # = ruby_var = 2
  scanner = StringScanner.new(txt)
  scanner.scan(/\s+/)
  scanner.scan(/['"]/) || EXCEPTION_MATCHES.any? {|regex| txt.match(regex) }
end

Instance Method Details

#findObject



39
40
41
42
43
44
45
46
47
48
# File 'lib/haml-i18n-extractor/extraction/finder/exception_finder.rb', line 39

def find
  ret = @text
  EXCEPTION_MATCHES.each do |regex|
    if @text.match(regex)
      ret = $1
      break # return whatever it finds on first try, order of above regexes matters
    end
  end
  ret
end