rails-frontend-cli 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/USER_MANUAL.md ADDED
@@ -0,0 +1,502 @@
1
+ # Rails Frontend CLI - User Manual
2
+
3
+ **English** | [Türkçe](KULLANIM_KILAVUZU.md)
4
+
5
+ A CLI tool that makes frontend development with Rails incredibly easy, allowing you to enjoy Rails frontend coding without needing to know Ruby or Rails.
6
+
7
+ ## Rails Frontend Coding Tutorial
8
+
9
+ 📚 [Training material](https://gamma.app/docs/Frontend-Coding-Training-with-Rails-thatg6lvcpx4g7l) (English)
10
+
11
+ ### Installation
12
+
13
+ ```bash
14
+ gem install rails-frontend-cli
15
+ ```
16
+
17
+ ### Uninstallation
18
+
19
+ ```bash
20
+ gem uninstall rails-frontend-cli
21
+ ```
22
+
23
+ ### Test Installation
24
+
25
+ ```bash
26
+ # For version information:
27
+ rails-frontend --version
28
+ ```
29
+
30
+ ## Usage
31
+
32
+ ### Creating a New Project
33
+
34
+ ```bash
35
+ # Clean frontend project (recommended)
36
+ # Unnecessary files for frontend won't be created
37
+ rails-frontend new blog --clean
38
+ cd blog
39
+ rails-frontend run
40
+
41
+ # Standard project
42
+ rails-frontend new blog
43
+ cd blog
44
+ rails-frontend run
45
+ ```
46
+
47
+ Open `http://localhost:3000` in your browser.
48
+
49
+ ### `--clean` Parameter
50
+
51
+ When a project is created with the `--clean` parameter, unnecessary Rails features for frontend development are removed:
52
+
53
+ **Skipped Features:**
54
+ - Test files (`--skip-test`, `--skip-system-test`)
55
+ - Action Mailer (`--skip-action-mailer`)
56
+ - Action Mailbox (`--skip-action-mailbox`)
57
+ - Action Text (`--skip-action-text`)
58
+ - Active Job (`--skip-active-job`)
59
+ - Action Cable (`--skip-action-cable`)
60
+ - Action Storage (`--skip-active-storage`)
61
+ - Active Record (`--skip-active-record`)
62
+ - ...
63
+
64
+ **Deleted Files and Folders:**
65
+ - `app/mailers/`
66
+ - `app/jobs/`
67
+ - `app/models`
68
+ - `test/`
69
+ - `app/channels/`
70
+ - `config/cable.yml`, `config/queue.yml`, `config/recurring.yml`
71
+ - `db/queue_schema.rb`, `db/cable_schema.rb`
72
+ - `bin/jobs`
73
+ - `.kamal`
74
+
75
+ ### Adding a New Page
76
+
77
+ While inside an existing Rails project:
78
+
79
+ ```bash
80
+ rails-frontend add-page PAGE_NAME
81
+ ```
82
+
83
+ **Examples:**
84
+ ```bash
85
+ cd blog
86
+ rails-frontend add-page about
87
+ rails-frontend add-page contact
88
+ rails-frontend add-page products
89
+ ```
90
+
91
+ Automatically created for each page:
92
+ - View (`app/views/home/PAGE_NAME.html.erb`) - in home folder
93
+ - CSS file (`app/assets/stylesheets/PAGE_NAME.css`)
94
+ - Action added to Home controller
95
+ - Route (`/PAGE_NAME` -> `home#PAGE_NAME`)
96
+
97
+ ### Starting the Server
98
+
99
+ ```bash
100
+ rails-frontend run
101
+ ```
102
+
103
+ This command starts the Rails server by running the `bin/dev` file.
104
+
105
+ ### Building a Static Site
106
+
107
+ ```bash
108
+ rails-frontend build
109
+ # or short name
110
+ rails-frontend b
111
+ ```
112
+
113
+ **How it Works:**
114
+ 1. Checks if Rails server is running
115
+ 2. Cleans and prepares the `build/` folder if it exists
116
+ 3. Creates `build/assets/{img,js,css,fonts}` folders
117
+ 4. Organizes all files (images, js, css, fonts)
118
+ 5. Fixes paths in HTML and CSS files
119
+ 6. Cleans HTML files (csrf, index.html links)
120
+
121
+ **Important:** Rails server must be running before executing this command!
122
+
123
+ **Example Usage:**
124
+ ```bash
125
+ # Terminal 1 - Start server
126
+ rails-frontend run
127
+
128
+ # Terminal 2 - Create build
129
+ rails-frontend build
130
+
131
+ # Test build folder
132
+ cd build && python3 -m http.server or npx http-server
133
+ ```
134
+
135
+ **Generated Folder Structure:**
136
+ ```
137
+ build/
138
+ ├── assets/
139
+ │ ├── img/ # All image files
140
+ │ ├── js/ # All JavaScript files
141
+ │ ├── css/ # All CSS files
142
+ │ └── fonts/ # All font files
143
+ └── *.html # HTML pages
144
+ ```
145
+
146
+ ### Removing a Page
147
+
148
+ ```bash
149
+ rails-frontend remove-page PAGE_NAME
150
+ ```
151
+
152
+ **Example:**
153
+ ```bash
154
+ rails-frontend remove-page contact
155
+ ```
156
+
157
+ **Note:** The home page (home/index) cannot be deleted.
158
+
159
+ ### Adding a Stimulus Controller
160
+
161
+ ```bash
162
+ rails-frontend add-stimulus CONTROLLER_NAME
163
+ ```
164
+
165
+ **Examples:**
166
+ ```bash
167
+ cd blog
168
+ rails-frontend add-stimulus dropdown
169
+ rails-frontend add-stimulus modal
170
+ rails-frontend add-stimulus tabs
171
+ ```
172
+
173
+ This command automatically creates:
174
+ - Stimulus controller (`app/javascript/controllers/CONTROLLER_NAME_controller.js`)
175
+ - Turkish characters are normalized
176
+
177
+ ### Removing a Stimulus Controller
178
+
179
+ ```bash
180
+ rails-frontend remove-stimulus CONTROLLER_NAME
181
+ ```
182
+
183
+ **Examples:**
184
+ ```bash
185
+ rails-frontend remove-stimulus dropdown
186
+ rails-frontend remove-stimulus modal
187
+ ```
188
+
189
+ **Important:** Before deletion, this command:
190
+ 1. Checks if the controller file exists
191
+ 2. Checks usage in all HTML files under `app/views`
192
+ 3. Lists files where the controller is used
193
+ 4. Asks for user confirmation
194
+
195
+ **Example Output:**
196
+ ```
197
+ WARNING: This controller is being used in the following files:
198
+ - app/views/home/index.html.erb
199
+ - app/views/home/products.html.erb
200
+
201
+ Do you still want to delete it? (y/n):
202
+ ```
203
+
204
+ ### Adding a Layout
205
+
206
+ ```bash
207
+ rails-frontend add-layout LAYOUT_NAME
208
+ ```
209
+
210
+ **Examples:**
211
+ ```bash
212
+ cd blog
213
+ rails-frontend add-layout contact
214
+ ```
215
+
216
+ **How it Works:**
217
+ 1. Searches for a view file matching the layout name
218
+ 2. If a matching view exists, automatically creates the layout file
219
+ 3. If no matching view exists, asks the user which view to use
220
+ 4. Checks for existing layout for the same view
221
+ 5. Creates layout file (`app/views/layouts/`)
222
+ 6. Adds layout assignment to `home_controller.rb`
223
+
224
+ ### Removing a Layout
225
+
226
+ ```bash
227
+ rails-frontend remove-layout LAYOUT_NAME
228
+ ```
229
+
230
+ **Examples:**
231
+ ```bash
232
+ rails-frontend remove-layout contact
233
+ ```
234
+
235
+ **Important:** Before deletion, this command:
236
+ 1. Checks if the layout file exists
237
+ 2. Asks for user confirmation
238
+ 3. Removes layout assignment from controller
239
+ 4. Deletes the layout file
240
+
241
+ ### Adding a JavaScript Library
242
+
243
+ ```bash
244
+ rails-frontend add-pin PACKAGE_NAME
245
+ ```
246
+
247
+ **Examples:**
248
+ ```bash
249
+ cd blog
250
+ rails-frontend add-pin alpinejs
251
+ rails-frontend add-pin sweetalert2
252
+ rails-frontend add-pin chart.js
253
+ ```
254
+
255
+ **How it Works:**
256
+ 1. Package is found from jspm and added to `config/importmap.rb`
257
+ 2. If successful, reminds user to import
258
+
259
+ **Important:** Don't forget to import in your JavaScript file after adding a pin:
260
+ ```javascript
261
+ // app/javascript/application.js
262
+ import Swal from "sweetalert2"
263
+ ```
264
+
265
+ ### Removing a JavaScript Library
266
+
267
+ ```bash
268
+ rails-frontend remove-pin PACKAGE_NAME
269
+ ```
270
+
271
+ **Examples:**
272
+ ```bash
273
+ rails-frontend remove-pin alpinejs
274
+ rails-frontend remove-pin sweetalert2
275
+ ```
276
+
277
+ **Important:** Before deletion, this command:
278
+ 1. Checks usage in JavaScript files (`app/javascript/**/*.js`)
279
+ 2. Checks usage in HTML files (`app/views/**/*.html.erb`)
280
+ 3. Checks if pin exists in `config/importmap.rb`
281
+ 4. Shows warning and asks for confirmation if in use
282
+
283
+ ## Project Structure
284
+
285
+ Newly created projects have the following structure:
286
+
287
+ ```
288
+ project_name/
289
+ ├── app/
290
+ │ ├── controllers/
291
+ │ │ └── home_controller.rb (all actions here)
292
+ │ ├── views/
293
+ │ │ ├── home/
294
+ │ │ │ ├── index.html.erb
295
+ │ │ │ ├── about.html.erb
296
+ │ │ │ └── contact.html.erb
297
+ │ │ ├── shared/
298
+ │ │ │ ├── _header.html.erb
299
+ │ │ │ ├── _navbar.html.erb
300
+ │ │ │ └── _footer.html.erb
301
+ │ │ └── layouts/
302
+ │ │ └── application.html.erb (updated)
303
+ │ ├── assets/
304
+ │ │ ├── stylesheets/
305
+ │ │ │ ├── application.tailwind.css
306
+ │ │ │ ├── home.css
307
+ │ │ │ ├── header.css
308
+ │ │ │ ├── navbar.css
309
+ │ │ │ └── footer.css
310
+ │ │ ├── images/
311
+ │ │ └── fonts/
312
+ │ └── javascript/
313
+ │ └── controllers/
314
+ │ └── home_controller.js
315
+ └── config/
316
+ └── routes.rb (root configured)
317
+ ```
318
+
319
+ ## Using Tailwind CSS
320
+
321
+ Projects come with Tailwind CSS. You can use Tailwind classes directly:
322
+
323
+ ```html
324
+ <div class="container mx-auto px-4 py-8">
325
+ <h1 class="text-4xl font-bold text-blue-600">Title</h1>
326
+ <p class="text-gray-700 mt-4">Content...</p>
327
+ </div>
328
+ ```
329
+
330
+ ### Adding Custom CSS
331
+
332
+ You can use the automatically generated CSS file for each page:
333
+
334
+ ```css
335
+ /* app/assets/stylesheets/about.css */
336
+ .about-container {
337
+ background: linear-gradient(to right, #667eea, #764ba2);
338
+ }
339
+ ```
340
+
341
+ CSS files are automatically imported into the `application.tailwind.css` file.
342
+
343
+ ### Stimulus Features and Usage Example
344
+
345
+ - **Targets:** Easy access to DOM elements
346
+ - **Actions:** Event handling
347
+ - **Values:** Data sharing with data attributes
348
+
349
+ **Example:**
350
+ ```html
351
+ <div data-controller="products"
352
+ data-products-count-value="0">
353
+ <button data-action="products#increment">+</button>
354
+ <span data-products-target="counter">0</span>
355
+ </div>
356
+ ```
357
+
358
+ ```javascript
359
+ export default class extends Controller {
360
+ static targets = ["counter"]
361
+ static values = { count: Number }
362
+
363
+ increment() {
364
+ this.countValue++
365
+ this.counterTarget.textContent = this.countValue
366
+ }
367
+ }
368
+ ```
369
+
370
+ ## Shared Components
371
+
372
+ The main layout file automatically includes shared components:
373
+ You can customize them as you wish.
374
+
375
+ ```erb
376
+ <!-- app/views/layouts/application.html.erb -->
377
+ <body class="flex flex-col min-h-screen">
378
+ <%= render 'shared/header' %>
379
+
380
+ <main class="flex-grow">
381
+ <%= yield %>
382
+ </main>
383
+
384
+ <%= render 'shared/footer' %>
385
+ </body>
386
+ ```
387
+
388
+ ### Using Links
389
+
390
+ ```erb
391
+ <%= link_to "Home", root_path %>
392
+ <%= link_to "About", about_path %>
393
+ <%= link_to "Contact", contact_path %>
394
+ ```
395
+
396
+ ## Command Reference
397
+
398
+ | Command | Short | Description |
399
+ |---------|-------|-------------|
400
+ | `rails-frontend new PROJECT [--clean]` | `n` | Create new project |
401
+ | `rails-frontend build` | `b` | Build static site |
402
+ | `rails-frontend add-page PAGE` | `ap` | Add page |
403
+ | `rails-frontend remove-page PAGE` | `rp` | Remove page |
404
+ | `rails-frontend add-stimulus CONTROLLER` | `as` | Add Stimulus controller |
405
+ | `rails-frontend remove-stimulus CONTROLLER` | `rs` | Remove Stimulus controller |
406
+ | `rails-frontend add-layout LAYOUT` | `al` | Add layout |
407
+ | `rails-frontend remove-layout LAYOUT` | `rl` | Remove layout |
408
+ | `rails-frontend add-pin PACKAGE` | `pin` | Add external JavaScript library |
409
+ | `rails-frontend remove-pin PACKAGE` | `unpin` | Remove external JavaScript library |
410
+ | `rails-frontend run` | `r` | Start server |
411
+ | `rails-frontend version` | `-v` | Show version |
412
+ | `rails-frontend help` | `-h` | Show help |
413
+
414
+ ## Troubleshooting
415
+
416
+ ### 1. Command not found error
417
+
418
+ **Problem:** `rails-frontend: command not found`
419
+
420
+ **Solution:**
421
+ ```bash
422
+ # Make sure you load the gem.
423
+ gem list rails-frontend-cli
424
+
425
+ # If not installed
426
+ gem install rails-frontend-cli
427
+ ```
428
+
429
+ ### 2. Tailwind CSS not working
430
+
431
+ **Problem:** Tailwind classes not being applied
432
+
433
+ **Solution:**
434
+ ```bash
435
+ # Recompile Tailwind (while in project folder)
436
+ bin/rails tailwindcss:build
437
+ ```
438
+
439
+ ### 3. Stimulus controller not working
440
+
441
+ **Problem:** "Controller not found" error in console
442
+
443
+ **Solution:**
444
+ ```bash
445
+ # Recompile JavaScript (while in project folder)
446
+ bin/rails assets:precompile
447
+ ```
448
+
449
+ ### 4. Turkish character issues
450
+
451
+ **Problem:** Error when using Turkish characters in page names
452
+
453
+ **Solution:** Turkish characters are now automatically converted:
454
+ - `hakkımızda` → `hakkimizda`
455
+ - `ürünler` → `urunler`
456
+ - `iletişim` → `iletisim`
457
+
458
+ ## Tips
459
+
460
+ ### Component Library
461
+
462
+ Create reusable components:
463
+
464
+ ```erb
465
+ <!-- app/views/shared/_card.html.erb -->
466
+ <div class="bg-white rounded-lg shadow-lg p-6">
467
+ <h3 class="text-xl font-bold mb-2"><%= title %></h3>
468
+ <p class="text-gray-600"><%= content %></p>
469
+ </div>
470
+ ```
471
+
472
+ Usage:
473
+ ```erb
474
+ <%= render 'shared/card', title: 'Title', content: 'Content' %>
475
+ ```
476
+
477
+ ## Additional Resources
478
+
479
+ - **Tailwind CSS:** https://tailwindcss.com/docs
480
+ - **Stimulus:** https://stimulus.hotwired.dev/
481
+ - **SCSS:** https://sass-lang.com/documentation/syntax/
482
+
483
+ ## Support
484
+
485
+ If you encounter issues:
486
+
487
+ 1. Run `rails-frontend help` command
488
+ 2. Check Rails log files: `log/development.log`
489
+ 3. Check browser console (F12)
490
+
491
+ ## Author
492
+
493
+ Levent Özbilgiç
494
+ [![LinkedIn](https://img.shields.io/badge/LinkedIn-0077B5?style=for-the-badge&logo=linkedin&logoColor=white)](https://www.linkedin.com/in/leventozbilgic/)
495
+
496
+ ## License
497
+
498
+ MIT
499
+
500
+ ---
501
+
502
+ **Happy coding! 🚀**
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'rails_frontend_cli'
5
+
6
+ cli = RailsFrontendCLI.new
7
+ cli.run(ARGV)
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RailsFrontendCLI
4
+ VERSION = "1.0.4"
5
+ end