Skip to content

Commit

Permalink
HTML-41 Don't print the output of variable assigns to the IO
Browse files Browse the repository at this point in the history
  • Loading branch information
sbsoftware committed Jan 24, 2025
1 parent 83a7a87 commit 5ca4669
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
27 changes: 27 additions & 0 deletions spec/instance_template/variable_assigns_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require "../spec_helper"

module ToHtml::InstanceTemplate::VariableAssignsSpec
class MyView
def something_expensive
["expensive", "strings"]
end

ToHtml.instance_template do
tmp = something_expensive
tmp.each do |item|
div { item }
end
end
end

describe "MyView#to_html" do
it "should not render the variable assignment" do
expected = <<-HTML.squish
<div>expensive</div>
<div>strings</div>
HTML

MyView.new.to_html.should eq(expected)
end
end
end
3 changes: 3 additions & 0 deletions src/instance_template.cr
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ module ToHtml
{% end %}
{% end %}
end
{% elsif blk.body.is_a?(Assign) %}
# Don't print this to the IO
{{blk.body}}
{% elsif blk.body.is_a?(Yield) %}
yield {{io}}, {{indent_level}}
{% elsif blk.body.is_a?(Nop) %}
Expand Down

0 comments on commit 5ca4669

Please sign in to comment.