reins 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d2524b1bf46d2ae61c2b40e164618ea2cef6bb83
4
+ data.tar.gz: 23695b75bd8701646b8eb593106c248e9ae7dda6
5
+ SHA512:
6
+ metadata.gz: 9d5411e9e1c5c0ff63cf9b05e3afc94c46e2a77686e2423b3a74c5fe81361617dabdc2fcc1adb79f15a20af4bb29a11e8effa8a8c36514fbfe8936d20c185af8
7
+ data.tar.gz: 980e99a96ac2522b16d74c2f8e2cf29aece083c3e763b73468080e1b2173ee8d511d3c4031415e861419b2e630716e68956e15a5527bd9d9477d9ca4403446c3
@@ -0,0 +1,20 @@
1
+ Copyright 2015 Tony Goncalves
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,23 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Reins'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
@@ -0,0 +1,18 @@
1
+ require 'rails/generators/named_base'
2
+
3
+ module Reins
4
+ module Generators
5
+ class AssetsGenerator < ::Rails::Generators::NamedBase
6
+
7
+ source_root File.expand_path("../templates", __FILE__)
8
+
9
+ def create_reins_controller
10
+ template(
11
+ 'reins_controller.js',
12
+ File.join('app/assets/javascripts/controllers', class_path, "#{ file_name }.js")
13
+ )
14
+ end
15
+
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Anonymous self-running function to keep us from polluting the global namespace
3
+ * with definitions that should be kept private.
4
+ */
5
+ +function() {
6
+
7
+ /**
8
+ * Publicly accessible functions related to <%= file_name %>.
9
+ * These can be called from anywhere as r.<%= file_name %>.function_name(arg1, arg2);
10
+ *
11
+ * This scope includes the JS controller action functions corresponding to the
12
+ * rails <%= file_name %> controller, so keep in mind that funcions
13
+ * that match the names of the actions will be called automatically by rails.
14
+ */
15
+ window.r.<%= file_name %> = {
16
+
17
+ /**
18
+ * Controller action corresponding to the #new rails action.
19
+ * This code is run everytime that the new.html format is rendered by rails.
20
+ */
21
+ // _new: function() {
22
+ // },
23
+
24
+
25
+ /**
26
+ * Controller action corresponding to the #create rails action.
27
+ * This code is run everytime that the create.html format is rendered by rails.
28
+ */
29
+ // _create: function(params) {
30
+ // },
31
+
32
+
33
+ /**
34
+ * Controller action corresponding to the #index rails action.
35
+ * This code is run everytime that the create.html format is rendered by rails.
36
+ */
37
+ // _index: function(params) {
38
+ // },
39
+
40
+
41
+ /**
42
+ * Controller action corresponding to the #show rails action.
43
+ * This code is run everytime that the create.html format is rendered by rails.
44
+ */
45
+ // _show: function(params) {
46
+ // },
47
+
48
+
49
+ /**
50
+ * Controller action corresponding to the #update rails action.
51
+ * This code is run everytime that the create.html format is rendered by rails.
52
+ */
53
+ // _update: function(params) {
54
+ // },
55
+
56
+
57
+ /**
58
+ * Controller action corresponding to the #destroy rails action.
59
+ * This code is run everytime that the create.html format is rendered by rails.
60
+ */
61
+ // _destroy: function(params) {
62
+ // },
63
+
64
+
65
+ /**
66
+ * You can also declare your own functions here.
67
+ *
68
+ * Call this one from anywhere like this:
69
+ * r.<%= file_name %>.my_function('John Doe');
70
+ */
71
+ // my_function: function(name) {
72
+ // alert('Have a nice day ' + name + '!');
73
+ // }
74
+
75
+ };
76
+
77
+
78
+
79
+ ////////////////////////////////////////////////////////////////////////////
80
+ // Anything below this but still inside the anonymous function is private //
81
+ ////////////////////////////////////////////////////////////////////////////
82
+
83
+ /**
84
+ * This is a private function. It can be called by any function inside this
85
+ * closure, including the controllers above, but it's invisible to the outside
86
+ * world.
87
+ */
88
+ // function my_function2() {
89
+ // // do stuff...
90
+ // }
91
+
92
+
93
+
94
+ }();
@@ -0,0 +1,2 @@
1
+ require 'reins/railtie'
2
+ require 'reins/engine' if defined?(Rails)
@@ -0,0 +1,7 @@
1
+ module Reins
2
+ class Engine < ::Rails::Engine
3
+ initializer 'reins.load_static_assets' do |app|
4
+ app.middleware.use ::ActionDispatch::Static, "#{root}/vendor"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ require 'reins/view_helpers'
2
+
3
+ module Reins
4
+ class Railtie < Rails::Railtie
5
+ config.app_generators.javascript_engine :reins
6
+
7
+ initializer 'reins.view_helpers' do
8
+ ActionView::Base.send :include, ViewHelpers
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module Reins
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,34 @@
1
+ module Reins
2
+ module ViewHelpers
3
+
4
+ # Helper that creates a <script> tag insertable into HTML templates to set the
5
+ # reins controller and action to the current rails controller and action name.
6
+ #
7
+ # Returns:: The javascript code that will perform the necessary actions.
8
+ def reins_script_tag
9
+ "<script>#{ update_reins_controller }</script>".html_safe
10
+ end
11
+
12
+
13
+ # Helper that emits JS code to set the reins controller and action to the
14
+ # current rails controller and action name.
15
+ #
16
+ # Returns:: The javascript code that will perform the necessary actions.
17
+ def update_reins_controller
18
+ "r.controller = '#{ params[:controller] }';
19
+ r.action = '#{ params[:action] }';
20
+ r.params = #{ @reins_params.to_json };".html_safe
21
+ end
22
+
23
+
24
+ # Helper for use in js.erb templates to automatically call the reins
25
+ # controller and action that matches the current rails controller and action
26
+ # name.
27
+ #
28
+ # Returns:: The javascript code that will perform the necessary actions.
29
+ def call_reins_controller
30
+ "#{ update_reins_controller }r.call_js_controller();".html_safe
31
+ end
32
+
33
+ end
34
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: reins
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tony Goncalves
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 4.2.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 4.2.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec-rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: execjs
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Reins is a ruby gem that automates the creation of javascript controllers
56
+ that match the structure of your rails controllers. This includes passing custom
57
+ data to the JS controllers from the server.
58
+ email:
59
+ - tony@weareredlight.com
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - MIT-LICENSE
65
+ - Rakefile
66
+ - lib/rails/generators/reins/assets/assets_generator.rb
67
+ - lib/rails/generators/reins/assets/templates/reins_controller.js
68
+ - lib/reins.rb
69
+ - lib/reins/engine.rb
70
+ - lib/reins/railtie.rb
71
+ - lib/reins/version.rb
72
+ - lib/reins/view_helpers.rb
73
+ homepage: http://github.com/weareredlight/reins
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.4.6
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Reins! Rein in your javascript
97
+ test_files: []