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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e29a5fa03f69f5d1b2b94436937f6c6e691111c7
4
- data.tar.gz: 4e8f0994a7d98254fcf05fb583cc9856e7a1a6dd
3
+ metadata.gz: afbdfa48fc19a1f413c5f71527218bb1daaf3d3a
4
+ data.tar.gz: 612f9ff4237d55935bcbf3cf0b88c689c732ed57
5
5
  SHA512:
6
- metadata.gz: 11a5af34c6def9a79db78f442915ee3e73fe2e629e3043b735d34f9f4be27f2a11eaf8a7e8604843d2dbb20ae52945559c515749eb573111835be778cbc3cf8d
7
- data.tar.gz: aecc8f25cc808a37cbcc3a98a6b1153504a622079f6e5e58963d728bb7286b10a3530de52bfa0cd385cdbad942f2ae4d5399b5ed187a39c404eba9ad2a4d58df
6
+ metadata.gz: d1aaa49ceda92281a40d5c96bdac4a8e598b2a026cca0ddd6ce9858b179adf545f5ba99681c067f26718dc3e980db539b7aa7abf3e5c8fe9cc52842256e6cc65
7
+ data.tar.gz: b9d4833090d527baeaf94a5ce298754e334d140023b8666d1cb380a67462e7debc5756f8ca78673ba5b2f5ffb4306f9d989fc967eff22810b2840ee38df35de0
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # Reins [![Gem Version](https://badge.fury.io/rb/reins.svg)](http://badge.fury.io/rb/reins) [![wercker status](https://app.wercker.com/status/6ea31467d299403dc3bac9f6bd962d96/s/master "wercker status")](https://app.wercker.com/project/bykey/6ea31467d299403dc3bac9f6bd962d96) ![](http://ruby-gem-downloads-badge.herokuapp.com/reins)
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
@@ -1,3 +1,3 @@
1
1
  module Reins
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
@@ -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.2
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