@@ -7,15 +7,17 @@ class Liquid < Scanner
7
7
8
8
DIRECTIVE_KEYWORDS = /endlist|list|endfor|for|endwrap|wrap|endif|if|endunless|unless|elsif|assignlist|assign|cycle|capture|end|capture|fill|endiflist|iflist|else/
9
9
10
- DIRECTIVE_OPERATORS = /#{ MATH } |contains/
11
-
12
10
MATH = /==|=|!=|>|<=|<|>|\+ /
13
11
12
+ DIRECTIVE_PREPOSITIONS = /contains|in|#{ MATH } /
13
+
14
14
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/
15
15
16
16
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/
17
17
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/
19
21
20
22
LIQUID_DIRECTIVE_BLOCK = /
21
23
{{1,2}%
@@ -35,7 +37,11 @@ def scan_spaces(encoder)
35
37
36
38
def scan_key_value_pair ( encoder , options , match )
37
39
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
39
45
if delimiter = scan ( /:/ )
40
46
encoder . text_token delimiter , :delimiter
41
47
scan_spaces ( encoder )
@@ -50,9 +56,14 @@ def scan_key_value_pair(encoder, options, match)
50
56
def scan_selector ( encoder , options , match )
51
57
scan_spaces ( encoder )
52
58
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
56
67
scan_selector ( encoder , options , match )
57
68
else
58
69
false
@@ -68,11 +79,12 @@ def scan_directive(encoder, options, match)
68
79
encoder . text_token match , :directive
69
80
scan_spaces ( encoder )
70
81
if match =~ /if|assign|assignlist/
82
+ scan_selector ( encoder , options , match )
71
83
if match = scan ( /\w +\. ?\w */ )
72
84
encoder . text_token match , :variable
73
85
end
74
86
scan_spaces ( encoder )
75
- if match = scan ( /#{ MATH } / )
87
+ if match = scan ( /#{ DIRECTIVE_PREPOSITIONS } / )
76
88
encoder . text_token match , :operator
77
89
scan_spaces ( encoder )
78
90
scan_selector ( encoder , options , match )
0 commit comments