Skip to content
Browse files

Use correct lvar regexp (#174)

  • Loading branch information...
1 parent 65b1cd1 commit 8e513b9daa37e443ffebc16ab5987b431ff3c8f4 @judofyr judofyr committed Feb 28, 2013
Showing with 4 additions and 3 deletions.
  1. +1 −1 lib/tilt/template.rb
  2. +3 −2 test/tilt_template_test.rb
View
2 lib/tilt/template.rb
@@ -187,7 +187,7 @@ def precompiled_template(locals)
# reporting in Kernel::caller and backtraces.
def precompiled_preamble(locals)
locals.map do |k,v|
- if k.to_s =~ /\A[a-z]\w*\z/
+ if k.to_s =~ /\A[a-z_][a-zA-Z_0-9]*\z/
"#{k} = locals[#{k.inspect}]"
else
raise "invalid locals key: #{k.inspect} (keys must be variable names)"
View
5 test/tilt_template_test.rb
@@ -135,9 +135,10 @@ def precompiled_template(locals)
end
test "template_source with locals having non-variable keys raises error" do
- inst = SourceGeneratingMockTemplate.new { |t| '1 + 2 = #{ANSWER}' }
- err = assert_raise(RuntimeError) { inst.render(Object.new, 'ANSWER' => '3') }
+ inst = SourceGeneratingMockTemplate.new { |t| '1 + 2 = #{_answer}' }
+ err = assert_raise(RuntimeError) { inst.render(Object.new, 'ANSWER' => 3) }
assert_equal "invalid locals key: \"ANSWER\" (keys must be variable names)", err.message
+ assert_equal "1 + 2 = 3", inst.render(Object.new, '_answer' => 3)
end
class Person

0 comments on commit 8e513b9

Please sign in to comment.
Something went wrong with that request. Please try again.