GithubHelp home page GithubHelp logo

jtreitz / prawn-grouping Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ddengler/prawn-grouping

0.0 0.0 0.0 35 KB

A gem to add a more flexible grouping option to the prawn gem

Home Page: https://github.com/ddengler/prawn-grouping

License: MIT License

Ruby 100.00%

prawn-grouping's Introduction

Prawn::Grouping

Gem Version Build Status Code Climate

An experimental gem to add a more flexible grouping option to the excellent prawn gem.

Installation

Add this line to your application's Gemfile:

gem 'prawn-grouping'

And then execute:

$ bundle

Or install it yourself as:

$ gem install prawn-grouping

Usage

Grouping

Prawn::Document.new do
  20.times { text "Regular text" }
  group do |g|
    20.times { g.text "Paragraphs not separated unless necessary" }
  end
end

Nested Groups

Prawn::Document.new do
  5.times { text "Regular text" }
  group do |g|
    15.times { g.text "Paragraphs not separated unless necessary" }
    group do |g|
      30.times { g.text "Subparagraphs not separated unless necessary" }
    end
  end
end

Do not overuse nesting because a every combination has to be tested recursively in a temporary document

Options

Currently three callbacks are supported:

  • :fits_current_context A proc called before the content is rendered and does fit context.
  • :fits_new_context A proc called before the content is rendered and does fit a single context.
  • :too_tall A proc called before the content is rendered and does not fit a single context.
Prawn::Document.new do
  5.times { text "Regular text" }

  group :too_tall => lambda { start_new_page } do |g|
    15.times { g.text "Paragraphs not separated unless necessary" }
  end
end

The example above starts a new page if the content is too tall for a single page. Default behavior would be to just append the content.

Troubleshooting

Manipulating objects within the group block

The grouping internally works by executing the block one or multiple times and checking the results, because deep copy did not work well for the original implementation in many cases. As a result you should not manipulate your data objects within the block. See issue #7 for details.

Contributing

  1. Fork it ( http://github.com//prawn-grouping/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

prawn-grouping's People

Contributors

ddengler avatar jeppester avatar petergoldstein avatar tomciopp avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.