Skip to content

Commit eaa8ebe

Browse files
committed
Update README.md
1 parent 8a1f5ff commit eaa8ebe

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

README.md

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ This will create the following in ```/app/assets/javascripts/elements/main_menu.
184184

185185
```
186186
# /app/assets/javascripts/elements/main_menu.js.coffee```
187+
187188
window.App.Element ||= {}
188189
class App.Element.MainMenu
189190
@@ -195,6 +196,7 @@ We can now add all the logic for the main menu in a separate class and call it o
195196

196197
```
197198
# app/assets/javascripts/base.js.coffee
199+
198200
window.App ||= {}
199201
class App.Base
200202
@@ -210,10 +212,11 @@ Inheritance is another key tool for reusability. Let's say our ```Element.MainM
210212

211213
$ rails g rails:script MainMenu Modal
212214

213-
This would generate:
215+
Which generates:
214216

215217
````
216-
# /app/assets/javascripts/elements/main_menu.js.coffee```
218+
# /app/assets/javascripts/elements/main_menu.js.coffee
219+
217220
window.App.Element ||= {}
218221
class App.Element.MainMenu extends App.Utility.Modal
219222
@@ -224,7 +227,7 @@ class App.Element.MainMenu extends App.Utility.Modal
224227
Inheritance from the generator can only come from a Utility class. Any custom class you wish to extend should be created as a Utility. The installer adds the line ```//= require_tree ./utilities``` before loading tree to handle this. If you have a utility that extends a utility, you should make sure the extended utility is loaded first by explicitly requiring it before the utilities tree.
225228

226229

227-
### Generating New Controllers
230+
### Custom Controllers
228231

229232
When a new controller is generated, the JavaScript asset file will be generated with RailsScript. However, if you need to manually generate a RailsScript controller you can use:
230233

@@ -262,6 +265,28 @@ class App.SomeNewController extends App.Base
262265
None of the pre-defined functions are necessary, you can remove the ones you don't want.
263266

264267

268+
### Generic Classes
269+
270+
To generate a generic class that isn't a Utility, Element or Controller, just use the following:
271+
272+
$ rails g rails_script:class My::ClassName
273+
274+
Which generates:
275+
276+
```
277+
# /app/assets/javascripts/my/class_name.js.coffee
278+
279+
window.App ||= {}
280+
class App.MyClassName
281+
282+
constructor: ->
283+
return this
284+
285+
```
286+
287+
288+
289+
265290
## Contributing
266291

267292
1. Fork it ( https://github.com/[my-github-username]/rails_script/fork )

0 commit comments

Comments
 (0)