Skip to content

Commit

Permalink
Compiler: add support for inline array, numbered param (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
noteflakes committed Apr 21, 2024
1 parent 746dd3d commit eb44226
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
14 changes: 14 additions & 0 deletions lib/papercraft/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,29 @@ class Sirop::Sourcifier
# self: :emit_verbatim
# })

def emit_nothing(node)
# emit nothing
end

def visit_self_node(node)
emit_verbatim(node)
end

def visit_numbered_parameters_node(node)
emit_nothing(node)
end

def visit_hash_node(node)
emit_code(node.opening_loc)
visit_comma_separated_nodes(node.elements)
emit_code(node.closing_loc)
end

def visit_array_node(node)
emit_code(node.opening_loc)
visit_comma_separated_nodes(node.elements)
emit_code(node.closing_loc)
end
end

class Papercraft::Compiler < Sirop::Sourcifier
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/iteration.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<p>1</p><p>2</p><p>3</p><p>4</p>
<p>1</p><p>2</p><p>3</p><p>4</p><q>5</q><q>6</q><q>7</q><q>8</q>
4 changes: 4 additions & 0 deletions test/fixtures/iteration_compiled.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@
items.each { |i|
__buffer__ << "<p>#{CGI.escapeHTML((i).to_s)}</p>"
}

[5, 6, 7, 8].each {
__buffer__ << "<q>#{CGI.escapeHTML((_1).to_s)}</q>"
}
}
4 changes: 4 additions & 0 deletions test/fixtures/iteration_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@
items.each { |i|
p i
}

[5, 6, 7, 8].each {
q _1
}
}

0 comments on commit eb44226

Please sign in to comment.