Project

dinbrief

0.01
No commit activity in last 3 years
No release in over 3 years
DIN Brief gem for Prawn. Creating letters that confirm to the DIN 5008 specifications.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

= 1.0.0.rc1
 Project Readme

DIN Brief gem for prawn.

Mission Objective

This gem tries to make producing letters from Ruby apps simpler. The resulting letter mostly meet the DIN 5008 standard.

It is (mainly) a semantic DSL on top of Prawn 1.x.

The name dinbrief was chosen as a tribute to the dinbrief LaTeX package, which it replaces in my projects.

Example

To get the headers and footers right for your company, you should subclass Dinbrief::Letter:

  class MyLetter < Dinbrief::Letter
    # define a header
    def header
      image(File.join("my_logo_.png"),
        :at => [0.mm, 35.mm],
        :fit => [80.mm, 22.mm]
      )
      text_box(%{My Company
        Some Road 23
        12345 Rubycity

        www.my-company.com
      },
        :at => [105.mm, 35.mm],
        :width => 85.mm,
        :align => :left,
        :size => 10.pt
      )
    end

    # define a footer
    def footer
      text_box(%{My Company Ltd. – Some Road 23 – 12345 Rubycity
        more infos as requred by law
      },
        :at => [20.mm, 12.mm],
        :width => 140.mm,
        :align => :center,
        :size => 8.pt,
      )
    end
  end

(Note: If you don’t implement these functions you’ll get some sample header and footer with additional information.)

Then, you can use this class to actually typeset your letters:

  MyLetter.letter('more_serious.pdf') do |db|
    db.return_address 'metaminded UG – Ulmer Straße 176 – 73233 Aalen'
    db.oursign        "PH"
    db.yoursign       "DHH"
    db.yourmessage    "24.12.2011"
    db.name           "Dr. Peter Horn"
    db.phone          "05604 - 919937"
    db.fax            "05604 - 919938"
    db.email          "ph@metaminded.com"
    db.address        "David Heinemeier-Hansson\n37signals, LLC\n30 North Racine Avenue #200\nChicago, Illinois 60607\nUSA"
    db.subject        "Thanks a lot for giving us Rails"
    db.body <<-TEXT
      Dear David and all you colleagues,

      Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

      ...

      Curabitur ullamcorper ultricies nisi. Nam eget dui.

      Best Regards,
    TEXT
  end

But, as always, things may be more complicated, and you may want to add fancy pdf things or generate the letter (from, e.g., an order object), so you can give a block to the body:

  MyLetter.letter('more_serious.pdf') do |db|
    db.return_address 'metaminded UG – Ulmer Straße 176 – 73233 Aalen'
    # ... as above ...
    db.subject        "Thanks a lot for giving us Rails"
    db.body do |letter|
      letter.text %{Dear David and all you colleagues,

        Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

        To impress people, I add a useless table:
        }

      letter.table [["Animal", "Programming Language", "coincidence"],
        ["Penguin",  "C",      "213" ],
        ["Platypus", "ObjC",   "143" ],
        ["Cat",      "Ruby",   "47"  ],
        ["Dog",      "Python", "23"  ],
        ["Olm",      "PHP",    "876" ]
      ]

      letter.text %{
        Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum.

        Curabitur ullamcorper ultricies nisi. Nam eget dui.

        Best Regards,
      }

      letter.image("signature.png", :fit => [3.cm, 3.cm])
    end
  end

The result then looks a little bit like this:

If you’re unhappy with the default info block, you may call info giving either a string:

  MyLetter.letter('more_serious.pdf') do |db|
    db.return_address 'metaminded UG – Ulmer Straße 176 – 73233 Aalen'
    db.subject        "Thanks a lot for giving us Rails"
    db.info           "Thing: something\nStuff: somestuff"
    ...

or – even more advanced – a block as with the body method:

  MyLetter.letter('more_serious.pdf') do |db|
    db.return_address 'metaminded UG – Ulmer Straße 176 – 73233 Aalen'
    db.subject        "Thanks a lot for giving us Rails"
    db.info do |box|
      4.times do |i|
        box.text "Line #{i}", size: 10.pt
      end
    end
    ...

inside the block, you may use virtually every prawn method. If info is given, all other info-methods (as yourmessage, oursign and the like) are disabled.

Almost every property (positions, sizes, fontsizes, …) of an element is defined in lib/dinbrief/letter/constants.rb, and can be overridden in your subclass.

Disclaimer

This is pretty much work-in-progress-without-reasonable-documentation. So if you use it, don’t complain ;)

Nevertheless, bug reports and improvements are highly appreciated:

Contributing to dinbrief

  • Check out the latest master to make sure the feature hasn’t been implemented or the bug hasn’t been fixed yet
  • Check out the issue tracker to make sure someone already hasn’t requested it and/or contributed it
  • Fork the project
  • Start a feature/bugfix branch
  • Commit and push until you are happy with your contribution
  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
  • Feel free to send a pull request if you think others (me, for example) would like to have your change incorporated into future versions of dinbrief.

License

Copyright © 2011-2012 Peter Horn, metaminded UG

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.