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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6305c2dcc2a4cef2e4533d78c5ec229d06899413
4
- data.tar.gz: 1f8315070f422185906bf667711ce6dc1dfc8c4b
3
+ metadata.gz: c73ccd4a0100fbe6bd04a29b38da594f360e4806
4
+ data.tar.gz: 568a5333ed6105496f2c301b8a40713dccebf019
5
5
  SHA512:
6
- metadata.gz: e610e3cbc21dd4d010287baff755baee5adc04b5b1833ce44a7e1bef5e035657a8b5fc1bb2170191d7676db51f6ec8a6dc6df28aac6ab6c35e400558b1c60ed6
7
- data.tar.gz: 7c0be19daa034223a78e52b94f6c712b36b4ee320d3d1d0e4201d11b991aa52661a5058c7891a3e69eab942e9d2bff26986c5169cc341ae9405d6f5deac30726
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
- For every coffee controller defined, you need to attach it through the `setController` function.
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
- setController 'foo', new FooController()
74
+ @FooController = class FooController
85
75
 
86
76
  # class FooBarController < ApplicationController
87
- setController 'foo_bar', new FooBarController()
77
+ @FooBarController = class FooBarController
88
78
 
89
79
  # class Foo::BarHomeController < ApplicationController
90
- setController 'foo_bar_home', new FooBarHomeController()
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 != undefined
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
- # Store a given controller object by its name in the @Controllers
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
- @Controllers[controllerName]
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 = ->
@@ -1,5 +1,5 @@
1
1
  module CoffeeControllers
2
2
  module Rails
3
- VERSION = '1.0.1'
3
+ VERSION = '2.0.0'
4
4
  end
5
5
  end
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: 1.0.1
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-02-28 00:00:00.000000000 Z
11
+ date: 2015-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: coffee-rails