ddengler / prawn-grouping

A gem to add a more flexible grouping option to the prawn gem
https://github.com/ddengler/prawn-grouping
MIT License
14 stars 21 forks source link

yield instead of instance_exec #16

Closed doits closed 8 years ago

doits commented 9 years ago

Allows the block to be run in the context it was defined. Block parameter is now mandatory.

Simple example in Rails view:

# I want to group this:
pdf.text t('some.translation')
pdf.text 'some other text'

# --> I can simply wrap it around now
pdf.group.do |g|
   g.text t('some.translation')
   g.text 'some other text'
end

Without this PR, t is not defined because it does not exist in the changed context. It had to be done like this:

translation = t('some.translation')
group.do |g|
   g.text translation
   g.text 'some other text'
end

This can get really messy if you want to group more complex things.

With this PR, the context is not changed anymore.

Only downside: The block parameter is mandatory, not only in jruby. But IMO the context should not be changed because it complicates things more than it solves (only benefit: the optional block parameter).

ddengler commented 8 years ago

Late but still: I am currently updating the project and I integrated your changes to yield alongside some other updates. Will release the next version of prawn grouping with it.