Wolfmans Howlings

A programmers Blog about Ruby, Rails and a few other issues

A HAML edit mode for JEdit

Posted by Jim Morris Sat, 02 Dec 2006 02:09:00 GMT

I've just started a new RoR project and thought I'd try out HAML for the views instead of rhtml.

Seeing as I just switched to JEdit, I looked for a HAML language mode, and to my surprise no one had done one yet.

So here is my first attempt at a language mode for JEdit and version 1.0 of the HAML language mode. It needs more work, and I hope someone with a better understanding of JEdit language modes will help out.

This will set the indent to 2 spaces and auto-indent after a %tag that has nothing else on the line...

%p
  stuff

It will not auto indent if there is more stuff on the line like in the following example the line after %p gets indented but the line after %label does not.

 %p
    %label{ :for => "login" }Login
    %br/
    = f.text_field :login

I have setup a basic syntax coloring scheme that should color %tags and .classes and #ids differently. It will color anything following an = or ~ and defer the syntax highlighting to the ruby mode for anything following them, ditto for anything inside { }.

Feedback and better ideas are welcome.

Download from here

To install copy the file to ~/.jedit/modes, and edit the catalog file in that directory and add this line:

<MODE NAME="haml" FILE="haml.xml" FILE_NAME_GLOB="*.haml" />

Then restart jedit, and your haml files will be syntax highlighted.

I like HAML but there simply is not enough example code out there yet, so here are two simple conversions from well know rhtml files into HAML...

First the standard login form from acts_as_authenticated

- form_tag sessions_path do
  %p
    %label{ :for => "login"} Login
    %br/
    = text_field_tag 'login'

  %p
    %label{ :for => "password" }Password
    %br/
    = password_field_tag 'password'

  %p
    %label{ :for => "remember_me" }Remember me:
    = check_box_tag 'remember_me'

  %p
    = submit_tag 'Log in'

Next the new user form from the same place...

= error_messages_for :user

- form_for :user, :url => users_path do |f|
  %p
    %label{ :for => "login" }Login
    %br/
    = f.text_field :login
  %p
    %label{ :for => "email" }Email
    %br/
    = f.text_field :email

  %p
    %label{ :for => "password" }Password
    %br/
    = f.password_field :password

  %p
    %label{ :for => "password_confirmation" } Confirm Password
    %br/
    = f.password_field :password_confirmation

  %p
    = submit_tag 'Sign up'

If this is dumb HAML coding please let me know how to improve it :)

Posted in , ,  | Tags , ,  | 4 comments | no trackbacks

Comments

  1. Frederick said about 1 month later:

    Hey, I've been looking for this. Thanks a lot for sparing me the pain of constructing an edit mode myself. Although I might have some energy to put into helping you improve it in the future. Seeing as I'm stuck with jEdit for some time before I earn enough money to go buy a Mac and use TextMate, I'm happy that at least now it's a bit more bearable.

  2. Xarc said 7 months later:

    haml.xml doesn't exist... 'Page not found'

  3. Xarc said 7 months later:

    Sorry for repeat. i find the correct URL: http://haml.googlegroups.com/web/haml.xml

  4. wolfmanjm said 7 months later:

    Thanks I fixed the link

Trackbacks

Use the following link to trackback from your own site:
http://blog.wolfman.com/articles/trackback/87

(leave url/email »)

   Comment Markup Help Preview comment