Sinatra render a ruby file -
how render ruby file (which in case returns pdf document) example:
"/pdf" @locals = {some_locals_hash} headers({'content-type' => 'application/pdf', 'content-description' => 'file transfer', 'content-transfer-encoding' => 'binary', 'content-disposition' => "attachment;filename=\"test.pdf\"", 'expires' => '0', 'pragma' => 'public'}) ruby :test, :layout => false, :locals => @locals end
i know tilt not have ruby template. put content in *.haml
file like:
-# pdf file description :ruby pdf = prawn::document.new( ... docs settings) ... docs content end = pdf.render()
and render haml :template ...etc...
truth is, need syntax highlighting, editor not highlight embedded ruby code in haml files :(. if it's complicated don't bother...
i managed tilt template
module tilt class rubytemplate < template def prepare end def evaluate(scope, locals, &block) super(scope, locals, &block) end def precompiled_template(locals) data.to_str end end register 'rb', rubytemplate end
and helper method
helpers def ruby(*args) render(:rb, *args) end end
i't sure best way, @ least working :)
Comments
Post a Comment