Ruby code in code element derails slimrb if it contains a string with an escaped expression
n8chz opened this issue · 1 comments
n8chz commented
I'm using Slim 4.1.0 with ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-linux-gnu]
If test.slim
is as follows:
doctype html
html lang="en"
head
meta charset="utf-8"
title Test
body
pre
code
| #!/usr/bin/ruby
foo = 1
puts "This is test ##{foo}"
and I run
slimrb test.slim test.html
I get the error message
NameError: undefined local variable or method `foo' for #<Object:0x0000563516d4ff70>
Use --trace for backtrace.
When I use --trace for backtrace, I get
Traceback (most recent call last):
8: from /usr/local/bin/slimrb:23:in `<main>'
7: from /usr/local/bin/slimrb:23:in `load'
6: from /var/lib/gems/2.7.0/gems/slim-4.1.0/bin/slimrb:6:in `<top (required)>'
5: from /var/lib/gems/2.7.0/gems/slim-4.1.0/lib/slim/command.rb:19:in `run'
4: from /var/lib/gems/2.7.0/gems/slim-4.1.0/lib/slim/command.rb:110:in `process'
3: from /var/lib/gems/2.7.0/gems/tilt-2.0.10/lib/tilt/template.rb:109:in `render'
2: from /var/lib/gems/2.7.0/gems/tilt-2.0.10/lib/tilt/template.rb:170:in `evaluate'
1: from /var/lib/gems/2.7.0/gems/tilt-2.0.10/lib/tilt/template.rb:170:in `call'
test.slim:11:in `__tilt_560': undefined local variable or method `foo' for #<Object:0x0000555c49a926d0> (NameError)
n8chz commented
I find that I can overcome this (and display the code as expected in the resulting HTML document) by prefixing with a \
those #
s used to escape expressions in strings.