Module: Hamlit::Parsers::Script
Constant Summary
collapse
- INTERNAL_STATEMENTS =
%w[else elsif when].freeze
- DEFAULT_SCRIPT_OPTIONS =
{ force_escape: false, disable_escape: false }.freeze
Instance Method Summary
collapse
extended
#count_indent, #count_width, #indent_label, #next_indent, #next_width, #replace_hard_tabs, #reset_indent, #same_indent?, #validate_indentation!, #with_indented
#assert_scan!, #copmile_error!, #syntax_error, #syntax_error!
Instance Method Details
#parse_preserve(scanner) ⇒ Object
37
38
39
40
41
42
|
# File 'lib/hamlit/parsers/script.rb', line 37
def parse_preserve(scanner)
assert_scan!(scanner, /~/)
code = scan_code(scanner)
escape_html([:haml, :preserve, code])
end
|
#parse_script(scanner, options = {}) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/hamlit/parsers/script.rb', line 20
def parse_script(scanner, options = {})
assert_scan!(scanner, /=|&=|!=/)
options = DEFAULT_SCRIPT_OPTIONS.merge(options)
code = scan_code(scanner)
return syntax_error("There's no Ruby code for = to evaluate.") if code.empty?
unless has_block?
return [:dynamic, code] if options[:disable_escape]
return escape_html([:dynamic, code], options[:force_escape])
end
ast = [:haml, :script, code, options]
ast += with_indented { parse_lines }
ast << [:code, 'end']
ast
end
|
#parse_silent_script(scanner) ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/hamlit/parsers/script.rb', line 44
def parse_silent_script(scanner)
assert_scan!(scanner, /-/)
if scanner.scan(/#/)
with_indented { skip_lines }
return [:multi]
end
ast = [:code]
ast << scan_code(scanner)
return ast unless has_block?
ast = [:multi, ast]
ast += with_indented { parse_lines }
ast << [:code, 'end'] unless same_indent?(next_line) && internal_statement?(next_line)
ast
end
|