Skip to content

Commit

Permalink
correct line number reporting for embedded engines
Browse files Browse the repository at this point in the history
* errors in interpolation in InterpolatedTiltEngines not yet working (e.g. markdown)
* precompiled engines not yet working (e.g. liquid)
  • Loading branch information
minad committed May 6, 2011
1 parent dfc3236 commit 50ce72a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
10 changes: 8 additions & 2 deletions lib/slim/embedded_engine.rb
Expand Up @@ -40,11 +40,17 @@ def collect_text(body)
end
end

def collect_newlines(body)
body[1..-1].inject([:multi]) do |multi, exp|
exp[0] == :newline ? (multi << exp) : multi
end
end

# Basic tilt engine
class TiltEngine < EmbeddedEngine
def on_slim_embedded(engine, body)
engine = Tilt[engine] || raise("Tilt engine #{engine} is not available.")
render(engine, collect_text(body))
[:multi, render(engine, collect_text(body)), collect_newlines(body)]
end
end

Expand Down Expand Up @@ -118,7 +124,7 @@ def on_slim_embedded(engine, body)
# Embeds ruby code
class RubyEngine < EmbeddedEngine
def on_slim_embedded(engine, body)
[:code, collect_text(body)]
[:code, "\n" + collect_text(body)]
end
end

Expand Down
27 changes: 26 additions & 1 deletion test/slim/test_ruby_errors.rb
Expand Up @@ -82,7 +82,32 @@ def test_embedded_ruby
= unknown_ruby_method
}

assert_ruby_error NameError,"(__TEMPLATE__):5", source
assert_ruby_error NameError,"(__TEMPLATE__):6", source
end

def test_embedded_markdown
source = %q{
markdown:
#Header
Hello from #{"Markdown!"}
"Second Line!"
= unknown_ruby_method
}

assert_ruby_error NameError,"(__TEMPLATE__):6", source
end

def test_embedded_liquid
source = %q{
- text = 'before liquid block'
liquid:
First
{{text}}
Third
= unknown_ruby_method
}

assert_ruby_error NameError,"(__TEMPLATE__):7", source
end

def test_embedded_javascript
Expand Down

0 comments on commit 50ce72a

Please sign in to comment.