This repository contains a collection of snippets for the Zed Editor, designed to enhance productivity when working with Ruby on Rails projects. The ERB snippets cover a wide range of common ERB patterns, including control structures, Rails helpers, and content management, making it easier to write clean and efficient ERB code. More snippets will follow.
zed-erb-snippets.mp4
To use these snippets in Zed Editor, follow these steps:
-
Clone the Repository:
git clone https://github.com/gobijan/zed-rails-snippets.git
-
Copy the Snippet File:
- Locate the
erb.json
file in the cloned repository. - Copy this file to Zed's snippet directory:
cp erb.json ~/.config/zed/snippets/
- Locate the
-
Reload Zed:
- Restart Zed or reload the snippets as per Zed's documentation to ensure the new snippets are loaded.
-
Verify:
- Open an ERB file (
.erb
or.html.erb
) in Zed. - Type
e
to see the list of available ERB snippets in the autocomplete menu.
- Open an ERB file (
Once installed, these snippets can be triggered by typing their respective prefixes in an ERB file. For example, typing ee
and pressing Tab will insert an ERB expression tag <%= %>
.
The snippets are organized into the following categories for easy reference:
-
Basic ERB
ee
: Expressioner
: Statementec
: Comment
-
Control Structures
eif
: If Statementeife
: If/Else Statementeeach
: Each Loopesafeeach
: Safe Each Loopefor
: For Loopeun
: Unless
-
Rendering
erp
: Render Partialerpl
: Render Partial with Localserc
: Render Collection
-
Helpers
elt
: Link Toeit
: Image Tagefw
: Form Withetf
: Text Fieldeselect
: Select Tages
: Submitebt
: Button Toect
: Content Tag
-
Content Management
ecf
: Content Foreyc
: Yield Contentecfi
: Content For Ifecfd
: Content For With Default
Below is a detailed list of all available snippets, including their prefixes, descriptions, and the code they generate:
-
ERB Expression
- Prefix:
ee
- Description: Inserts an ERB expression tag for outputting content
- Code:
<%= $1 %>
- Prefix:
-
ERB Statement
- Prefix:
er
- Description: Inserts an ERB statement tag for Ruby code
- Code:
<% $1 %>
- Prefix:
-
ERB Comment
- Prefix:
ec
- Description: Inserts an ERB comment
- Code:
<%# $1 %>
- Prefix:
-
ERB If Statement
- Prefix:
eif
- Description: Inserts an ERB if statement
- Code:
<% if $1 %> $2 <% end %>
- Prefix:
-
ERB If/Else Statement
- Prefix:
eife
- Description: Inserts an ERB if/else statement
- Code:
<% if $1 %> $2 <% else %> $3 <% end %>
- Prefix:
-
ERB Each Loop
- Prefix:
eeach
- Description: Inserts an ERB each loop for iterating over a collection
- Code:
<% $1.each do |$2| %> $3 <% end %>
- Prefix:
-
ERB Safe Each Loop
- Prefix:
esafeeach
- Description: Inserts an ERB each loop with a presence check
- Code:
<% if $1.present? %> <% $1.each do |$2| %> $3 <% end %> <% end %>
- Prefix:
-
ERB For Loop
- Prefix:
efor
- Description: Inserts an ERB for loop
- Code:
<% for $1 in $2 %> $3 <% end %>
- Prefix:
-
ERB Render Partial
- Prefix:
erp
- Description: Renders a partial template
- Code:
<%= render partial: "$1" %>
- Prefix:
-
ERB Render Partial with Locals
- Prefix:
erpl
- Description: Renders a partial with local variables
- Code:
<%= render partial: "$1", locals: { $2: $3 } %>
- Prefix:
-
ERB Render Collection
- Prefix:
erc
- Description: Renders a partial for each item in a collection
- Code:
<%= render partial: "$1", collection: $2, as: :$3 %>
- Prefix:
-
ERB Link To
- Prefix:
elt
- Description: Inserts a Rails link_to helper with optional class
- Code:
<%= link_to "$1", $2${3:, class: "$4"} %>
- Prefix:
-
ERB Image Tag
- Prefix:
eit
- Description: Inserts a Rails image_tag helper with optional alt and class
- Code:
<%= image_tag "$1"${2:, alt: "$3", class: "$4"} %>
- Prefix:
-
ERB Form With
- Prefix:
efw
- Description: Inserts a Rails form_with helper
- Code:
<%= form_with $1 do |f| %> $2 <% end %>
- Prefix:
-
ERB Text Field
- Prefix:
etf
- Description: Inserts a Rails text_field helper with optional placeholder and class
- Code:
<%= f.text_field :$1${2:, placeholder: "$3", class: "$4"} %>
- Prefix:
-
ERB Select Tag
- Prefix:
eselect
- Description: Inserts a Rails select helper with optional blank and class
- Code:
<%= f.select :$1, $2${3:, { include_blank: true }, { class: "$4" }} %>
- Prefix:
-
ERB Submit
- Prefix:
es
- Description: Inserts a Rails submit button with optional class
- Code:
<%= f.submit "$1"${2:, class: "$3"} %>
- Prefix:
-
ERB Button To
- Prefix:
ebt
- Description: Inserts a Rails button_to helper with optional class
- Code:
<%= button_to "$1", $2${3:, class: "$4"} %>
- Prefix:
-
ERB Unless
- Prefix:
eun
- Description: Inserts an ERB unless statement
- Code:
<% unless $1 %> $2 <% end %>
- Prefix:
-
ERB Content Tag
- Prefix:
ect
- Description: Inserts a Rails content_tag helper with optional class
- Code:
<%= content_tag :$1, "$2"${3:, class: "$4"} %>
- Prefix:
-
ERB Content For
- Prefix:
ecf
- Description: Inserts a Rails content_for block
- Code:
<% content_for :$1 do %> $2 <% end %>
- Prefix:
-
ERB Yield Content
- Prefix:
eyc
- Description: Yields content from a content_for block
- Code:
<%= yield :$1 %>
- Prefix:
-
ERB Content For If
- Prefix:
ecfi
- Description: Conditionally yields content with a fallback
- Code:
<% if content_for?(:$1) %> <%= yield :$1 %> <% else %> $2 <% end %>
- Prefix:
-
ERB Content For With Default
- Prefix:
ecfd
- Description: Yields content with a default value if absent
- Code:
<%= content_for?(:$1) ? yield(:$1) : "$2" %>
- Prefix:
Contributions are welcome! If you have suggestions for new snippets or improvements to existing ones, please follow these steps:
-
Fork the Repository:
- Click the "Fork" button on the repository page to create your own copy.
-
Make Your Changes:
- Edit the
erb.json
file to add or modify snippets. - Ensure that all prefixes start with "e" and are unique.
- Edit the
-
Submit a Pull Request:
- Push your changes to your forked repository.
- Open a pull request with a clear description of your changes.
-
Review and Merge:
- Your pull request will be reviewed, and if approved, merged into the main repository.
Thank you for contributing to making these snippets better for the community!
This project is licensed under the MIT License. See the LICENSE file for details.