• Stars
    star
    140
  • Rank 261,473 (Top 6 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 2 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Format ERB files with speed and precision

ERB::Formatter 🪜

Format ERB files with speed and precision.

Features:

  • very fast
  • attempts to limit length (configurable)
  • tries to have an output similar to prettier for HTML
  • indents correctly ruby blocks (e.g. if/elsif/do/end)
  • designed to be integrated into editors and commit hooks
  • gives meaningful output in case of errors (most of the time)
  • will use multiline values for class and data-action attributes

Roadmap:

  • extensive unit testing
  • more configuration options
  • more ruby reformatting capabilities
  • JavaScript and CSS formatting
  • VSCode plugin
  • fix spaces after attribute equal signs instead of complaining

Installation

Add this line to your application's Gemfile:

$ bundle add erb-formatter

Or install it yourself as:

$ gem install erb-formatter

Usage

From Visual Studio Code

Just install the Ruby ERB::Formatter 🪜 extension and follow the setup instructions there.

From the command line

Update files in-place:

$ erb-format app/views/**/*.html.erb --write

or use stdin/stdout (useful for editor integrations):

$ echo "<div       > asdf  <% if 123%> <%='foobar'%> <%end-%>  </div>" | erb-format --stdin
<div>
  asdf
  <% if 123 %>
    <%= 'foobar' %>
  <% end -%>
</div>

Check out erb-format --help for more options.

From Ruby

require 'erb/formatter'

formatted = ERB::Formatter.format <<-ERB
<div        >
            asdf
                  <% if 123%>
                      <%='foobar'%> <%end-%>
           </div>
ERB

# => "<div>\n  asdf\n  <% if 123 %>\n    <%= 'foobar' %>\n  <% end -%>\n</div>\n"
#
# Same as:
#
#   <div>
#     asdf
#     <% if 123 %>
#       <%= 'foobar' %>
#     <% end -%>
#   </div>

With lint-staged

Add the gem to your gemfile and the following to your package.json:

"lint-staged": {
  // …
  "*.html.erb": "bundle exec erb-format --write"
}

As a TextMate command

Create a command with the following settings:

  • Scope selector: text.html.erb
  • Semantic class: callback.document.will-save
  • Input: document → text
  • Output: replace document → text
  • Caret placement: line-interpolation
#!/usr/bin/env bash

cd "$TM_PROJECT_DIRECTORY"
bundle exec erb-format --stdin-filename "$TM_FILEPATH" < /dev/stdin 2> /dev/stdout

With (Neo)VIM ALE

Enable erb-formatter as a fixer in the ALE config:

let g:ale_fixers = {
\   'eruby': ['erb-formatter'],
\}

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.

In order to run a specific test, use the following command:

m test/erb/test_formatter.rb:123

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/nebulab/erb-formatter.

License

The gem is available as open source under the terms of the MIT License.

More Repositories

1

simple_command

A simple, standardized way to build and use Service Objects (aka Commands) in Ruby
Ruby
617
star
2

pulsar

Manage your Capistrano deployments with ease
Ruby
129
star
3

cangaroo

Connect Any App to Any Service
Ruby
107
star
4

spree-subscriptions

Spree extension to handle subscriptions
Ruby
86
star
5

reverse_coverage

A tool to find the test examples which cover a specific line (or set of lines) of a Ruby project
JavaScript
78
star
6

omnes

Pub/Sub for Ruby
Ruby
58
star
7

playbook

📖 We are Nebulab, and this is how we work.
SCSS
53
star
8

prependers

Easily and cleanly extend third-party code.
Ruby
27
star
9

spree-one-page-checkout

Source code for One Page Checkout blog post
Ruby
24
star
10

runtime_config

A runtime configuration tool for Rails 5
Ruby
23
star
11

rails_console_toolkit

Configurable Rails Console Helpers
Ruby
20
star
12

umarell

All in one Ruby static code analyzer
Ruby
18
star
13

spree-ember-example

The example repository that goes with http://nebulab.it/blog/using-ember-js-with-spree/
Ruby
17
star
14

multitenant_shop

Solidus eCommerce with multitenancy
Ruby
11
star
15

spree-garbage-cleaner

A little gem that helps you cleanup old, unneeded data from a Spree database.
Ruby
11
star
16

erb-formatter-vscode

VSCode extension for ERB::Formatter (Format ERB files with speed and precision)
JavaScript
9
star
17

indago

Lightweight drop-in Ransack replacement without the ActiveRecord hackery.
Ruby
7
star
18

dev_tools

Contains useful gems to be used in development
Ruby
7
star
19

spree_return_authorizations_frontend

Adds a frontend interface to allow user to ask for items returns
Ruby
7
star
20

rails-vuejs-jsx

Products catalog Rails application moved to VueJS and JSX
Ruby
7
star
21

spree_simple_reports

JavaScript
6
star
22

dru

DRU - Docker-Compose Run Utility
Ruby
6
star
23

moonshine

Moonshine is a configuration driven method chain builder.
Ruby
5
star
24

cypress-store

An example of integrating Cypress with Rails.
Ruby
5
star
25

spree_ember_one_page_checkout

An ember.js application to add a one page checkout to Spree.
CoffeeScript
5
star
26

erb-linter

Check your ERB files for closing tags, indentation, bad attributes etc.
Ruby
5
star
27

renderful

A Ruby rendering engine for headless CMSs, with support for caching and Ruby on Rails.
Ruby
5
star
28

spree_order_constraints

A simple way to change the behaviour of checkout_allowed? to add some constraints to your customers as they proceed to checkout
Ruby
5
star
29

spree_exclusive_products

It filters variants depending on user roles
Ruby
5
star
30

solidus_shipwire

solidus and shipwire connect manager
Ruby
5
star
31

solidus_page_objects

An extension that adds site_prism page objects for common Solidus views
Ruby
4
star
32

solidus_client

Solidus eCommerce API Ruby client
Ruby
4
star
33

spree_one_page_add_to_cart

Spree one page add to cart for fast checkout
Ruby
4
star
34

soliton

An Ember application to search for Solidus extensions on GitHub
JavaScript
4
star
35

solidus_nextjs_frontend

JavaScript
4
star
36

baywatch

Rescue projects before they sink: easy 1-container feature branch previews with Docker
Dockerfile
4
star
37

spree-api-client.js

JavaScript
4
star
38

minitest-shopify

Ruby
4
star
39

wombat_migration

Useful to share info about how to migrate wombat
3
star
40

bretelline

Nebulab's Rails (and Solidus) application template.
Ruby
3
star
41

create-hydrogen

JavaScript
2
star
42

workflow

A repo useful to simulate a basic features management workflow
2
star
43

spree_line_item_discount

Adds the ability to create a different discount in percentage for each item in the cart with the same coupon code
Ruby
2
star
44

spree_multiple_notifications

Ruby
2
star
45

nebulab.github.io

The Nebulab website
HTML
2
star
46

easy_maintenance

Easy maintenance page for your apps
Ruby
2
star
47

klarna_proxy

Ruby Klarna proxy gem that consumes the Klarna APIs: https://developers.klarna.com/api/
Ruby
2
star
48

rails-sales-taxes-kata

One of the exercises used in our internal academy.
2
star
49

solidus_bot

A simple chatbot which search products on a solidus store
Ruby
1
star
50

spree_social_promotions

Ruby
1
star
51

products_feed

Easy products feed generator
Ruby
1
star
52

solidus_product_uploads

Ruby
1
star
53

circleci-orbs-stoplight

📜 An Orb for linking your Git repository to a Stoplight project.
1
star
54

docker-preview-server

Chef cookbooks to spin up a docker preview server.
Ruby
1
star
55

helen

Helen - Office Automation
1
star
56

heroku-ruby-docker

A docker image to mimic Heroku Ruby environment
Dockerfile
1
star
57

solidus_frontend_examples

Example custom frontend applications built on Solidus's GraphQL API
JavaScript
1
star
58

spree_allow_shipping_methods

Ruby
1
star
59

html5-boilerplate-stasis

JavaScript
1
star
60

backport

Manage your backported code with ease.
Ruby
1
star
61

segmentation

The missing SDK for integrating Segment in your Ruby on Rails application.
Ruby
1
star
62

pulsar-conf-demo

Example of pulsar-conf repository
Ruby
1
star
63

spree-invite-a-friend-example

Ruby
1
star
64

circleci-orbs-feature-branch-preview

👓 An Orb to preview PRs on a specific server using Docker
1
star
65

products_catalog

Simple app Rails APIs with VueJS JSX for the Ruby day Workshop
Ruby
1
star
66

cangaroo_tutorial

Example application on how to setup Cangaroo to tweet every time a new product is created
Ruby
1
star
67

darkstore

Darkstore API gem
Ruby
1
star
68

solidus-on-heroku

Deploy your solidus app on heroku like a boss
Ruby
1
star
69

aws-solidus-demo-opsworks_cookbook

Chef 13 cookbook with Opsworks and NodeJS for AWS Rails deployment
Ruby
1
star