/hobo-serenity

Connecting Hobo with Serenity (testing)

Primary LanguageRubyMIT LicenseMIT

HoboSerenity

This plugin tries to simplify the process of integrating two great gems: Hobo and Serenity-ODT. It also uses a LibreOffice to convert automatically ODT template into PDF file if you want to.

Thanks to:

Requirements

  • Rails >= 2.3.8
  • Hobo >= 1.0.1 gem
  • Serenity-odt gem
  • Git
  • LibreOffice >= version 4

Installation

pre.

  1. For Rails versions < 3
    script/plugin install git://github.com/iox/hobo-serenity.git
  2. For Rails versions >= 3
    Add it to your Gemfile like so: gem ‘hobo-serenity’, :git => ‘https://github.com/iox/hobo-serenity.git
    and the just: bundle install

How to use it

First step, a global variable in config/environment.rb or your static configuration file.
ODT_TEMPLATES_PATH should point to the folder in which your templates reside, for example:

# HoboSerenity configuration options
ODT_TEMPLATES_PATH = 'documents/odt_templates/'

Second step, define the templates and the methods you are going to need. Create your templates accordingly to Serenity needs: checkout examples folder to get a basic idea, or refer to serenity gem to see more detailed syntax examples. Then save them in the folder you have determined in the previous step.
Go to your model and include HoboSerenity:

include HoboSerenity

After that you need to define one more method to instruct Hobo Serenity where to store the final parsed document: it should return the name of the document you are going to create (without .odt or .pdf). For example:

# --- Document creation --- #
def example
  return 'documents/my_documents/DOC-' + id.to_s
end

Third step, add download methods to the controller

# Allow File Downloads
include HoboSerenityController

And finally, add the download buttons to the view and routes. Note that “example” is the template file name, so in this case the template it will be looking for would be “example.odt”:

The view first:

<show-page>
  <append-heading:>
    <a href="&this.odt_download_url('example')" class="button">Download ODT</a>
    <a href="&this.pdf_download_url('example')" class="button">Download PDF</a>
  </append-heading:>
</show-page>

And then the routes:

pre.
get ‘my_model/download_odt/:id’ => ‘my_model#download_odt’
get ‘my_model/download_pdf/:id’ => ‘my_model#download_pdf’

Enjoy!

Copyright © 2016 Ignacio Huerta (http://ihuerta.net), released under the MIT license