![Maven Central Adds Sigstore Signature Validation](https://cdn.sanity.io/images/cgdhsj6q/production/7da3bc8a946cfb5df15d7fcf49767faedc72b483-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
= clamsy
Ruby wrapper for generating a single pdf for multiple contexts from an odt template.
== 1. Basics
A template odt is just an ordinary odt (http://en.wikipedia.org/wiki/OpenDocument). In order for it to function as a template, we just need to decorate it (just use openoffice, pls don't buy ms office for that) with placeholders & embedded ruby code.
Under the hood, clamsy is using a slightly hacked version of the awesome tenjin template engine (http://www.kuwata-lab.com/tenjin) to do the rendering. The following is all u need to know to write odt templates:
== 2. Examples
=== 2.1. Text Replacement Example
Template Odt:
${@company_full_name} ${@company_address_line_1} ${@company_address_line_2}
S/N Item Description Amount (SGD) {? @items.each_with_index do |item, i| ?} ${i+1} ${item.description} ${amount} {? end ?} Total ${total} ----------------------------------- Page 1 -
Code:
class Item attr_reader :description, :amount def initialize(description, amount) @description, @amount = description, amount end end
items = [ Item.new('Shells (x2 Bags)', 10), Item.new('Clams (x2 Bags)', 20) ]
context = { :company_full_name => 'Monster Inc', :company_address_line_1 => 'Planet Mars, Street xyz,', :company_address_line_2 => 'Postal Code 009900', :items => items, :total => items.inject(0) {|sum, item| sum + item.amount } }
Clamsy.process( context, path_to_template_odt, # eg. '/tmp/invoice.odt' path_to_final_pdf, # eg. '/tmp/invoice.pdf' )
Generated Pdf:
Monster Inc Planet Mars, Street xyz, Postal Code 009900
S/N Item Description Amount (SGD)
1 Shells (x2 Bags) 10 2 Clams (x2 Bags) 20
Total 30
----------------------------------- Page 1 -
=== 2.2: Multiple Contexts Example
Taking the above example one step further, if we have multiple contexts:
items << Item.new('Shrimps (x2 Bags)', 15) items << Item.new('Prawns (x2 Bags)', 25)
contexts = [{ :company_full_name => 'Monster Inc', :company_address_line_1 => 'Planet Mars, Street xyz,', :company_address_line_2 => 'Postal Code 009900', :items => items[0..1], :total => items[0..1].inject(0) {|sum, item| sum + item.amount } }, { :company_full_name => 'Fisherman Inc', :company_address_line_1 => 'Planet Jupiter, Street xyz,', :company_address_line_2 => 'Postal Code 008800', :items => items[2..3], :total => items[2..3].inject(0) {|sum, item| sum + item.amount } }]
Clamsy.process( contexts, path_to_template_odt, # eg. '/tmp/invoice.odt' path_to_final_pdf # eg. '/tmp/invoice.pdf' )
Generated Pdf:
Monster Inc Planet Mars, Street xyz, Postal Code 009900
S/N Item Description Amount (SGD)
1 Shells (x2 Bags) 10 2 Clams (x2 Bags) 20
Total 30
Fisherman Inc Planet Jupiter, Street xyz, Postal Code 008800
S/N Item Description Amount (SGD)
1 Shrimps (x2 Bags) 15 2 Prawns (x2 Bags) 25
Total 40
----------------------------------- Page 1 -
As you can see, (whether you like it or not) the pages are merely concatenated together to form a single pdf !!
=== 2.3: Image Replacement Example
It is possible to replace images in an odt file, a useful feature if u need to insert digital signature into the final pdf. To acheive this, u have to:
Template Odt:
~~~~~~~~~~~~~~~~~~
Hey | nice_guy_image |
~~~~~~~~~~~~~~~~~~
This is a gentle reminder that i still
owe you some money ...
~~~~~~~~~~~~~~~~~~~~~~
| my_signature_image |
~~~~~~~~~~~~~~~~~~~~~~
----------------------------------- Page 1 -
Assuming 'nice_guy_image' & 'my_signature_image' as names of the images, the following code does the appropriate replacing of images:
Clamsy.process( context = {:_pictures => { :nice_guy_image => path_to_avatar_image, # eg. '/tmp/handsome.png' :my_signature_image => path_to_signature_image # eg. '/tmp/signature.png' }}, path_to_template_odt # eg. '/tmp/confession.odt' path_to_final_pdf # eg. '/tmp/confession.pdf' )
== 3. Configuration
(see http://wiki.github.com/ngty/clamsy/configuration)
== 4. Pre-requisites
== TODO
== Note on Patches/Pull Requests
== Contacts
Written 2010 by:
Released under the MIT license
FAQs
Unknown package
We found that clamsy demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.