VcShortcut - a gem to reduce the verbosity of rendering ViewComponents & Phlex components

It might be subjective, but I’ve always disliked how verbose rendering a view component is. Especially if they’re namespaced under a bunch of modules.

Traditionally, you’d: render :compact) { ... }

With VcShortcut, you can now also do: vc.admin.navbar(style: :compact) { ... }

It should work for both ViewComponents and Phlex components/views out of the box.

It is also highly customizable. You can change the lookup logic if you have a non-standard component setup, change the name of the shortcut.

You can even setup additional custom shortcuts.

For example, in case all your components are namespaced under Primer and have the suffix Component, you can easily set a custom shortcut so that instead of writing render, you can write

All of this (and much more) is documented on the Github repository along with examples.

1 Like