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
16
17
# File 'lib/theme_check/parsing_helpers.rb', line 5

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

  while scanner.scan(/.*?("|')/)
    yield scanner.matched[0..-2]
    quote = scanner.matched[-1] == "'" ? "'" : "\""
    # Skip to the end of the string
    # Check for empty string first, since follow regexp uses lookahead
    scanner.skip(/#{quote}/) || scanner.skip_until(/[^\\]#{quote}/)
  end

  yield scanner.rest if scanner.rest?
end