page as block?

0 views
Skip to first unread message

runs_with_kona

unread,
Jul 6, 2009, 2:39:31 PM7/6/09
to Prawn
Is there a way to do something like,

page1 = new_page(options) {|page|
content...
}


If some_condition
pdf.render page1
else
pdf.render page2
end

Gregory Brown

unread,
Jul 6, 2009, 3:04:06 PM7/6/09
to prawn...@googlegroups.com


Sure.

page1 = lambda { |pdf|
# ...
}

if some_condition
page1[pdf]
else
#...
end

You can also use ordinary methods for this.


A pattern I like to use is:

class MyDocument < Prawn::Document

# whatever helpers

end

MyDocument.generate("foo.pdf") { |pdf| ... }

Reply all
Reply to author
Forward
0 new messages