rails_script 0.6.1 → 0.7.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 +13 -5
- data/README.md +28 -20
- data/lib/generators/rails_script/class/templates/javascript.js.coffee +3 -3
- data/lib/generators/rails_script/controller/templates/javascript.js.coffee +3 -3
- data/lib/generators/rails_script/install/install_generator.rb +1 -0
- data/lib/generators/rails_script/install/templates/base.js.coffee +2 -2
- data/lib/generators/rails_script/install/templates/global.js.coffee +1 -1
- data/lib/generators/rails_script/install/templates/rails_script.rb +4 -0
- data/lib/rails_script/loader_helper.rb +3 -3
- data/lib/rails_script/version.rb +1 -1
- data/lib/rails_script.rb +6 -0
- metadata +15 -14
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MWIxY2ZiNzBjYjVkMTU4MGMzZmIyN2Q5ZGVmZTgzNjE5NGRmOGFlMg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MjQ2M2VkZjY5NDgxNjk1ZTE2OGFhMjMwZmI1YjU1MzE2M2MzNTRhMA==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
M2M4NmI0NDc5Y2Q3ZjRiNGVjZWRmODg4NzQ2OWQ2Yjk1ZTZiMDk1Yzg3MTBl
|
10
|
+
ZjI5NTA1NWExMmQ2OGY5NDAzNjAxOWFhMWY4ZmFmN2ZmYTk2ZDlmN2QxNDdl
|
11
|
+
Y2U3ZDE0M2M2NGEwMTc0MDZkYTlmMjc4Y2U1Zjc4ZmQyYjk2NWM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZWJlYTZlNGIyNjdhYTMzNWNhMGQxNzNlYTM0MWViYWNiZjEwMTRkZjA4Zjgw
|
14
|
+
ZmMyMDU0ODBjMWJmNmQ0ZTU1ZjdkYTJkOGZlNGY1N2E4ODJkZjhiNDFkY2E0
|
15
|
+
OWY4ZmE4OTJiZGMyMDgxOTI2NzhhYjU5YmQyZTRiZjUzZTQ5YTE=
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@ RailsScript is a Rails-centric, object oriented, featherweight framework for wri
|
|
6
6
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
|
-
gem 'rails_script', '~> 0.6.
|
9
|
+
gem 'rails_script', '~> 0.6.1'
|
10
10
|
|
11
11
|
And then execute:
|
12
12
|
|
@@ -22,13 +22,18 @@ After the generator finishes, you will be prompted to add helper call to your ap
|
|
22
22
|
<%= include_rails_script %>
|
23
23
|
```
|
24
24
|
|
25
|
+
NOTE: Your JS files needed have been included before `include_rails_script`. In other words, you still need `<%= javascript_include_tag "application" %>` in your application layout.
|
26
|
+
|
27
|
+
## Configuration
|
28
|
+
You can configure name of your application in config/initializers/rails_script.rb file.
|
29
|
+
|
25
30
|
## Usage
|
26
31
|
|
27
32
|
### Page (Action) Specific JavaScript
|
28
33
|
|
29
34
|
Your JavaScript class is named after your Controller and there is a method for each Controller action. Whenever you generate a Controller, the CoffeeScript file that is generated will define the new JavaScript class and the basic REST actions. The example below would print 'users#show' in the console for the ```Users#show``` action.
|
30
35
|
|
31
|
-
```
|
36
|
+
```coffeescript
|
32
37
|
# app/assets/javascripts/users.js.coffee
|
33
38
|
|
34
39
|
window.App ||= {}
|
@@ -42,9 +47,9 @@ class App.Users extends App.Base
|
|
42
47
|
|
43
48
|
### Controller Specific JavaScript
|
44
49
|
|
45
|
-
Executing some JavaScript to run on all controller actions is just a matter of adding it to the ```beforeAction``` or ```afterAction``` function. ```beforeAction``` is run before all controller action functions and ```afterAction``` is run after all controller action functions. The before and after action functions have an optional argument ```action``` which is string containing the current action name. The example below would print 'before ACTION action' and 'after ACTION action' for each ```Users``` controller action.
|
50
|
+
Executing some JavaScript to run on all controller actions is just a matter of adding it to the ```beforeAction``` or ```afterAction``` function. ```beforeAction``` is run before all controller action functions and ```afterAction``` is run after all controller action functions. The before and after action functions have an optional argument ```action``` which is a string containing the current action name. The example below would print 'before ACTION action' and 'after ACTION action' for each ```Users``` controller action.
|
46
51
|
|
47
|
-
```
|
52
|
+
```coffeescript
|
48
53
|
# app/assets/javascripts/users.js.coffee
|
49
54
|
window.App ||= {}
|
50
55
|
class App.Users extends App.Base
|
@@ -53,7 +58,7 @@ class App.Users extends App.Base
|
|
53
58
|
console.log "before #{action} action"
|
54
59
|
|
55
60
|
afterAction: (action) =>
|
56
|
-
|
61
|
+
console.log "after #{action} action"
|
57
62
|
```
|
58
63
|
|
59
64
|
|
@@ -61,7 +66,7 @@ class App.Users extends App.Base
|
|
61
66
|
|
62
67
|
Running some JavaScript on every page of an Application is a common need. For example, we may want to create a site credit rollover in the footer of every page.
|
63
68
|
|
64
|
-
```
|
69
|
+
```coffeescript
|
65
70
|
# app/assets/javascripts/base.js.coffee
|
66
71
|
window.App ||= {}
|
67
72
|
class App.Base
|
@@ -87,18 +92,16 @@ In this example we extracted the rollover action into a new function. Doing so
|
|
87
92
|
|
88
93
|
Any functions that need to be accessible in the global scope should be defined in ```global.js.coffee``` using the ```App``` namespace. Below is an example of one of our favorite functions that we use to submit a form using AJAX as a JSON request.
|
89
94
|
|
90
|
-
```
|
95
|
+
```coffeescript
|
91
96
|
# app/assets/javascripts/global.js.coffee
|
92
97
|
window.App ||= {}
|
93
98
|
|
94
99
|
App.remoteSubmission = ($form) ->
|
95
|
-
$.ajax
|
100
|
+
return $.ajax
|
96
101
|
url: $form.attr('action')
|
97
102
|
type: $form.attr('method')
|
98
103
|
data: $form.serialize()
|
99
104
|
dataType: 'json'
|
100
|
-
|
101
|
-
return
|
102
105
|
```
|
103
106
|
|
104
107
|
Now you can access this function from anywhere in the application by just calling ```App.remoteSubmission($('#myForm'))```
|
@@ -115,7 +118,7 @@ First, generate the ```Utility```
|
|
115
118
|
|
116
119
|
This will create the following in ```/app/assets/javascripts/utilities/modal.js.coffee```:
|
117
120
|
|
118
|
-
```
|
121
|
+
```coffeescript
|
119
122
|
# /app/assets/javascripts/utilities/modal.js.coffee
|
120
123
|
window.Utility ||= {}
|
121
124
|
class Utility.Modal
|
@@ -126,7 +129,7 @@ class Utility.Modal
|
|
126
129
|
|
127
130
|
Let's add some basic functionality:
|
128
131
|
|
129
|
-
```
|
132
|
+
```coffeescript
|
130
133
|
# /app/assets/javascripts/utilities/modal.js.coffee
|
131
134
|
window.Utility ||= {}
|
132
135
|
class Utility.Modal
|
@@ -156,7 +159,7 @@ class Utility.Modal
|
|
156
159
|
|
157
160
|
Now, here's how we use the utility from ```users#show```
|
158
161
|
|
159
|
-
```
|
162
|
+
```coffeescript
|
160
163
|
# app/assets/javascripts/users.js.coffee
|
161
164
|
|
162
165
|
window.App ||= {}
|
@@ -179,7 +182,7 @@ First generate the ```Element```
|
|
179
182
|
|
180
183
|
This will create the following in ```/app/assets/javascripts/elements/main_menu.js.coffee```
|
181
184
|
|
182
|
-
```
|
185
|
+
```coffeescript
|
183
186
|
# /app/assets/javascripts/elements/main_menu.js.coffee```
|
184
187
|
|
185
188
|
window.Element ||= {}
|
@@ -191,7 +194,7 @@ class Element.MainMenu
|
|
191
194
|
|
192
195
|
We can now add all the logic for the main menu in a separate class and call it on every page like so:
|
193
196
|
|
194
|
-
```
|
197
|
+
```coffeescript
|
195
198
|
# app/assets/javascripts/base.js.coffee
|
196
199
|
|
197
200
|
window.App ||= {}
|
@@ -212,7 +215,7 @@ Inheritance is another key tool for reusability. Let's say our ```Element.MainM
|
|
212
215
|
|
213
216
|
Which generates:
|
214
217
|
|
215
|
-
````
|
218
|
+
````coffeescript
|
216
219
|
# /app/assets/javascripts/elements/main_menu.js.coffee
|
217
220
|
|
218
221
|
window.Element ||= {}
|
@@ -234,7 +237,7 @@ When a new controller is generated, the JavaScript asset file will be generated
|
|
234
237
|
|
235
238
|
Since the above example includes a namespace, it would generate:
|
236
239
|
|
237
|
-
```
|
240
|
+
```coffeescript
|
238
241
|
# app/assets/javascripts/some/new_controller.js.coffee
|
239
242
|
|
240
243
|
window.App ||= {}
|
@@ -276,7 +279,7 @@ To generate a generic class that isn't a Utility, Element or Controller, just us
|
|
276
279
|
|
277
280
|
Which generates:
|
278
281
|
|
279
|
-
```
|
282
|
+
```coffeescript
|
280
283
|
# /app/assets/javascripts/my/class_name.js.coffee
|
281
284
|
|
282
285
|
window.App ||= {}
|
@@ -294,7 +297,7 @@ class App.MyClassName
|
|
294
297
|
To pass data from Rails to JavaScript, just call ```to_javascript``` along with a hash of your data. This is then converted to a JSON object with ```to_javascript.to_json``` and can be accessed with ```Utility.RailsVars```. The ```to_javascript``` helper may be called from multiple points in the application, all data is merged together.
|
295
298
|
|
296
299
|
Here's an example where ```to_javascript``` is used in a ```before_filter``` to pass the current user and their friends:
|
297
|
-
```
|
300
|
+
```ruby
|
298
301
|
# /app/controllers/application_controller.rb
|
299
302
|
|
300
303
|
class ApplicationController
|
@@ -312,7 +315,7 @@ end
|
|
312
315
|
|
313
316
|
And here's how we print that data to the console on the ```users#index``` action:
|
314
317
|
|
315
|
-
```
|
318
|
+
```coffeescript
|
316
319
|
# /app/assets/javascripts/users.js.coffee
|
317
320
|
|
318
321
|
window.App ||= {}
|
@@ -331,6 +334,11 @@ Since Turbolinks doesn't refresh the page and only replaces the body, event list
|
|
331
334
|
|
332
335
|
|
333
336
|
|
337
|
+
### Page Transitions
|
338
|
+
|
339
|
+
Full page transitions are super easy with RailsScript and Turbolinks. Checkout the wiki for more information on how to add these to your RailsScript application, https://github.com/gemgento/rails_script/wiki/Turbolinks-Page-Transitions.
|
340
|
+
|
341
|
+
|
334
342
|
|
335
343
|
## Contributing
|
336
344
|
|
@@ -1,5 +1,5 @@
|
|
1
|
-
window.
|
2
|
-
class
|
1
|
+
window.<%= RailsScript.app_namespace %> ||= {}
|
2
|
+
class <%= RailsScript.app_namespace %>.<%= controller.gsub('::', '') %> extends <%= RailsScript.app_namespace %>.Base
|
3
3
|
|
4
4
|
beforeAction: (action) =>
|
5
5
|
return
|
@@ -22,4 +22,4 @@ class App.<%= controller.gsub('::', '') %> extends App.Base
|
|
22
22
|
|
23
23
|
|
24
24
|
edit: =>
|
25
|
-
return
|
25
|
+
return
|
@@ -6,6 +6,7 @@ module RailsScript
|
|
6
6
|
def copy_files
|
7
7
|
template 'base.js.coffee', 'app/assets/javascripts/base.js.coffee'
|
8
8
|
template 'global.js.coffee', 'app/assets/javascripts/global.js.coffee'
|
9
|
+
template 'rails_script.rb', 'config/initializers/rails_script.rb'
|
9
10
|
end
|
10
11
|
|
11
12
|
def create_directories
|
@@ -1 +1 @@
|
|
1
|
-
window.
|
1
|
+
window.<%= RailsScript.app_namespace %> ||= {}
|
@@ -7,7 +7,7 @@ window.Utility || (window.Utility = {});
|
|
7
7
|
Utility.RailsVars = #{@to_javascript.nil? ? '{}' : @to_javascript.to_json};
|
8
8
|
|
9
9
|
(function() {
|
10
|
-
window.$this = new (
|
10
|
+
window.$this = new (#{RailsScript.app_namespace}.#{ controller_path.split(/\/|_/).map(&:capitalize).join('') } || #{RailsScript.app_namespace}.Base)();
|
11
11
|
if (typeof $this.beforeAction === 'function') {
|
12
12
|
$this.beforeAction("#{action_name}");
|
13
13
|
}
|
@@ -18,8 +18,8 @@ Utility.RailsVars = #{@to_javascript.nil? ? '{}' : @to_javascript.to_json};
|
|
18
18
|
$this.afterAction("#{action_name}");
|
19
19
|
}
|
20
20
|
})();
|
21
|
-
RUBY
|
21
|
+
RUBY
|
22
22
|
end
|
23
23
|
|
24
24
|
end
|
25
|
-
end
|
25
|
+
end
|
data/lib/rails_script/version.rb
CHANGED
data/lib/rails_script.rb
CHANGED
metadata
CHANGED
@@ -1,61 +1,61 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_script
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Pheasey
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.6'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.6'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: coffee-rails
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '4.0'
|
48
|
-
- -
|
48
|
+
- - ! '>='
|
49
49
|
- !ruby/object:Gem::Version
|
50
50
|
version: 4.0.0
|
51
51
|
type: :runtime
|
52
52
|
prerelease: false
|
53
53
|
version_requirements: !ruby/object:Gem::Requirement
|
54
54
|
requirements:
|
55
|
-
- -
|
55
|
+
- - ~>
|
56
56
|
- !ruby/object:Gem::Version
|
57
57
|
version: '4.0'
|
58
|
-
- -
|
58
|
+
- - ! '>='
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: 4.0.0
|
61
61
|
description: Rails Script is a Rails-centric, object oriented, featherweight framework
|
@@ -68,7 +68,7 @@ executables: []
|
|
68
68
|
extensions: []
|
69
69
|
extra_rdoc_files: []
|
70
70
|
files:
|
71
|
-
-
|
71
|
+
- .gitignore
|
72
72
|
- Gemfile
|
73
73
|
- LICENSE.txt
|
74
74
|
- README.md
|
@@ -88,6 +88,7 @@ files:
|
|
88
88
|
- lib/generators/rails_script/install/templates/base.js.coffee
|
89
89
|
- lib/generators/rails_script/install/templates/elements/.keep
|
90
90
|
- lib/generators/rails_script/install/templates/global.js.coffee
|
91
|
+
- lib/generators/rails_script/install/templates/rails_script.rb
|
91
92
|
- lib/generators/rails_script/install/templates/utilities/.keep
|
92
93
|
- lib/generators/rails_script/utility/USAGE
|
93
94
|
- lib/generators/rails_script/utility/templates/javascript.js.coffee
|
@@ -109,17 +110,17 @@ require_paths:
|
|
109
110
|
- lib
|
110
111
|
required_ruby_version: !ruby/object:Gem::Requirement
|
111
112
|
requirements:
|
112
|
-
- -
|
113
|
+
- - ! '>='
|
113
114
|
- !ruby/object:Gem::Version
|
114
115
|
version: '0'
|
115
116
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
117
|
requirements:
|
117
|
-
- -
|
118
|
+
- - ! '>='
|
118
119
|
- !ruby/object:Gem::Version
|
119
120
|
version: '0'
|
120
121
|
requirements: []
|
121
122
|
rubyforge_project:
|
122
|
-
rubygems_version: 2.
|
123
|
+
rubygems_version: 2.4.8
|
123
124
|
signing_key:
|
124
125
|
specification_version: 4
|
125
126
|
summary: A Rails-centric, object oriented, featherweight framework for writting CoffeeScript
|