reins 0.0.2 → 0.0.3
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 +30 -0
- data/lib/reins/version.rb +1 -1
- data/vendor/assets/javascripts/reins.js +50 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: afbdfa48fc19a1f413c5f71527218bb1daaf3d3a
|
4
|
+
data.tar.gz: 612f9ff4237d55935bcbf3cf0b88c689c732ed57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1aaa49ceda92281a40d5c96bdac4a8e598b2a026cca0ddd6ce9858b179adf545f5ba99681c067f26718dc3e980db539b7aa7abf3e5c8fe9cc52842256e6cc65
|
7
|
+
data.tar.gz: b9d4833090d527baeaf94a5ce298754e334d140023b8666d1cb380a67462e7debc5756f8ca78673ba5b2f5ffb4306f9d989fc967eff22810b2840ee38df35de0
|
data/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# Reins [](http://badge.fury.io/rb/reins) [](https://app.wercker.com/project/bykey/6ea31467d299403dc3bac9f6bd962d96) 
|
2
|
+
|
3
|
+
Reins is a ruby gem that automates the creation of javascript controllers that match the structure of your rails controllers.
|
4
|
+
It enables you to keep javascript code out of your views by defining namespaced functions that get called automatically for each rails controller action that runs.
|
5
|
+
|
6
|
+
This even works in the case of javascript code that needs data from the server (which almost always ends up inside a <script> tag somewhere with <%%> tags...).
|
7
|
+
You just have to define the @reins_params hash on the controller and this hash will be JSONified and passed to the javascript controller as a dictionary object.
|
8
|
+
|
9
|
+
Reins can be used with or without turbolinks.
|
10
|
+
|
11
|
+
|
12
|
+
To start using it:
|
13
|
+
|
14
|
+
add to your gemfile:
|
15
|
+
|
16
|
+
gem 'reins'
|
17
|
+
|
18
|
+
|
19
|
+
add to application.js:
|
20
|
+
|
21
|
+
//= require reins
|
22
|
+
|
23
|
+
|
24
|
+
add to layouts/*.html.erb, right before </body> closing tag:
|
25
|
+
|
26
|
+
<%= reins_script_tag %>
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
Reins is licenced under the MIT License. Please see the file MIT-LICENSE for more details.
|
data/lib/reins/version.rb
CHANGED
@@ -0,0 +1,50 @@
|
|
1
|
+
/**
|
2
|
+
* Implementation of JavaScript controllers that match the rails controllers
|
3
|
+
* and get called automatically upon rendering of html.erb views.
|
4
|
+
*
|
5
|
+
* "r" is the main namespace where all JS controllers related code will be
|
6
|
+
* nested in.
|
7
|
+
*/
|
8
|
+
var r = {
|
9
|
+
|
10
|
+
/**
|
11
|
+
* Varible where current rails controller name is stored for easy access.
|
12
|
+
*/
|
13
|
+
controller: '',
|
14
|
+
|
15
|
+
|
16
|
+
/**
|
17
|
+
* Varible where current rails action name is stored for easy access.
|
18
|
+
*/
|
19
|
+
action: '',
|
20
|
+
|
21
|
+
|
22
|
+
/**
|
23
|
+
* Varible where the @reins_params that were set on the server controller get
|
24
|
+
* stored.
|
25
|
+
*/
|
26
|
+
params: null,
|
27
|
+
|
28
|
+
|
29
|
+
/**
|
30
|
+
* Calls the current JS controller that corresponds to the rendered rails
|
31
|
+
* controller#action (if it exists).
|
32
|
+
*/
|
33
|
+
call_js_controller: function() {
|
34
|
+
var reins_controller = r.controller.replace(/\//gi, '_');
|
35
|
+
if (r[reins_controller] != null) {
|
36
|
+
var func = r[reins_controller]['_' + r.action];
|
37
|
+
if (typeof func == 'function')
|
38
|
+
func.call(r[reins_controller], r.params);
|
39
|
+
}
|
40
|
+
}
|
41
|
+
|
42
|
+
};
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
/**
|
47
|
+
* When page is ready, run javascript controller#action that corresponds to
|
48
|
+
* current rails controller#action.
|
49
|
+
*/
|
50
|
+
$(document).on('page:load ready', r.call_js_controller);
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reins
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tony Goncalves
|
@@ -62,6 +62,7 @@ extensions: []
|
|
62
62
|
extra_rdoc_files: []
|
63
63
|
files:
|
64
64
|
- MIT-LICENSE
|
65
|
+
- README.md
|
65
66
|
- Rakefile
|
66
67
|
- lib/rails/generators/reins/assets/assets_generator.rb
|
67
68
|
- lib/rails/generators/reins/assets/templates/reins_controller.js
|
@@ -70,6 +71,7 @@ files:
|
|
70
71
|
- lib/reins/railtie.rb
|
71
72
|
- lib/reins/version.rb
|
72
73
|
- lib/reins/view_helpers.rb
|
74
|
+
- vendor/assets/javascripts/reins.js
|
73
75
|
homepage: http://github.com/weareredlight/reins
|
74
76
|
licenses:
|
75
77
|
- MIT
|