Skip to content

Commit 429751a

Browse files
committed
set key value pair as directives sometimes
1 parent 7f25ad3 commit 429751a

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

lib/coderay/scanners/liquid.rb

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@ class Liquid < Scanner
77

88
DIRECTIVE_KEYWORDS = /endlist|list|endfor|for|endwrap|wrap|endif|if|endunless|unless|elsif|assignlist|assign|cycle|capture|end|capture|fill|endiflist|iflist|else/
99

10-
DIRECTIVE_OPERATORS = /#{MATH}|contains/
11-
1210
MATH = /==|=|!=|>|<=|<|>|\+/
1311

12+
DIRECTIVE_PREPOSITIONS= /contains|in|#{MATH}/
13+
1414
FILTER_KEYWORDS = /#{FILTER_WITH_VALUE_KEYWORDS}|textilize|capitalize|downcase|upcase|first|last|sort|map|size|escape_once|escape|strip_html|strip_newlines|newline_to_br/
1515

1616
FILTER_WITH_VALUE_KEYWORDS = /date|replace_first|replace|remove_first|remove_first|remove|minus|times|divided_by|modulo|mod|split|join|truncatewords|truncate|prepend|append/
1717

18-
SELECTOR_KEYWORDS = /in|with|snippet|script|tag|tabs|items_per_tab/
18+
SELECTOR_KEYWORDS = /in|with|snippet|script|content_item|folder|widget|wrapper|category|asset_folder|asset/
19+
20+
DIRECTIVE_KEYS = /#{SELECTOR_KEYWORDS}|tabs|items_per_tab/
1921

2022
LIQUID_DIRECTIVE_BLOCK = /
2123
{{1,2}%
@@ -35,7 +37,11 @@ def scan_spaces(encoder)
3537

3638
def scan_key_value_pair(encoder, options, match)
3739
scan_spaces(encoder)
38-
encoder.text_token match, :key
40+
if match =~ /#{SELECTOR_KEYWORDS}/
41+
encoder.text_token match, :directive
42+
else
43+
encoder.text_token match, :key
44+
end
3945
if delimiter = scan(/:/)
4046
encoder.text_token delimiter, :delimiter
4147
scan_spaces(encoder)
@@ -50,9 +56,14 @@ def scan_key_value_pair(encoder, options, match)
5056
def scan_selector(encoder, options, match)
5157
scan_spaces(encoder)
5258
Rails.logger.debug 'DEBUG: Looking for a selector'
53-
if match = scan(/#{SELECTOR_KEYWORDS}/)
54-
Rails.logger.debug 'DEBUG: Selector keyword found'
55-
scan_key_value_pair(encoder, options, match)
59+
if match = scan(/#{DIRECTIVE_KEYS}/)
60+
if peek(1) == ':'
61+
Rails.logger.debug "DEBUG: Peek: #{peek(5)}"
62+
Rails.logger.debug 'DEBUG: Selector keyword found'
63+
scan_key_value_pair(encoder, options, match)
64+
else
65+
encoder.text_token match, :variable
66+
end
5667
scan_selector(encoder, options, match)
5768
else
5869
false
@@ -68,11 +79,12 @@ def scan_directive(encoder, options, match)
6879
encoder.text_token match, :directive
6980
scan_spaces(encoder)
7081
if match =~ /if|assign|assignlist/
82+
scan_selector(encoder, options, match)
7183
if match = scan(/\w+\.?\w*/)
7284
encoder.text_token match, :variable
7385
end
7486
scan_spaces(encoder)
75-
if match = scan(/#{MATH}/)
87+
if match = scan(/#{DIRECTIVE_PREPOSITIONS}/)
7688
encoder.text_token match, :operator
7789
scan_spaces(encoder)
7890
scan_selector(encoder, options, match)

0 commit comments

Comments
 (0)