Module: ThemeCheck::ParsingHelpers

Included in:
LiquidCheck
Defined in:
lib/theme_check/parsing_helpers.rb

Instance Method Summary collapse

Instance Method Details

#outside_of_strings(markup) {|scanner.rest| ... } ⇒ Object

Yield each chunk outside of “…”, ‘…’

Yields:

  • (scanner.rest)


5
6
7
8
9
10
11
12
13
14
15
# File 'lib/theme_check/parsing_helpers.rb', line 5

def outside_of_strings(markup)
  scanner = StringScanner.new(markup)

  while scanner.scan(/.*?("|')/)
    yield scanner.matched[..-2]
    # Skip to the end of the string
    scanner.skip_until(scanner.matched[-1] == "'" ? /[^\\]'/ : /[^\\]"/)
  end

  yield scanner.rest if scanner.rest?
end