class HtmlToHaml::Erb::ControlFlowMatcher
Constants
- CONTROL_FLOW_BEGINNING_OF_LINE_KEYWORDS
- CONTROL_FLOW_CONTINUE_KEYWORDS
- CONTROL_FLOW_MIDDLE_OF_LINE_KEYWORDS
Public Instance Methods
begin_case_statement?(erb:)
click to toggle source
# File lib/html_to_haml/tools/erb/control_flow_matcher.rb, line 12 def begin_case_statement?(erb:) matches_keywords_at_beginning_of_line?(erb: erb, keywords: ["case"]) end
begin_indented_control_flow?(erb:)
click to toggle source
# File lib/html_to_haml/tools/erb/control_flow_matcher.rb, line 16 def begin_indented_control_flow?(erb:) matches_keywords?(erb: erb, keywords: CONTROL_FLOW_MIDDLE_OF_LINE_KEYWORDS) || matches_keywords_at_beginning_of_line?(erb: erb, keywords: CONTROL_FLOW_BEGINNING_OF_LINE_KEYWORDS) end
continue_indented_control_flow?(erb:)
click to toggle source
# File lib/html_to_haml/tools/erb/control_flow_matcher.rb, line 21 def continue_indented_control_flow?(erb:) matches_keywords_at_beginning_of_line?(erb: erb, keywords: CONTROL_FLOW_CONTINUE_KEYWORDS) end
end_of_block?(erb:)
click to toggle source
# File lib/html_to_haml/tools/erb/control_flow_matcher.rb, line 25 def end_of_block?(erb:) erb_without_strings(erb: erb) =~ /\s*-\send/ end
Private Instance Methods
erb_without_strings(erb:)
click to toggle source
# File lib/html_to_haml/tools/erb/control_flow_matcher.rb, line 39 def erb_without_strings(erb:) erb.gsub(/".*?"/, '').gsub(/'.*?'/, '') end
matches_keywords?(erb:, keywords:)
click to toggle source
# File lib/html_to_haml/tools/erb/control_flow_matcher.rb, line 35 def matches_keywords?(erb:, keywords:) erb_without_strings(erb: erb) =~ /\s*(-|=)(.*)\s+(#{keywords.join("|")})(\s|$)/ end
matches_keywords_at_beginning_of_line?(erb:, keywords:)
click to toggle source
# File lib/html_to_haml/tools/erb/control_flow_matcher.rb, line 31 def matches_keywords_at_beginning_of_line?(erb:, keywords:) erb_without_strings(erb: erb) =~ /\s*(-|=)\s*(#{keywords.join("|")})(\s|$)/ end