rails-js 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +114 -0
- data/MIT-LICENSE +20 -0
- data/README.md +132 -2
- data/Rakefile +19 -0
- data/lib/rails/js/version.rb +5 -0
- data/rails-js.gemspec +11 -1
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/images/.keep +0 -0
- data/test/dummy/app/assets/javascripts/application.js +14 -0
- data/test/dummy/app/assets/javascripts/testing.js +2 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/controllers/concerns/.keep +0 -0
- data/test/dummy/app/controllers/testing_controller.rb +6 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/helpers/testing_helper.rb +2 -0
- data/test/dummy/app/mailers/.keep +0 -0
- data/test/dummy/app/models/.keep +0 -0
- data/test/dummy/app/models/concerns/.keep +0 -0
- data/test/dummy/app/views/layouts/application.html.erb +15 -0
- data/test/dummy/app/views/testing/index.html.erb +0 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +22 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +83 -0
- data/test/dummy/config/environments/test.rb +39 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +4 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/lib/assets/.keep +0 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/test/helpers/testing_helper_test.rb +4 -0
- data/test/teaspoon_env.rb +24 -0
- data/test/test_helper.rb +15 -0
- data/test/testing_controller_test.rb +12 -0
- metadata +111 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7a095e9cfffa3e1d2b2c014a5337274493cd77a
|
4
|
+
data.tar.gz: e95794d144143f42b1cc83cc919ee619c0d6986e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47ced54a87c6dbad5d2b70e8cd08d940bc892204cb04ae184945e053746b93179b43a6e52f471a81458d92fcaff46413372c745b38e8a2cf4c6a0e2f6f73abf8
|
7
|
+
data.tar.gz: 9caa7c7725d5381a0874a43371ede315b1a45fea9803cfa841e479f234c452435ebaae08c188a263c999af7d8e015385b1a30a6a3ad42c6bd938f3a28e76a3c1
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
# Declare your gem's dependencies in penis.gemspec.
|
4
|
+
# Bundler will treat runtime dependencies like base dependencies, and
|
5
|
+
# development dependencies will be added by default to the :development group.
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
# Declare any dependencies that are still in development here instead of in
|
9
|
+
# your gemspec. These might include edge Rails or gems from your path or
|
10
|
+
# Git. Remember to move these dependencies to your gemspec before releasing
|
11
|
+
# your gem to rubygems.org.
|
12
|
+
|
13
|
+
# To use debugger
|
14
|
+
# gem 'debugger'
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rails-js (0.0.2)
|
5
|
+
rails (~> 4.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
actionmailer (4.1.1)
|
11
|
+
actionpack (= 4.1.1)
|
12
|
+
actionview (= 4.1.1)
|
13
|
+
mail (~> 2.5.4)
|
14
|
+
actionpack (4.1.1)
|
15
|
+
actionview (= 4.1.1)
|
16
|
+
activesupport (= 4.1.1)
|
17
|
+
rack (~> 1.5.2)
|
18
|
+
rack-test (~> 0.6.2)
|
19
|
+
actionview (4.1.1)
|
20
|
+
activesupport (= 4.1.1)
|
21
|
+
builder (~> 3.1)
|
22
|
+
erubis (~> 2.7.0)
|
23
|
+
activemodel (4.1.1)
|
24
|
+
activesupport (= 4.1.1)
|
25
|
+
builder (~> 3.1)
|
26
|
+
activerecord (4.1.1)
|
27
|
+
activemodel (= 4.1.1)
|
28
|
+
activesupport (= 4.1.1)
|
29
|
+
arel (~> 5.0.0)
|
30
|
+
activesupport (4.1.1)
|
31
|
+
i18n (~> 0.6, >= 0.6.9)
|
32
|
+
json (~> 1.7, >= 1.7.7)
|
33
|
+
minitest (~> 5.1)
|
34
|
+
thread_safe (~> 0.1)
|
35
|
+
tzinfo (~> 1.1)
|
36
|
+
arel (5.0.1.20140414130214)
|
37
|
+
builder (3.2.2)
|
38
|
+
capybara (2.2.1)
|
39
|
+
mime-types (>= 1.16)
|
40
|
+
nokogiri (>= 1.3.3)
|
41
|
+
rack (>= 1.0.0)
|
42
|
+
rack-test (>= 0.5.4)
|
43
|
+
xpath (~> 2.0)
|
44
|
+
cliver (0.3.2)
|
45
|
+
erubis (2.7.0)
|
46
|
+
hike (1.2.3)
|
47
|
+
i18n (0.6.11)
|
48
|
+
json (1.8.1)
|
49
|
+
mail (2.5.4)
|
50
|
+
mime-types (~> 1.16)
|
51
|
+
treetop (~> 1.4.8)
|
52
|
+
mime-types (1.25.1)
|
53
|
+
mini_portile (0.6.0)
|
54
|
+
minitest (5.3.5)
|
55
|
+
multi_json (1.10.1)
|
56
|
+
nokogiri (1.6.2.1)
|
57
|
+
mini_portile (= 0.6.0)
|
58
|
+
poltergeist (1.5.1)
|
59
|
+
capybara (~> 2.1)
|
60
|
+
cliver (~> 0.3.1)
|
61
|
+
multi_json (~> 1.0)
|
62
|
+
websocket-driver (>= 0.2.0)
|
63
|
+
polyglot (0.3.5)
|
64
|
+
rack (1.5.2)
|
65
|
+
rack-test (0.6.2)
|
66
|
+
rack (>= 1.0)
|
67
|
+
rails (4.1.1)
|
68
|
+
actionmailer (= 4.1.1)
|
69
|
+
actionpack (= 4.1.1)
|
70
|
+
actionview (= 4.1.1)
|
71
|
+
activemodel (= 4.1.1)
|
72
|
+
activerecord (= 4.1.1)
|
73
|
+
activesupport (= 4.1.1)
|
74
|
+
bundler (>= 1.3.0, < 2.0)
|
75
|
+
railties (= 4.1.1)
|
76
|
+
sprockets-rails (~> 2.0)
|
77
|
+
railties (4.1.1)
|
78
|
+
actionpack (= 4.1.1)
|
79
|
+
activesupport (= 4.1.1)
|
80
|
+
rake (>= 0.8.7)
|
81
|
+
thor (>= 0.18.1, < 2.0)
|
82
|
+
rake (10.3.2)
|
83
|
+
sprockets (2.12.2)
|
84
|
+
hike (~> 1.2)
|
85
|
+
multi_json (~> 1.0)
|
86
|
+
rack (~> 1.0)
|
87
|
+
tilt (~> 1.1, != 1.3.0)
|
88
|
+
sprockets-rails (2.2.0)
|
89
|
+
actionpack (>= 3.0)
|
90
|
+
activesupport (>= 3.0)
|
91
|
+
sprockets (>= 2.8, < 4.0)
|
92
|
+
sqlite3 (1.3.9)
|
93
|
+
teaspoon (0.8.0)
|
94
|
+
railties (>= 3.2.5, < 5)
|
95
|
+
thor (0.19.1)
|
96
|
+
thread_safe (0.3.4)
|
97
|
+
tilt (1.4.1)
|
98
|
+
treetop (1.4.15)
|
99
|
+
polyglot
|
100
|
+
polyglot (>= 0.3.1)
|
101
|
+
tzinfo (1.2.1)
|
102
|
+
thread_safe (~> 0.1)
|
103
|
+
websocket-driver (0.3.4)
|
104
|
+
xpath (2.0.0)
|
105
|
+
nokogiri (~> 1.3)
|
106
|
+
|
107
|
+
PLATFORMS
|
108
|
+
ruby
|
109
|
+
|
110
|
+
DEPENDENCIES
|
111
|
+
poltergeist (~> 1.5)
|
112
|
+
rails-js!
|
113
|
+
sqlite3 (~> 1.3)
|
114
|
+
teaspoon (~> 0.8)
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2014 YOURNAME
|
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.
|
data/README.md
CHANGED
@@ -1,4 +1,134 @@
|
|
1
|
-
rails
|
1
|
+
rails-js
|
2
2
|
========
|
3
3
|
|
4
|
-
|
4
|
+
I worked on several Rails projects and there were many cases when it felt overkill to use a framework like ``Angular`` or ``Ember``, because javascript was only needed in some parts of the application.
|
5
|
+
But by not using these frameworks I had to think of a way to *structure* the code by myself.
|
6
|
+
I came up with the conclusion to organize the javascript code like the ruby code is organized, that means: __Split up in controllers, which are split up in actions.__
|
7
|
+
|
8
|
+
## How it works
|
9
|
+
* In ``rails-js`` we are able to define ``controllers``, as well as ``helpers``.
|
10
|
+
* Controllers have ``actions`` which are executed when the matching rails action is executed.
|
11
|
+
* Helpers should be clear. Pretty much like the rails helpers. There are helper per controller and global helpers.
|
12
|
+
* The gem also provides a ``view helper`` to use in your layouts, which passes the routing information to ``rails-js``.
|
13
|
+
|
14
|
+
#### You start by creating an app.
|
15
|
+
|
16
|
+
```js
|
17
|
+
//= rails
|
18
|
+
|
19
|
+
/*
|
20
|
+
* app/assets/javascripts/application.js
|
21
|
+
*/
|
22
|
+
|
23
|
+
Rails.app({
|
24
|
+
// Define global helpers here
|
25
|
+
helper: function() {
|
26
|
+
}
|
27
|
+
},
|
28
|
+
// Put in initial data
|
29
|
+
{
|
30
|
+
foo: 'bar'
|
31
|
+
},
|
32
|
+
// A function that is executed before every action
|
33
|
+
function() {
|
34
|
+
console.log('beforeAll() executed');
|
35
|
+
});
|
36
|
+
|
37
|
+
```
|
38
|
+
#### Create controllers accordingly.
|
39
|
+
|
40
|
+
```js
|
41
|
+
|
42
|
+
/*
|
43
|
+
* app/assets/javascripts/controllers/users.js
|
44
|
+
*/
|
45
|
+
|
46
|
+
Rails.controller('users', {
|
47
|
+
// actions here
|
48
|
+
new: function(h) {
|
49
|
+
// execute helper
|
50
|
+
h.awesomeHelper();
|
51
|
+
},
|
52
|
+
|
53
|
+
index: function(h) {
|
54
|
+
// Do the same as in new()
|
55
|
+
this.index(h);
|
56
|
+
}
|
57
|
+
},
|
58
|
+
{
|
59
|
+
// helpers here
|
60
|
+
function awesomeHelper() {
|
61
|
+
}
|
62
|
+
});
|
63
|
+
|
64
|
+
```
|
65
|
+
|
66
|
+
|
67
|
+
#### Use code from other controllers.
|
68
|
+
```js
|
69
|
+
|
70
|
+
/*
|
71
|
+
* app/assets/javascripts/controllers/admin/users.js
|
72
|
+
*/
|
73
|
+
|
74
|
+
Rails.controller('admin/users', {
|
75
|
+
new: function(h) {
|
76
|
+
// Execute action of foreign controller
|
77
|
+
R.action('users#new');
|
78
|
+
},
|
79
|
+
|
80
|
+
index: function(h) {
|
81
|
+
// Execute foreign helper with arguments
|
82
|
+
R.helper('users', 'awesomeHelper', 1, 2, 3);
|
83
|
+
|
84
|
+
// Execute global helper with arguments
|
85
|
+
R.global('helper', 1, 2, 3);
|
86
|
+
}
|
87
|
+
},{});
|
88
|
+
|
89
|
+
```
|
90
|
+
|
91
|
+
|
92
|
+
#### Global variables without the mess.
|
93
|
+
```js
|
94
|
+
/*
|
95
|
+
* Use R singleton everywhere
|
96
|
+
*/
|
97
|
+
|
98
|
+
// Setting
|
99
|
+
R('answer', 42);
|
100
|
+
// Multiple levels
|
101
|
+
R('a.global.variable', 'foo');
|
102
|
+
|
103
|
+
// Getting
|
104
|
+
console.log(R('a.global.variable'));
|
105
|
+
```
|
106
|
+
|
107
|
+
|
108
|
+
#### Define hooks for namespaces.
|
109
|
+
```js
|
110
|
+
/*
|
111
|
+
* app/assets/javascripts/namespaces/admin.js
|
112
|
+
*/
|
113
|
+
|
114
|
+
Rails.namespace('admin', function() {
|
115
|
+
// Will be executed on all admin routes (e.g. admin/users#new)
|
116
|
+
console.log('Hello Mr. Admin');
|
117
|
+
});
|
118
|
+
```
|
119
|
+
|
120
|
+
#### For more info...
|
121
|
+
...just read in ``app/assets/javascripts/rails.js``. I tried my best and documented nearly every line of code :)
|
122
|
+
|
123
|
+
Installing
|
124
|
+
==========
|
125
|
+
|
126
|
+
Install it as any other gem by putting this to your ``Gemfile``:
|
127
|
+
```ruby
|
128
|
+
gem 'rails-js'
|
129
|
+
```
|
130
|
+
In your layouts, put this line into the ``head``:
|
131
|
+
```erb
|
132
|
+
<%= rails_js %>
|
133
|
+
```
|
134
|
+
Also make sure to include ``rails`` in your ``application.js``.
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
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
|
+
Bundler::GemHelper.install_tasks
|
8
|
+
|
9
|
+
require 'rake/testtask'
|
10
|
+
|
11
|
+
Rake::TestTask.new(:test) do |t|
|
12
|
+
t.libs << 'lib'
|
13
|
+
t.libs << 'test'
|
14
|
+
t.pattern = 'test/**/*_test.rb'
|
15
|
+
t.verbose = false
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
task default: :test
|
data/rails-js.gemspec
CHANGED
@@ -1,6 +1,11 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
|
3
|
+
# Maintain your gem's version:
|
4
|
+
require "rails/js/version"
|
5
|
+
|
1
6
|
Gem::Specification.new do |s|
|
2
7
|
s.name = 'rails-js'
|
3
|
-
s.version =
|
8
|
+
s.version = Rails::JS::VERSION
|
4
9
|
s.date = '2014-10-11'
|
5
10
|
s.summary = "A new approach to structure your javascript in non single-page Rails apps"
|
6
11
|
s.description = "Divide your javascript like you divide your ruby code. Put it in controllers and actions and write clean, scalable code."
|
@@ -10,4 +15,9 @@ Gem::Specification.new do |s|
|
|
10
15
|
s.require_paths = ['lib']
|
11
16
|
s.homepage = 'http://rubygems.org/gems/rails-js'
|
12
17
|
s.license = 'MIT'
|
18
|
+
|
19
|
+
s.add_dependency "rails", "~> 4.1"
|
20
|
+
s.add_development_dependency "sqlite3", "~> 1.3"
|
21
|
+
s.add_development_dependency "teaspoon", "~> 0.8"
|
22
|
+
s.add_development_dependency "poltergeist", "~> 1.5"
|
13
23
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
== README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
25
|
+
|
26
|
+
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
28
|
+
<tt>rake doc:app</tt>.
|
data/test/dummy/Rakefile
ADDED
File without changes
|
@@ -0,0 +1,14 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require rails
|
14
|
+
//= require_tree .
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
+
* file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|