Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement the fix the grid may be redefined in a document #492

Closed
bwl21 opened this issue May 20, 2013 · 4 comments
Closed

implement the fix the grid may be redefined in a document #492

bwl21 opened this issue May 20, 2013 · 4 comments

Comments

@bwl21
Copy link

bwl21 commented May 20, 2013

The hint in https://groups.google.com/forum/?fromgroups#!topic/prawn-ruby/nYfR9EBvygk should be implmentd.

I have created an application to show calendars. This is based on grid, and expected that I can redefine the grid within a Document.boundingbox.

In my application I have added:

module Prawn
  class Document

    # Defines the grid system for a particular document.  Takes the number of
    # rows and columns and the width to use for the gutter as the
    # keys :rows, :columns, :gutter, :row_gutter, :column_gutter
    #
    def define_grid(options = {})
      @grid = Grid.new(self, options)
      @boxes = nil  # see https://groups.google.com/forum/?fromgroups#!topic/prawn-ruby/nYfR9EBvygk
    end
  end
end

This allows to redefine the grid. Could this be part of the official Prawn.

@traels
Copy link

traels commented Feb 7, 2014

1 vote for merging this into Prawn - or update the manual to tell that grid is per document.
I wasted 2 hours of my life before finding this - thank you for showing me a fix @bwl21 :)

@practicingruby
Copy link
Member

@traels:

I am not super familiar with the grid code, but having it be global is definitely weird when most things in Prawn can be nested relative to a bounding box.

If you want to work on a patch or update the documentation, it'd certainly be welcome. Please submit a pull request, and let me know if you need help figuring out how to implement it!

@traels
Copy link

traels commented Feb 7, 2014

The update bwl21 has posted sort of makes sense - I have just implemented in my app. I can't really see that applying that fix should break anything.

As far as I can see the problem is somewhere around https://github.com/prawnpdf/prawn/blob/stable/lib/prawn/layout/grid.rb#L20 which could be a performance thing but has the drawback that the boxes are not rewritten when a new grid is defined.

I'll try to update the manual to say that grid is defined per document.

@practicingruby
Copy link
Member

What we have here isn't a patch, it's just showing a line of code we could change if we wanted to prepare a patch. It has no tests or examples, and so it's not in a reviewable state. If we simply changed this line in Prawn, nothing would stop us from breaking it or misunderstanding the intention in a future release.

A pull request with tests and a clear example, and any necessary documentation updates is definitely worth reviewing though!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants