Correct, the line offset thing is gone. So I'd recommend you wrap your
block "pdf.instance_eval { ... }" so the line numbers are correct.On Mon, Dec 15, 2008 at 12:49 PM, thorny_sun <[email protected]> wrote: > > I get it-- perfect-- thanks! > > another minor question: It seems you prefer to have the source > surrounding the "template.source" be separated by semicolons rather > than newlines? I see you've also gotten rid of the line count > property. I assume that is to keep things simple and bug reported > line numbers accurate? But what if there is an issue with the first > line number-- wouldn't that come back with a lot of extra stuff (in my > case the surrounding code is very long and would come back with a very > uselessly long string) -- or am I missing something again? > > -thorny_sun > > On Dec 15, 10:42 am, "Joshua Peek" <[email protected]> wrote: >> This should work: >> >> "pdf = Prawn::Document.new; pdf.instance_eval do\n#{template.source}\nend" >> >> This string will get eval'd into a method. Big difference between it >> actually running. AV will create something like this for you: >> >> def _pdf_app_views_docs_show >> pdf = Prawn::Document.new >> pdf.instance_eval do >> # the actual template source will be here >> text "Hello, World" >> end >> end >> >> >> >> On Mon, Dec 15, 2008 at 5:45 AM, thorny_sun <[email protected]> wrote: >> >> > Josh, >> >> > ah ok-- I get it now -- thanks so much for helping me understand! >> >> > follow up question: I also have an option where the user can specify >> > a template to be run as if it were inside a pdf.instance_eval where >> > pdf is just the Prawn::Document object. This makes the template more >> > compact, since the user avoids having to type "pdf." all the time. >> > (i.e. "pdf = Prawn::Document.new; pdf.instance_eval template.source;") >> > Soooo-- I'm assuming that having the "pdf.instance_eval" in the eval'd >> > string kinda defeats the benefits of using compile? Could I get >> > around this by mimicking the compile paradigm and creating a method >> > and calling that method within the string to be eval'd? >> >> > thanks so much for the help! >> > -thorny_sun >> >> > On Dec 11, 10:36 am, Joshua Peek <[email protected]> wrote: >> >> On Dec 11, 8:46 am, thorny_sun <[email protected]> wrote: >> >> >> > so are you saying now that ruby source is somehow getting run faster >> >> > since it is getting "compiled". I'm very confused. What if we take >> >> > the builder template as an example (since prawnto template handler >> >> > works very similarly in that it is just ruby code) -- is there any >> >> > speed gain expected by "compiling" it? Or did I just misunderstand? >> >> >> In most cases, you going to have to compile it no matter what. In your >> >> prawnto template handler you directly call `[email protected]_eval >> >> source, template.filename, 1`. While this works, you are rebuilding >> >> and reevaling the template ever run. This is really slow. You could >> >> make this optimizations internally, but ActionView can take care of >> >> all this for you if you just return the source from the handler >> >> instead. >> >> -- >> Joshua Peek > > > -- Joshua Peek --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
