coffee_controllers-rails 1.0.1 → 2.0.0
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.
- checksums.yaml +4 -4
- data/README.md +6 -17
- data/app/assets/javascripts/coffee_controllers/core.js.coffee +14 -8
- data/lib/coffee_controllers/rails/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c73ccd4a0100fbe6bd04a29b38da594f360e4806
|
4
|
+
data.tar.gz: 568a5333ed6105496f2c301b8a40713dccebf019
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95729213fdf00b2320b326dfec4511d875136d90677acf6eca49e2896432727c5459e79b1008cffd3cf9e449943877e3d7ff883d3f3c474a6984d75e6467d324
|
7
|
+
data.tar.gz: 3819df7db9508eb65332affff1a1e1f15954180ef9f4c13e026df54af4ecb4c2f62ba0d41bb72674364146b90c7eb655bd11eb62140cefff5d958bff2b23b4bb
|
data/README.md
CHANGED
@@ -58,36 +58,26 @@ You can add a `home.js.coffee` file with:
|
|
58
58
|
```coffeescript
|
59
59
|
# app/assets/javascripts/home.js.coffee
|
60
60
|
|
61
|
-
class HomeController
|
61
|
+
@HomeController = class HomeController
|
62
62
|
index: ->
|
63
63
|
alert 'Hello, world!'
|
64
|
-
|
65
|
-
setController 'home', new HomeController()
|
66
64
|
```
|
67
65
|
|
68
66
|
So, for every request to the `index` action, as soon as the DOM is ready, the `index` function will be ran, displaying the `alert`.
|
69
67
|
|
70
68
|
### Remind
|
71
69
|
|
72
|
-
|
73
|
-
|
74
|
-
```coffeescript
|
75
|
-
# setController controllerName, controllerObject
|
76
|
-
|
77
|
-
setController 'foo', new FooController()
|
78
|
-
```
|
79
|
-
|
80
|
-
The `controllerName` has to be the name of the controller underscored. For example:
|
70
|
+
The controller's class name MUST be the same name of the rails controller counterpart. For example:
|
81
71
|
|
82
72
|
```coffeescript
|
83
73
|
# class FooController < ApplicationController
|
84
|
-
|
74
|
+
@FooController = class FooController
|
85
75
|
|
86
76
|
# class FooBarController < ApplicationController
|
87
|
-
|
77
|
+
@FooBarController = class FooBarController
|
88
78
|
|
89
79
|
# class Foo::BarHomeController < ApplicationController
|
90
|
-
|
80
|
+
@FooBarHomeController = class FooBarHomeController
|
91
81
|
```
|
92
82
|
|
93
83
|
### Init
|
@@ -95,7 +85,7 @@ setController 'foo_bar_home', new FooBarHomeController()
|
|
95
85
|
You can define a `init` function to your coffee controllers that is going to be executed before every action function. For example:
|
96
86
|
|
97
87
|
```coffeescript
|
98
|
-
class HomeController
|
88
|
+
@HomeController = class HomeController
|
99
89
|
init: ->
|
100
90
|
alert 'initializing...'
|
101
91
|
|
@@ -113,7 +103,6 @@ class HomeController
|
|
113
103
|
## Todo
|
114
104
|
|
115
105
|
- Lacking some JS tests
|
116
|
-
- Get rid of the `setController` step
|
117
106
|
|
118
107
|
## Contributing
|
119
108
|
|
@@ -15,7 +15,7 @@
|
|
15
15
|
# set the current active controller script, based on the current controller set previously
|
16
16
|
@ActiveController = getController controller
|
17
17
|
|
18
|
-
if @ActiveController
|
18
|
+
if @ActiveController?
|
19
19
|
# call the init function (if any)
|
20
20
|
@ActiveController.init() if typeof @ActiveController.init is 'function'
|
21
21
|
# call the function related to the current action (if any)
|
@@ -23,14 +23,20 @@
|
|
23
23
|
|
24
24
|
return
|
25
25
|
|
26
|
-
#
|
27
|
-
@setController = (controllerName, controllerObj) ->
|
28
|
-
@Controllers[controllerName] = controllerObj
|
29
|
-
return
|
30
|
-
|
31
|
-
# Get a given controller object by its name from the @Controllers
|
26
|
+
# Eval and instantiate a given controller object by its name
|
32
27
|
@getController = (controllerName) ->
|
33
|
-
|
28
|
+
# camelize controller name
|
29
|
+
words = controllerName.split /_|\s+/
|
30
|
+
array = []
|
31
|
+
for word in words
|
32
|
+
array.push word.charAt(0).toUpperCase() + word.toLowerCase().slice(1)
|
33
|
+
controllerCamelized = array.join ''
|
34
|
+
# try to eval the controller and instantiate
|
35
|
+
try
|
36
|
+
controller = eval "#{controllerCamelized}Controller"
|
37
|
+
return new controller()
|
38
|
+
catch
|
39
|
+
return null
|
34
40
|
|
35
41
|
# Get the current active controller object
|
36
42
|
@getCurrentController = ->
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coffee_controllers-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Ferraz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: coffee-rails
|