railshero
railshero

Reputation: 163

How can i set syntax highlight in gedit for html.erb file as ruby file?

How can i set syntax highlight in gedit for html.erb file as ruby file?

I tried these, doesn't work. Syntax highlighting in gedit not working automatically

Upvotes: 7

Views: 4967

Answers (5)

maikel
maikel

Reputation: 1779

If you use Debian then there is a package for the needed MIME types and syntax files: https://github.com/mkllnk/gedit-rails-extensions/releases

The package might also work with other Debian based distributions like Ubuntu. The contained files work in general with gedit and are system independend. They are similar to the files mentioned in other posts. But for newer Gnome versions the .lang files have to be in a newer directory:

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

If you use Ubuntu and want more features than highlighting then GMate is supposed to be very good.

Upvotes: 1

Bernard Banta
Bernard Banta

Reputation: 755

Oh! I got the solution.

You need to install Gmate in Ubuntu. GMate is a collection of plugins, themes/styles and other improvements to get TextMate-like features in Gedit. Type the following commands to install Gmate.

sudo apt-add-repository ppa:ubuntu-on-rails/ppa
sudo apt-get update
sudo apt-get install gedit-gmate

When you are finished open your a .html.erb and voila! there it is.

More info visit https://github.com/gmate/gmate#readme

Upvotes: 13

magicbacon
magicbacon

Reputation: 331

You can manually change the highlighting preference from the drop-list on the status bar. If gedit can't recognize the file type, it assumes "plain text" by default.

I think I found a good solution: http://www.webupd8.org/2010/12/get-textmate-features-and-styles-in.html

Upvotes: 1

htanata
htanata

Reputation: 36944

This method works for me. It's taken from this article. Unfortunately the commands showed there doesn't work because the files that we're supposed to download are not available. So here are the modified steps including the content of the files.

Create or override the file /usr/share/gtksourceview-2.0/language-specs/rhtml.lang with the following content:

<?xml version="1.0" encoding="UTF-8"?>
<language id="rhtml" _name="RHTML" version="2.0" _section="Markup">
  <metadata>
    <property name="mimetypes">text/rhtml</property>
    <property name="globs">*.rhtml</property>
  </metadata>
  <definitions>
    <context id="erb-block">
      <start>&lt;%</start>
      <end>%&gt;</end>
      <include>
        <context ref="ruby:ruby:*"/>
      </include>
    </context>
    <context id="rhtml">
      <include>
        <context ref="html:html"/>
        <context ref="erb-block"/>
      </include>
    </context>
  </definitions>
</language>

And also create or override the file /usr/share/mime/packages/rails.xml with the following content:

<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
  <mime-type type="text/rhtml">
    <sub-class-of type="text/html"/>
    <comment>RHTML Template</comment>
    <glob pattern="*.rhtml"/>
    <glob pattern="*.erb"/>
  </mime-type>
  <mime-type type="application/x-ruby">
    <comment>Ruby JavaScript</comment>
    <glob pattern="*.rjs"/>
  </mime-type>
  <mime-type type="application/x-ruby">
    <comment>Ruby Rakefile</comment>
    <glob pattern="Rakefile"/>
  </mime-type>
  <mime-type type="application/x-ruby">
    <comment>Ruby Rake Task</comment>
    <glob pattern="*.rake"/>
  </mime-type>
  <mime-type type="application/x-ruby">
    <comment>Ruby XML Template</comment>
    <glob pattern="*.rxml"/>
    <glob pattern="*.builder"/>
  </mime-type>
  <mime-type type="text/x-yaml">
    <comment>YAML Ain't Markup Language</comment>
    <glob pattern="*.yml"/>
  </mime-type>
</mime-info>

Then run sudo update-mime-database /usr/share/mime.

Upvotes: 2

ankit
ankit

Reputation: 3358

You can change the highlighting preference from the drop-down list on the status bar. See if there is an option for RHTML present. If there isn't, you can follow this post to install it in: here. That's what I did, it works for me.

Upvotes: 2

Related Questions