Skip to content

Commit

Permalink
Compiler: add support for #emit with template (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
noteflakes committed May 9, 2024
1 parent 0847c68 commit 1e31e90
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/papercraft/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def render_emit_call(o, *a, **b, &block)
case o
when nil
# do nothing
when Papercraft::Template
o.render(*a, **b, &block)
when ::Proc
Papercraft.html(&o).render(*a, **b, &block)
else
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/compiler/emit_template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>foo</p><p>42</p><br/><q>bar</q>
3 changes: 3 additions & 0 deletions test/fixtures/compiler/emit_template_compiled.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
->(__buffer__) {
__buffer__ << "#{Papercraft.render_emit_call(pr1)}#{Papercraft.render_emit_call(pr2, 42)}<br/>#{Papercraft.render_emit_call(Papercraft.html { q 'bar' })}"
}
9 changes: 9 additions & 0 deletions test/fixtures/compiler/emit_template_source.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pr1 = Papercraft.html { p 'foo' }
pr2 = Papercraft.html { |x| p x }

->() {
emit pr1
emit pr2, 42
br
emit Papercraft.html { q 'bar' }
}

0 comments on commit 1e31e90

Please sign in to comment.