@@ -5,7 +5,7 @@ class Liquid < Scanner
5
5
6
6
register_for :liquid
7
7
8
- DIRECTIVE_KEYWORDS = "list|endlist|for|endfor|wrap|endwrap|if|endif|unless|endunless|elsif|assign|cycle|capture|end|capture|fill|iflist|endiflist|else"
8
+ DIRECTIVE_KEYWORDS = "list|endlist|for|endfor|wrap|endwrap|if|endif|unless|endunless|elsif|assignlist| assign|cycle|capture|end|capture|fill|iflist|endiflist|else"
9
9
10
10
DIRECTIVE_OPERATORS = "=|==|!=|>|<|<=|>=|contains"
11
11
@@ -20,7 +20,7 @@ class Liquid < Scanner
20
20
/x
21
21
22
22
def setup
23
- @html_scanner = CodeRay . scanner ( :html , tokens : @tokens , keep_tokens : true , keep_state : false )
23
+ @html_scanner = CodeRay . scanner ( :html , tokens : @tokens , keep_tokens : true , keep_state : true )
24
24
end
25
25
26
26
def scan_spaces ( encoder )
@@ -31,7 +31,7 @@ def scan_spaces(encoder)
31
31
32
32
def scan_selector ( encoder , options , match )
33
33
scan_spaces ( encoder )
34
- if match = scan ( /in|with/ )
34
+ if match = scan ( /in|with|script|tabs|items_per_tab / )
35
35
Rails . logger . debug 'DEBUG: Scanning selector'
36
36
scan_spaces ( encoder )
37
37
encoder . text_token match , :type
@@ -43,26 +43,29 @@ def scan_selector(encoder, options, match)
43
43
encoder . text_token variable , :variable
44
44
end
45
45
scan_selector ( encoder , options , match )
46
+ else
47
+ false
46
48
end
47
49
end
48
50
49
51
def scan_directive ( encoder , options , match )
50
52
Rails . logger . debug 'DEBUG: Scanning directive'
51
- encoder . text_token match , :key
53
+ encoder . text_token match , :tag
52
54
state = :liquid
53
55
scan_spaces ( encoder )
54
56
#This regex doesn't work and I don't know why
55
57
if match = scan ( /#{ DIRECTIVE_KEYWORDS } / )
56
58
encoder . text_token match , :directive
57
59
scan_spaces ( encoder )
58
- if match =~ /if/
60
+ if match =~ /if|assign|assignlist /
59
61
if match = scan ( /\w +\. ?\w */ )
60
62
encoder . text_token match , :variable
61
63
end
62
64
scan_spaces ( encoder )
63
65
if match = scan ( /#{ MATH } / )
64
66
encoder . text_token match , :char
65
67
scan_spaces ( encoder )
68
+ scan_selector ( encoder , options , match )
66
69
end
67
70
if match = scan ( /(\w +)|('\S +')|(".+")/ )
68
71
encoder . text_token match , :variable
@@ -73,7 +76,7 @@ def scan_directive(encoder, options, match)
73
76
scan_selector ( encoder , options , match )
74
77
scan_spaces ( encoder )
75
78
if match = scan ( /%}/ )
76
- encoder . text_token match , :key
79
+ encoder . text_token match , :tag
77
80
state = :initial
78
81
end
79
82
end
@@ -98,18 +101,18 @@ def scan_output_filters(encoder, options, match)
98
101
99
102
def scan_output ( encoder , options , match )
100
103
Rails . logger . debug 'DEBUG: Scanning output'
101
- encoder . text_token match , :key
104
+ encoder . text_token match , :tag
102
105
state = :liquid
103
106
scan_spaces ( encoder )
104
- if match = scan ( /(\w +)|('\S +')|("\w +")/ )
107
+ if match = scan ( /(\w +\. ? \w * )|('\S +')|("\w +")/ )
105
108
encoder . text_token match , :variable
106
109
end
107
110
if match = scan ( /(\s \| \s )/ )
108
111
scan_output_filters ( encoder , options , match )
109
112
end
110
113
scan_spaces ( encoder )
111
114
if match = scan ( /}}/ )
112
- encoder . text_token match , :key
115
+ encoder . text_token match , :tag
113
116
end
114
117
state = :initial
115
118
end
@@ -120,7 +123,13 @@ def scan_tokens(encoder, options)
120
123
121
124
until eos?
122
125
if ( match = scan_until ( /(?=({{|{%))/ ) || scan_rest ) and not match . empty? and state != :liquid
123
- @html_scanner . tokenize ( match , tokens : encoder )
126
+ Rails . logger . debug "DEBUG: HTML scanning: #{ match } "
127
+ if match =~ /^"|^'/
128
+ #match = match.sub /^"|^'/, ''
129
+ @html_scanner . tokenize ( match , { tokens : encoder , state : :attribute_value_string } )
130
+ else
131
+ @html_scanner . tokenize ( match , tokens : encoder )
132
+ end
124
133
state = :initial
125
134
scan_spaces ( encoder )
126
135
elsif match = scan ( /{%/ )
0 commit comments