Code Alignment Tool for Ruby
Ruby Shell
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
bin
lib
script
spec
tmp
.gitignore
.rspec
.ruby-align.toml
.ruby-version
.travis.yml
CHANGELOG.md
Gemfile
Gemfile.lock
LICENSE
README.md
Rakefile

README.md

ruby-align Build Status

A code formatter for Ruby to make alignment.

Usage

ruby-align your_program.rb
ruby-align --[f]ile=your_program.rb

Or it can receive input from STDIN and output formatted code.

How this works?

This script provides functionality of aligning code elements such as variable assignments or hash declarations.

Here's an example:

## before
a = 1
dddd ||= (1..3)
bb -= 20
e = { foo: 1, bar: 'Bar' }

stash = {
  foo: 123,
  'bar' => 'Bar',
  "bazz" => %w[ x y z ]
}

## after
a      = 1
dddd ||= (1..3)
bb    -= 20
e      = { foo: 1, bar: 'Bar' }

stash = {
  foo:      123,
  'bar'  => 'Bar',
  "bazz" => %w[ x y z ]
}

If you are curious, you can see formatting examples under spec/ directory. In spec/subjects/ directory, there are some unformatted code snippets. And formatted results of them are in spec/expects/ directory.

Call ruby-align in Text Editors

Because I am a vimmer, here is only example of .vimrc.

" == ruby-align ==
" set your favorite leader key
let mapleader = ","
noremap <Leader>ra <Esc>:%! /path/to/ruby-align<Return>
noremap <Leader>rav <Esc>:'<,'>! /path/to/ruby-align<Return>

If you add this into your .vimrc, you can call ruby-align to whole your buffer by typing ,ra. Or you can partially apply it by ,rav for selected area in visual mode.

Settings for other editors are welcome.

CAUTION

This program might have bugs.
Please take a backup before you apply this to your code.

For known issues, see the issue list in this project.

LICENSE

The MIT License (MIT)

Copyright (c) 2016 IKEDA Kiyoshi