Class: Haml::I18n::Extractor::TextFinder
- Inherits:
-
Object
- Object
- Haml::I18n::Extractor::TextFinder
- Defined in:
- lib/haml-i18n-extractor/text_finder.rb
Constant Summary collapse
- THINGS_THAT_ARE_NOT_POTENTIAL_TEXT =
[ Haml::Parser::DIV_CLASS, Haml::Parser::DIV_ID, Haml::Parser::COMMENT, Haml::Parser::SANITIZE, Haml::Parser::FLAT_SCRIPT, Haml::Parser::FILTER, Haml::Parser::DOCTYPE, Haml::Parser::ESCAPE ]
- SIMPLE_STRING_REGEX =
hint: Use rubular.com
/["'](.*)["']/
- LINK_TO_REGEX =
“yes”
‘yes’
/link_to\s*\(?\s*['"](.*)['"]\s*,\s*(.*)\)?/
- ELEMENT_REGEX =
/%([\w.#-]+)({.+?})?(=)?(.*)/
Instance Method Summary collapse
- #find ⇒ Object
-
#initialize(haml) ⇒ TextFinder
constructor
%foo.bar yes %foo.bar= no %foo=> ‘b’ yes rubular.com against %foo#bar#cheez=> ‘hell’= “what #var”.
- #line ⇒ Object
-
#process_by_regex ⇒ Object
returns [ line_type, text_found ].
Constructor Details
#initialize(haml) ⇒ TextFinder
%foo.bar yes %foo.bar= no %foo=> ‘b’ yes rubular.com against %foo#bar#cheez=> ‘hell’= “what #var”
26 27 28 29 |
# File 'lib/haml-i18n-extractor/text_finder.rb', line 26 def initialize(haml) @haml = haml @parser = Haml::Parser.new(haml, Haml::Options.new) end |
Instance Method Details
#find ⇒ Object
44 45 46 |
# File 'lib/haml-i18n-extractor/text_finder.rb', line 44 def find text_match = process_by_regex.last end |
#line ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/haml-i18n-extractor/text_finder.rb', line 31 def line if @haml == "" return Haml::Parser::Line.new("", "", "", 0, @parser, false) end match = @haml.rstrip.scan(/(([ \t]+)?(.*?))(?:\Z|\r\n|\r|\n)/m) match.pop haml_line ||= match.each_with_index.map do |(full, whitespace, text), index| Haml::Parser::Line.new(whitespace, text.rstrip, full, index, @parser, false) end.first haml_line end |
#process_by_regex ⇒ Object
returns [ line_type, text_found ]
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/haml-i18n-extractor/text_finder.rb', line 49 def process_by_regex case line.full[0] when *THINGS_THAT_ARE_NOT_POTENTIAL_TEXT [:not_text, ""] when Haml::Parser::SILENT_SCRIPT parse_silent_script when Haml::Parser::ELEMENT parse_element when Haml::Parser::SCRIPT parse_loud_script else [:text, line.full.strip] end end |