Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/progrhyme/ruby-align

Code Alignment Tool for Ruby
https://github.com/progrhyme/ruby-align

Last synced: 18 days ago
JSON representation

Code Alignment Tool for Ruby

Awesome Lists containing this project

README

        

# ruby-align [![Build Status](https://travis-ci.org/key-amb/ruby-align.svg?branch=master)](https://travis-ci.org/key-amb/ruby-align)

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:

```ruby
## 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`.

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

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](https://github.com/key-amb/ruby-align/issues)
in this project.

# LICENSE

The MIT License (MIT)

Copyright (c) 2016 IKEDA Kiyoshi