Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Ruby, Rails and RHTML snippets for the gedit Snippets plugin

tree: 541c609e63

Fetching latest commit…

Cannot retrieve the latest commit at this time

README.textile

gedit-snippets

Ruby, Rails and RHTML snippets for the gedit Snippets plugin

This is a collection of code snippets that I am using in my favorite editor, gedit.

Please also check out my blog post on this.

Install

The snippets are meant to replace those that come bundled with the Snippets plugin entirely, as some of them use the same keywords and will make a popup-select window appear if you do not remove the default ones.

On a default install, the snippets will be stored in /usr/share/gedit-2/plugins/snippets/ruby.xml, so to remove them, do a

sudo rm /usr/share/gedit-2/plugins/snippets/ruby.xml

After that, you can either put all the xml files from the snippets/ directory in this package into mentioned directory, or store them in your home directory in ~/.gnome2/gedit/snippets, which probably is the preferred option.

After putting the files into one of these directories, they should become available automatically when editing .rb files.

If you want to automate the download, you can execute the following command, which will retrieve the latest revision from github as a tarball and extract it into the snippets directory in your home:

wget -nv http://github.com/colszowka/gedit-snippets/tarball/master -O- | tar xzv -C ~/.gnome2/gedit/ --strip 1

For automatic updates, you might want to put this into a cron job

Documentation

If you want an overview of all snippets available, have a look into the cheatsheet

There is a script supplied in the doc/ directory which will generate this cheatsheet based upon the current snippets files. If you want to roll your own, simply do ruby doc/create_documentation.rb. Please remember though that you will need to have the following gems installed: xmlsimple, coderay, haml

Demonstration

Included snippets

Currently, there are following snippet packages:

  • Rails Activerecord Associations
  • Rails Activerecord Basic
  • Rails Activerecord Validations
  • Rails Controllers Basic
  • Rhtml Basic
  • Rhtml Forms
  • Rhtml Html
  • Rhtml Ruby
  • Ruby Basic
  • Ruby Collections
  • Snippet Tools

Known Issues

Unfortunately, the Snippets plugin is entirely based upon mime types, so there is no way of making, i.e., ActiveRecord validation snippets only available in Rails models based upon path.

The effect of this is that you will have all snips defined for Ruby files available in every .rb-file you are editing, even if the inclusion doesn’t make sense at all in this particular file. My apologies for that!

I once mailed the author of the plugin, "Jesse van den Kieboom ":http://www.icecrew.nl/~jesse/, about that issue, but unfortunately he does not work on the plugin any more. If anyone is into Python, a path-based snippet enabler patch for the plugin would be greatly appreciated!

Style guide

This is a rough list of rules that I use when updating the snips.

1. Multi-word method or symbol names are abbreviated with the first letter of each word

Examples:


validates_presence_of => vpo
:wrong_length => wl

2. Single-word method or symbol names are not abbreviated

3. For block methods, the original method name is to be used for the {} form, while an appended “o” behind the method name stands for the mulit-line do..end style

Examples:

each {|item| puts item} => each
each do |item|
  ...
end => eacho

4. The description should feature a short form of the included code as well as an optional comment, maybe even from an official RDoc document.

Copyright

gedit-snippets is Copyright © 2009 Christoph Olszowka , It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.

accessories-text-editor icon used in gnome-snippets-logo taken from the Tango project, licensed under the Creative Commons Attribution Share-Alike license. gnome-snippets-logo licensed under Creative Commons Attribution Share-Alike license

CodeRay coloring theme for cheatsheet by Ryan Bates

Something went wrong with that request. Please try again.