├── LICENSE ├── README.md └── erb.json /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 Bijan Rahnema 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ruby on Rails Snippets for Zed Editor 2 | 3 | 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. 4 | More snippets will follow. 5 | 6 | https://github.com/user-attachments/assets/51ec5af2-5e63-4bf1-a3d6-45e6bea0d10c 7 | 8 | 9 | ## Installation 10 | 11 | To use these snippets in Zed Editor, follow these steps: 12 | 13 | 1. **Clone the Repository**: 14 | ```bash 15 | git clone https://github.com/gobijan/zed-rails-snippets.git 16 | ``` 17 | 18 | 2. **Copy the Snippet File**: 19 | - Locate the `erb.json` file in the cloned repository. 20 | - Copy this file to Zed's snippet directory: 21 | ```bash 22 | cp erb.json ~/.config/zed/snippets/ 23 | ``` 24 | 25 | 3. **Reload Zed**: 26 | - Restart Zed or reload the snippets as per Zed's documentation to ensure the new snippets are loaded. 27 | 28 | 4. **Verify**: 29 | - Open an ERB file (`.erb` or `.html.erb`) in Zed. 30 | - Type `e` to see the list of available ERB snippets in the autocomplete menu. 31 | 32 | ## Usage 33 | 34 | 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 `<%= %>`. 35 | 36 | ### Snippet Categories 37 | 38 | The snippets are organized into the following categories for easy reference: 39 | 40 | - **Basic ERB** 41 | - `ee`: Expression 42 | - `er`: Statement 43 | - `ec`: Comment 44 | 45 | - **Control Structures** 46 | - `eif`: If Statement 47 | - `eife`: If/Else Statement 48 | - `eeach`: Each Loop 49 | - `esafeeach`: Safe Each Loop 50 | - `efor`: For Loop 51 | - `eun`: Unless 52 | 53 | - **Rendering** 54 | - `erp`: Render Partial 55 | - `erpl`: Render Partial with Locals 56 | - `erc`: Render Collection 57 | 58 | - **Helpers** 59 | - `elt`: Link To 60 | - `eit`: Image Tag 61 | - `efw`: Form With 62 | - `etf`: Text Field 63 | - `eselect`: Select Tag 64 | - `es`: Submit 65 | - `ebt`: Button To 66 | - `ect`: Content Tag 67 | 68 | - **Content Management** 69 | - `ecf`: Content For 70 | - `eyc`: Yield Content 71 | - `ecfi`: Content For If 72 | - `ecfd`: Content For With Default 73 | 74 | ### Snippet Details 75 | 76 | Below is a detailed list of all available snippets, including their prefixes, descriptions, and the code they generate: 77 | 78 | - **ERB Expression** 79 | - **Prefix**: `ee` 80 | - **Description**: Inserts an ERB expression tag for outputting content 81 | - **Code**: `<%= $1 %>` 82 | 83 | - **ERB Statement** 84 | - **Prefix**: `er` 85 | - **Description**: Inserts an ERB statement tag for Ruby code 86 | - **Code**: `<% $1 %>` 87 | 88 | - **ERB Comment** 89 | - **Prefix**: `ec` 90 | - **Description**: Inserts an ERB comment 91 | - **Code**: `<%# $1 %>` 92 | 93 | - **ERB If Statement** 94 | - **Prefix**: `eif` 95 | - **Description**: Inserts an ERB if statement 96 | - **Code**: 97 | ```erb 98 | <% if $1 %> 99 | $2 100 | <% end %> 101 | ``` 102 | 103 | - **ERB If/Else Statement** 104 | - **Prefix**: `eife` 105 | - **Description**: Inserts an ERB if/else statement 106 | - **Code**: 107 | ```erb 108 | <% if $1 %> 109 | $2 110 | <% else %> 111 | $3 112 | <% end %> 113 | ``` 114 | 115 | - **ERB Each Loop** 116 | - **Prefix**: `eeach` 117 | - **Description**: Inserts an ERB each loop for iterating over a collection 118 | - **Code**: 119 | ```erb 120 | <% $1.each do |$2| %> 121 | $3 122 | <% end %> 123 | ``` 124 | 125 | - **ERB Safe Each Loop** 126 | - **Prefix**: `esafeeach` 127 | - **Description**: Inserts an ERB each loop with a presence check 128 | - **Code**: 129 | ```erb 130 | <% if $1.present? %> 131 | <% $1.each do |$2| %> 132 | $3 133 | <% end %> 134 | <% end %> 135 | ``` 136 | 137 | - **ERB For Loop** 138 | - **Prefix**: `efor` 139 | - **Description**: Inserts an ERB for loop 140 | - **Code**: 141 | ```erb 142 | <% for $1 in $2 %> 143 | $3 144 | <% end %> 145 | ``` 146 | 147 | - **ERB Render Partial** 148 | - **Prefix**: `erp` 149 | - **Description**: Renders a partial template 150 | - **Code**: `<%= render partial: "$1" %>` 151 | 152 | - **ERB Render Partial with Locals** 153 | - **Prefix**: `erpl` 154 | - **Description**: Renders a partial with local variables 155 | - **Code**: `<%= render partial: "$1", locals: { $2: $3 } %>` 156 | 157 | - **ERB Render Collection** 158 | - **Prefix**: `erc` 159 | - **Description**: Renders a partial for each item in a collection 160 | - **Code**: `<%= render partial: "$1", collection: $2, as: :$3 %>` 161 | 162 | - **ERB Link To** 163 | - **Prefix**: `elt` 164 | - **Description**: Inserts a Rails link_to helper with optional class 165 | - **Code**: `<%= link_to "$1", $2${3:, class: "$4"} %>` 166 | 167 | - **ERB Image Tag** 168 | - **Prefix**: `eit` 169 | - **Description**: Inserts a Rails image_tag helper with optional alt and class 170 | - **Code**: `<%= image_tag "$1"${2:, alt: "$3", class: "$4"} %>` 171 | 172 | - **ERB Form With** 173 | - **Prefix**: `efw` 174 | - **Description**: Inserts a Rails form_with helper 175 | - **Code**: 176 | ```erb 177 | <%= form_with $1 do |f| %> 178 | $2 179 | <% end %> 180 | ``` 181 | 182 | - **ERB Text Field** 183 | - **Prefix**: `etf` 184 | - **Description**: Inserts a Rails text_field helper with optional placeholder and class 185 | - **Code**: `<%= f.text_field :$1${2:, placeholder: "$3", class: "$4"} %>` 186 | 187 | - **ERB Select Tag** 188 | - **Prefix**: `eselect` 189 | - **Description**: Inserts a Rails select helper with optional blank and class 190 | - **Code**: `<%= f.select :$1, $2${3:, { include_blank: true }, { class: "$4" }} %>` 191 | 192 | - **ERB Submit** 193 | - **Prefix**: `es` 194 | - **Description**: Inserts a Rails submit button with optional class 195 | - **Code**: `<%= f.submit "$1"${2:, class: "$3"} %>` 196 | 197 | - **ERB Button To** 198 | - **Prefix**: `ebt` 199 | - **Description**: Inserts a Rails button_to helper with optional class 200 | - **Code**: `<%= button_to "$1", $2${3:, class: "$4"} %>` 201 | 202 | - **ERB Unless** 203 | - **Prefix**: `eun` 204 | - **Description**: Inserts an ERB unless statement 205 | - **Code**: 206 | ```erb 207 | <% unless $1 %> 208 | $2 209 | <% end %> 210 | ``` 211 | 212 | - **ERB Content Tag** 213 | - **Prefix**: `ect` 214 | - **Description**: Inserts a Rails content_tag helper with optional class 215 | - **Code**: `<%= content_tag :$1, "$2"${3:, class: "$4"} %>` 216 | 217 | - **ERB Content For** 218 | - **Prefix**: `ecf` 219 | - **Description**: Inserts a Rails content_for block 220 | - **Code**: 221 | ```erb 222 | <% content_for :$1 do %> 223 | $2 224 | <% end %> 225 | ``` 226 | 227 | - **ERB Yield Content** 228 | - **Prefix**: `eyc` 229 | - **Description**: Yields content from a content_for block 230 | - **Code**: `<%= yield :$1 %>` 231 | 232 | - **ERB Content For If** 233 | - **Prefix**: `ecfi` 234 | - **Description**: Conditionally yields content with a fallback 235 | - **Code**: 236 | ```erb 237 | <% if content_for?(:$1) %> 238 | <%= yield :$1 %> 239 | <% else %> 240 | $2 241 | <% end %> 242 | ``` 243 | 244 | - **ERB Content For With Default** 245 | - **Prefix**: `ecfd` 246 | - **Description**: Yields content with a default value if absent 247 | - **Code**: `<%= content_for?(:$1) ? yield(:$1) : "$2" %>` 248 | 249 | ## Contributing 250 | 251 | Contributions are welcome! If you have suggestions for new snippets or improvements to existing ones, please follow these steps: 252 | 253 | 1. **Fork the Repository**: 254 | - Click the "Fork" button on the repository page to create your own copy. 255 | 256 | 2. **Make Your Changes**: 257 | - Edit the `erb.json` file to add or modify snippets. 258 | - Ensure that all prefixes start with "e" and are unique. 259 | 260 | 3. **Submit a Pull Request**: 261 | - Push your changes to your forked repository. 262 | - Open a pull request with a clear description of your changes. 263 | 264 | 4. **Review and Merge**: 265 | - Your pull request will be reviewed, and if approved, merged into the main repository. 266 | 267 | Thank you for contributing to making these snippets better for the community! 268 | 269 | ## License 270 | 271 | This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. 272 | -------------------------------------------------------------------------------- /erb.json: -------------------------------------------------------------------------------- 1 | { 2 | "ERB Expression": { 3 | "prefix": "ee", 4 | "body": "<%= $1 %>", 5 | "scope": "erb,html.erb,eruby", 6 | "description": "Inserts an ERB expression tag for outputting content" 7 | }, 8 | "ERB Statement": { 9 | "prefix": "er", 10 | "body": "<% $1 %>", 11 | "scope": "erb,html.erb,eruby", 12 | "description": "Inserts an ERB statement tag for Ruby code" 13 | }, 14 | "ERB Comment": { 15 | "prefix": "ec", 16 | "body": "<%# $1 %>", 17 | "scope": "erb,html.erb,eruby", 18 | "description": "Inserts an ERB comment" 19 | }, 20 | "ERB If Statement": { 21 | "prefix": "eif", 22 | "body": ["<% if $1 %>", " $2", "<% end %>"], 23 | "scope": "erb,html.erb,eruby", 24 | "description": "Inserts an ERB if statement" 25 | }, 26 | "ERB If/Else Statement": { 27 | "prefix": "eife", 28 | "body": ["<% if $1 %>", " $2", "<% else %>", " $3", "<% end %>"], 29 | "scope": "erb,html.erb,eruby", 30 | "description": "Inserts an ERB if/else statement" 31 | }, 32 | "ERB Each Loop": { 33 | "prefix": "eeach", 34 | "body": ["<% $1.each do |$2| %>", " $3", "<% end %>"], 35 | "scope": "erb,html.erb,eruby", 36 | "description": "Inserts an ERB each loop for iterating over a collection" 37 | }, 38 | "ERB Safe Each Loop": { 39 | "prefix": "esafeeach", 40 | "body": [ 41 | "<% if $1.present? %>", 42 | " <% $1.each do |$2| %>", 43 | " $3", 44 | " <% end %>", 45 | "<% end %>" 46 | ], 47 | "scope": "erb,html.erb,eruby", 48 | "description": "Inserts an ERB each loop with a presence check" 49 | }, 50 | "ERB For Loop": { 51 | "prefix": "efor", 52 | "body": ["<% for $1 in $2 %>", " $3", "<% end %>"], 53 | "scope": "erb,html.erb,eruby", 54 | "description": "Inserts an ERB for loop" 55 | }, 56 | "ERB Render Partial": { 57 | "prefix": "erp", 58 | "body": "<%= render partial: \"$1\" %>", 59 | "scope": "erb,html.erb,eruby", 60 | "description": "Renders a partial template" 61 | }, 62 | "ERB Render Partial with Locals": { 63 | "prefix": "erpl", 64 | "body": "<%= render partial: \"$1\", locals: { $2: $3 } %>", 65 | "scope": "erb,html.erb,eruby", 66 | "description": "Renders a partial with local variables" 67 | }, 68 | "ERB Render Collection": { 69 | "prefix": "erc", 70 | "body": "<%= render partial: \"$1\", collection: $2, as: :$3 %>", 71 | "scope": "erb,html.erb,eruby", 72 | "description": "Renders a partial for each item in a collection" 73 | }, 74 | "ERB Link To": { 75 | "prefix": "elt", 76 | "body": "<%= link_to \"$1\", $2${3:, class: \"$4\"} %>", 77 | "scope": "erb,html.erb,eruby", 78 | "description": "Inserts a Rails link_to helper with optional class" 79 | }, 80 | "ERB Image Tag": { 81 | "prefix": "eit", 82 | "body": "<%= image_tag \"$1\"${2:, alt: \"$3\", class: \"$4\"} %>", 83 | "scope": "erb,html.erb,eruby", 84 | "description": "Inserts a Rails image_tag helper with optional alt and class" 85 | }, 86 | "ERB Form With": { 87 | "prefix": "efw", 88 | "body": ["<%= form_with $1 do |f| %>", " $2", "<% end %>"], 89 | "scope": "erb,html.erb,eruby", 90 | "description": "Inserts a Rails form_with helper" 91 | }, 92 | "ERB Text Field": { 93 | "prefix": "etf", 94 | "body": "<%= f.text_field :$1${2:, placeholder: \"$3\", class: \"$4\"} %>", 95 | "scope": "erb,html.erb,eruby", 96 | "description": "Inserts a Rails text_field helper with optional placeholder and class" 97 | }, 98 | "ERB Select Tag": { 99 | "prefix": "eselect", 100 | "body": "<%= f.select :$1, $2${3:, { include_blank: true }, { class: \"$4\" }} %>", 101 | "scope": "erb,html.erb,eruby", 102 | "description": "Inserts a Rails select helper with optional blank and class" 103 | }, 104 | "ERB Submit": { 105 | "prefix": "es", 106 | "body": "<%= f.submit \"$1\"${2:, class: \"$3\"} %>", 107 | "scope": "erb,html.erb,eruby", 108 | "description": "Inserts a Rails submit button with optional class" 109 | }, 110 | "ERB Button To": { 111 | "prefix": "ebt", 112 | "body": "<%= button_to \"$1\", $2${3:, class: \"$4\"} %>", 113 | "scope": "erb,html.erb,eruby", 114 | "description": "Inserts a Rails button_to helper with optional class" 115 | }, 116 | "ERB Unless": { 117 | "prefix": "eun", 118 | "body": ["<% unless $1 %>", " $2", "<% end %>"], 119 | "scope": "erb,html.erb,eruby", 120 | "description": "Inserts an ERB unless statement" 121 | }, 122 | "ERB Content Tag": { 123 | "prefix": "ect", 124 | "body": "<%= content_tag :$1, \"$2\"${3:, class: \"$4\"} %>", 125 | "scope": "erb,html.erb,eruby", 126 | "description": "Inserts a Rails content_tag helper with optional class" 127 | }, 128 | "ERB Content For": { 129 | "prefix": "ecf", 130 | "body": ["<% content_for :$1 do %>", " $2", "<% end %>"], 131 | "scope": "erb,html.erb,eruby", 132 | "description": "Inserts a Rails content_for block" 133 | }, 134 | "ERB Yield Content": { 135 | "prefix": "eyc", 136 | "body": "<%= yield :$1 %>", 137 | "scope": "erb,html.erb,eruby", 138 | "description": "Yields content from a content_for block" 139 | }, 140 | "ERB Content For If": { 141 | "prefix": "ecfi", 142 | "body": [ 143 | "<% if content_for?(:$1) %>", 144 | " <%= yield :$1 %>", 145 | "<% else %>", 146 | " $2", 147 | "<% end %>" 148 | ], 149 | "scope": "erb,html.erb,eruby", 150 | "description": "Conditionally yields content with a fallback" 151 | }, 152 | "ERB Content For With Default": { 153 | "prefix": "ecfd", 154 | "body": "<%= content_for?(:$1) ? yield(:$1) : \"$2\" %>", 155 | "scope": "erb,html.erb,eruby", 156 | "description": "Yields content with a default value if absent" 157 | } 158 | } 159 | --------------------------------------------------------------------------------