Showing posts with label gem. Show all posts
Showing posts with label gem. Show all posts

Sunday, July 31, 2011

Reuse gettext gem to parse .po file

I am working on a translation service which requires translating .po file (ruby gettext gem). Spent hours to understand the rake tasks it provides and looked for methods to extract all String inside .po file. Finally found the parser and the method to do my job:


require 'gettext/tools/poparser'
require 'gettext/tools/rmsgmerge'

parser = GetText::PoParser.new
result = parser.parse_file("...../my_rails_project/po/en/text_domain.po", GetText::RMsgMerge::PoData.new, false)

the object representing the data structure is assigned to result.


In case you are also extending gettext library, check the gettext/tools directory. Most of the useful methods are located there.

Monday, March 14, 2011

uninitialized constant ActiveRecord::TestFixtures

I saw this uninitialized constant ActiveRecord::TestFixtures error when i run the rake test. I have checked all the environment configuration. I am sure i am using Mongoid without ActiveRecord.

after reading the fixture_support.rb source code, I found out that the error is thrown only if ActiveRecord was called somewhere in my code. and it turned out to be caused by the Transition suggested by krzysiek: http://dev.netizer.pl/transitions-state-machine-for-rails-3.html

So, I have to switch the state machine to another gem which is not using ActiveRecord stuff. that's why i found stateflow: https://github.com/ryanza/stateflow

My test can run happily ever after.

Saturday, February 26, 2011

Using Jekyll, Hyde and Heroku for presentation slides

I was sharing architecture of a RU05 program and performance tuning we did on with Mongo.
Codeaholics Feb Meetup


The slides i showed was actually a web page moving like a powerpoint slides.
The source code to generate the slides is available in github.


here I draft out high level steps giving you some rough ideas of the work required to create such webpage. you can find all the detail steps in jekyll, jekyll_and_hyde and rack-jekyll github page.


install required gems and create project:

gem install jekyll
gem install jekyll_and_hyde
gem install rack-jekyll
jh new codeaholics_hk_feb_2011
cd codeaholics_hk_feb_2011

To prepare deployment for the future, generate the static pages into another folder instead of default _site directory. i used "pages" folder in my case:

in the .gems file, include rack-jekyll
follow the github pages to setup _config.yml and config.ru

You can start creating your powerpoint, and read it at localhost:4000

jekyll --server pages
jh generate frontpage
... // generate your static pages
... // keep your jekyll server running until you finish. i explain why below

When you want to deploy to heroku:

git init
git add .
git commit -m ""
heroku create codeaholics_hk_feb_2011
git push heroku master

One issue i saw when generating post was that. I edited my posts markdown files after I stopped the jekyll server, and later when i started it again, no more static pages generated automatically. I guess the service could no longer recognizes which files was edited. I could not resolve this problem. So, i have to create another project and copy over my markdown files to continue.

Friday, February 18, 2011

Overflow / page break examples in Prawn PDF generation

I have been using Prawn for a while. Here I gather several overflow / page break examples.


1. Text paragraph overflow

Having several lines of text and I want whole block of text stick together


Solution is using group to hold them together



2. Table rows overflow

Sometime there is no enough space for the last table row when it reaches the end of page, and Prawn does not move it to next page. That's why we have to manually add a page break:



More code snippets available at https://gist.github.com/3dd13