Using Haml Views

20 Jun 2011

Haml is a markup language that’s used to cleanly and simply describe the HTML of any web document without the use of inline code. Haml functions as a replacement for inline page templating systems such as PHP, ASP, and ERB, the templating language used in most Ruby on Rails applications. However, Haml avoids the need for explicitly coding HTML into the template, because it itself is a description of the HTML, with some code to generate dynamic content.

you can install haml in two ways

  1. install from rubygem repository
gem install haml
  1. install from source
git clone git://github.com/nex3/haml.git
cd haml
rake install

If you prefer installing via bundle, append this line in your Gemfile.

gem 'haml'
# if rails
gem 'haml-rails'

After adding this code to your Gemfile just run “bundle install”. Haml gem give us a full freedom to convert html or erb files to haml, for that you can use

html2haml "html_path"

To achive this we have to install two more dependent gems. i prefer you to use that gems in development mode if you are using bundler.

# If you are installing gem directly use the following
gem install hpricot
gem install ruby_parse

# Otherwise if you are using bundler add following lines to your Gemfile
group :developement do
  gem 'hpricot'
  gem 'ruby_parser'
end

Here is small code snippet which will help you to create a new haml from your erb files and delete the existing erb file in your rails application.

# Will create a new haml file from your existing erb file.
for i in `find app/views -name '*.erb'` ; do html2haml -e $i ${i%erb}haml ;  done

# Will delete your existing erb file.
for i in `find app/views/devise -name '*.erb'` ; do rm $i ; done

Install ImageMagick from source

05 Jan 2011

Lets start install ImageMagick 6.6.6-10 on Ubuntu 10.4 LTS

First remove existing version of ImageMagick if it was already installed.

sudo apt-get remove imagemagick

Update your machine with required application dependencies

sudo apt-get update
sudo apt-get install libperl-dev gcc libjpeg62-dev libbz2-dev libtiff4-dev libwmf-dev libz-dev libpng12-dev libx11-dev libxt-dev libxext-dev libxml2-dev libfreetype6-dev liblcms1-dev libexif-dev perl libjasper-dev libltdl3-dev graphviz gs-gpl pkg-config

Get your latest source ImageMagick.tar.gz or select your download from Archive Download using

wget ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick.tar.gz

extract source from tar using

tar -xzf ImageMagick.tar.gz
cd ImageMagick-6.5.0-0

Just configure, compile, make and install using

./configure
make
sudo make install

Now image magick got installed in your ubuntu box, but you are need to add the following lines to ~/.bashrc

export LD_LIBRARY_PATH=/usr/local/lib

ImageMagick installation is now completed lets check them,

convert --version

The above comand will respond you

Version: ImageMagick 6.6.2-6 2010-12-02 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2010 ImageMagick Studio LLC
Features: OpenMP

Install Rails 3 on Ubuntu 10.4

20 Nov 2010

Lets install Rails 3 stable on ubuntu 10.4. I am going to use Ruby 1.9.2 with Ruby Version Manager and Ubuntu 10.4 32 bit version

Initially, install the necessary tools for our installation

sudo apt-get install gcc g++ build-essential libssl-dev libreadline5-dev zlib1g-dev linux-headers-generic libsqlite3-dev

Install Ruby 1.9.2 from Ruby version Manager (RVM). Official Rvm references available at here. Make sure that curl and git installed (from above).

bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )

After installing Rvm for the first time in your machine, you must write the following script in your profile page at very end after the load path.

[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"

After adding the above lines in to the profile, you have to make some more changes in Ubuntu.

[ -z "$PS1" ] && return

You need to replace the above statement with if and indent code stated below till rvm loads script and add fi to the end of if statement. After the changes, your code will look like

if [[ -n "$PS1" ]]; then
# Existing code here...
fi
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Loads RVM into terminal.

we can make sure that the rvm is installed successfully on our machine by using the following command in the new terminal

$ type rvm | head -n1

if your rvm installed properly, you will get response as,

rvm is a function

Now we have successfully installed our RVM. Next we have to install Ruby 1.9.2. Just enter the below code in you terminal.

$ rvm install 1.9.2

IIt will take several minutes to install in your machine. After it has been installed we have to make Ruby 1.9.2 as default ruby version on to our machine.The following code will help you to achieve that

$ rvm --default 1.9.2

you can test your ruby version by

$ ruby -v
ruby 1.9.2p0 (2010-08-18 revision 29036) [i686-linux]

Lets install Rails 3, simply typing following command in your terminal

gem install rails

make sure rails 3 is installed

rails -v

After installing rails we have to install sqllite3, to install use following lines on your terminal

sudo apt-get install sqlite3 libsqlite3-dev

Lets finally install sqllite gem by using

sudo gem install sqlite3-ruby

Now all your dependecies for installing rails3 are completed, create your “hello world” project and run it.