Syntax Highlighting for rhtml and erb with gedit

I like to use gedit for coding with ruby on rails and it features syntax highlighting for ruby and html but unfortunately not for rhtml and erb files.

So in this article I will show you how to get syntax highlighting for .rhtml and .erb files within the gedit editor as shown here.

Gedit Screen Shot with syntax highlighting

Gedit uses the GTK toolkit, which in turn has a configuration for language parsing and highlighting. The syntax files delivered with Ubuntu reside under

/usr/share/gtksourceview-3.0/language-specs/

and the files can be extended or overruled by installing new files in your home directory under

~/.local/share/gtksourceview-3.0/language-specs/

This is a safer place for your changed files as the /user/share path might be changed with upgrades.

I have created based on the html.lang file an rhtml.lang file, which you find below.

So here are the two steps what you need to do:

First, create the following directory

Second, downdload this file and copy it into the just created directory.

If you now restart gedit and load a file with the .rhtml and .erb ending you should see a result similar to the example above.

Installing Rails Version 2.3.11

I have just recently re-installed rails, mysql and mongrel in an older version 2.3.11 and its required libraries and tools on 3 computers. As not all instructions I found in the web did work for me here is my learned procedure to get up and running on Linux Ubuntu 12.04.

Installing ruby

[bash]sudo apt-get install ruby rubygems[/bash]

To get access to the ruby documentation and to enable “./script/console” you have to install ri and interactive ruby.

[bash]sudo apt-get install ri irb[/bash]

Installing rails

As Rails version 3 caused some problems for me and some of my aps are not yet ported to Rails 3, I explicitly installed v2.3.8.

[bash]sudo gem install rails -v 2.3.11 -V[/bash]

I prefer to use the verbose option “-V” as the installation is sometimes just sitting around seemingly not responding anymore. In verbose mode however after a few seconds you should see what URLs are queried. So give it some time and be patient.

Installing MySQL

[bash]sudo apt-get install mysql-server mysql-client
sudo apt-get install libmysql-ruby libmysqlclient-dev
sudo apt-get install ruby1.8-dev
sudo gem install mysql [/bash]

Preparing the environment

Ok, the previous steps installed some gems but the executables are not yet accessible. So we have to add their path to our shell.

For this we first check where the binaries were installed, just call:

[bash]gem env[/bash]

Which provides the following output on my computer.

[bash]RubyGems Environment:
– RUBYGEMS VERSION: 1.3.5
– RUBY VERSION: 1.8.7 (2009-06-12 patchlevel 174) [i486-linux]
– INSTALLATION DIRECTORY: /var/lib/gems/1.8
– RUBY EXECUTABLE: /usr/bin/ruby1.8
– EXECUTABLE DIRECTORY: /var/lib/gems/1.8/bin
– RUBYGEMS PLATFORMS:
– ruby
– x86-linux
– GEM PATHS:
– /var/lib/gems/1.8
– /home/georg/.gem/ruby/1.8
– GEM CONFIGURATION:
– :update_sources => true
– :verbose => true
– :benchmark => false
– :backtrace => false
– :bulk_threshold => 1000
– REMOTE SOURCES:
– http://gems.rubyforge.org/ [/bash]

We then take the executable path and add it to our shells path.

[bash]cd ~
gedit .bashrc [/bash]

And in the just opened editor we add the following lines and save the file again.

[bash]# Ruby environment
export PATH=${PATH}:/var/lib/gems/1.8/bin [/bash]

Calling the “which” command should then produce the following output, given your gems path is identical to mine.

[bash]which ruby gem rails rake mongrel_rails
/usr/bin/ruby
/usr/bin/gem
/var/lib/gems/1.8/bin/rails
/var/lib/gems/1.8/bin/rake
/var/lib/gems/1.8/bin/mongrel_rails
[/bash]

Remaining is now the installation of helpful tools and helpers such as the mongrel application server, SSL- or the debugging support.

[bash]sudo gem install mongrel ruby-debug log4r
sudo apt-get install libopenssl-ruby[/bash]