rails_script 1.0.0 → 2.0.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 +8 -8
- data/README.md +6 -5
- data/app/assets/javascripts/base.coffee +23 -0
- data/{lib/generators/rails_script/install/templates → app/assets/javascripts}/elements/.keep +0 -0
- data/{lib/generators/rails_script/install/templates/global.js.coffee → app/assets/javascripts/global.coffee} +0 -0
- data/app/assets/javascripts/rails_script.coffee +4 -0
- data/{lib/generators/rails_script/install/templates → app/assets/javascripts}/utilities/.keep +0 -0
- data/lib/generators/rails_script/class/templates/javascript.js.coffee +1 -1
- data/lib/generators/rails_script/controller/templates/javascript.js.coffee +1 -1
- data/lib/generators/rails_script/element/element_generator.rb +1 -1
- data/lib/generators/rails_script/install/install_generator.rb +7 -13
- data/lib/rails_script.rb +2 -6
- data/lib/rails_script/engine.rb +4 -0
- data/lib/rails_script/loader_helper.rb +5 -1
- data/lib/rails_script/version.rb +1 -1
- data/lib/templates/coffee/assets/{javascript.js.coffee → javascript.coffee} +0 -0
- data/vendor/assets/javascripts/rails_script/init.coffee +25 -0
- metadata +10 -8
- data/lib/generators/rails_script/install/templates/base.js.coffee +0 -45
- data/lib/generators/rails_script/install/templates/rails_script.rb +0 -4
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NWZmNTVhNzNhMDMzMmE1MzZjYmQ1OTRmNTU4ZmUzMWFhYzgxMjJiNQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MjI1ZjYwNmNkNjM0NjEwYmQwZTdmYjkwMTMzYmUxNDE2MTdhZWE5ZQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NDE2MWI4YjI1N2EwYmFhOTRlN2Q3NzBmN2FkNmE3ZTk5ZTgwZTNiMzNjMTAw
|
10
|
+
NjVkY2Y5M2RhZWEyZmU0ZWY0NGIwNDVkMTEyNDJhNzA4YWNmN2VlZjFlNDRm
|
11
|
+
MGYyNThjMGVhZWEyODA3ZjljNmY4OWY1NDdhYzg2M2VkNmY2MTU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OWM1MmQwYzBlZTZiNWM5ZDg3YmVlNTQ0ODAzODZiYjIzZmVjYTIzZGM2ODI2
|
14
|
+
OWQ4ZGFiOGE3NDI5MWI3YTRkNzE0MTVjZjAzZTI4OGJiMDM3MmViMGIzMmQ5
|
15
|
+
NTVmZDhjZWQxMzVkYmY1MTc3ZTM0NTA1NGE3NDE4OGJiM2JiMjM=
|
data/README.md
CHANGED
@@ -2,11 +2,15 @@
|
|
2
2
|
|
3
3
|
RailsScript is a Rails-centric, object oriented, featherweight framework for writing CoffeeScript. It is optimized for the [Rails Asset Pipeline](http://guides.rubyonrails.org/asset_pipeline.html) and is compatible with [TurboLinks](https://github.com/rails/turbolinks). Using Rails controller names and actions to call JavaScript, it has never been easier to write clean, concise, and maintainable page specific JavaScript.
|
4
4
|
|
5
|
+
## Upgrading to V2
|
6
|
+
|
7
|
+
To migrate from version 0.x to 1.x, please see the wiki; https://github.com/gemgento/rails_script/wiki/v2-Migration
|
8
|
+
|
5
9
|
## Installation
|
6
10
|
|
7
11
|
Add this line to your application's Gemfile:
|
8
12
|
|
9
|
-
gem 'rails_script', '~> 0
|
13
|
+
gem 'rails_script', '~> 2.0'
|
10
14
|
|
11
15
|
And then execute:
|
12
16
|
|
@@ -24,9 +28,6 @@ After the generator finishes, you will be prompted to add helper call to your ap
|
|
24
28
|
|
25
29
|
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
30
|
|
27
|
-
## Configuration
|
28
|
-
You can configure name of your application in config/initializers/rails_script.rb file.
|
29
|
-
|
30
31
|
## Usage
|
31
32
|
|
32
33
|
### Page (Action) Specific JavaScript
|
@@ -227,7 +228,7 @@ Inheritance from the generator can only come from a Utility class. Any class yo
|
|
227
228
|
|
228
229
|
### Custom Controllers
|
229
230
|
|
230
|
-
When a new controller is generated, the JavaScript asset file will be generated with
|
231
|
+
When a new controller is generated, the JavaScript asset file will be generated with App. However, if you need to manually generate a RailsScript controller you can use:
|
231
232
|
|
232
233
|
$ rails g rails_script:controller Some::NewController
|
233
234
|
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class App.Base
|
2
|
+
|
3
|
+
constructor: ->
|
4
|
+
if (window.jQuery) then RailsScript.setClearEventHandlers() # clearing application event handlers only possible with jQuery
|
5
|
+
return this
|
6
|
+
|
7
|
+
|
8
|
+
###
|
9
|
+
Run the new action for the create action. Generally the create action will 'render :new' if there was a problem.
|
10
|
+
This prevents doubling the code for each action.
|
11
|
+
###
|
12
|
+
create: ->
|
13
|
+
if typeof $this.new == 'function'
|
14
|
+
return $this.new()
|
15
|
+
|
16
|
+
|
17
|
+
###
|
18
|
+
Run the edit action for the update action. Generally the update action will 'render :edit' if there was a problem.
|
19
|
+
This prevents doubling the code for each action.
|
20
|
+
###
|
21
|
+
update: ->
|
22
|
+
if typeof $this.edit == 'function'
|
23
|
+
return $this.edit()
|
data/{lib/generators/rails_script/install/templates → app/assets/javascripts}/elements/.keep
RENAMED
File without changes
|
File without changes
|
data/{lib/generators/rails_script/install/templates → app/assets/javascripts}/utilities/.keep
RENAMED
File without changes
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module RailsScript
|
2
2
|
module Generators
|
3
3
|
class ElementGenerator < ::Rails::Generators::Base
|
4
|
-
source_root File.expand_path(
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
5
5
|
argument :element_name, type: :string
|
6
6
|
argument :utility, type: :string, default: ''
|
7
7
|
|
@@ -1,34 +1,28 @@
|
|
1
1
|
module RailsScript
|
2
2
|
module Generators
|
3
3
|
class InstallGenerator < ::Rails::Generators::Base
|
4
|
-
source_root File.expand_path("
|
4
|
+
source_root File.expand_path("../../../../../app/assets/javascripts", __FILE__)
|
5
5
|
|
6
6
|
def copy_files
|
7
|
-
template 'base.
|
8
|
-
template 'global.
|
9
|
-
template 'rails_script.rb', 'config/initializers/rails_script.rb'
|
10
|
-
end
|
11
|
-
|
12
|
-
def create_directories
|
13
|
-
directory 'utilities/', 'app/assets/javascripts/utilities'
|
14
|
-
directory 'elements/', 'app/assets/javascripts/elements'
|
7
|
+
template 'base.coffee', 'app/assets/javascripts/base.coffee'
|
8
|
+
template 'global.coffee', 'app/assets/javascripts/global.coffee'
|
15
9
|
end
|
16
10
|
|
17
11
|
def insert_load_order
|
18
12
|
if File.exist?('app/assets/javascripts/application.js')
|
19
13
|
|
20
14
|
if File.readlines('app/assets/javascripts/application.js').grep('//= require_tree .').any?
|
21
|
-
inject_into_file 'app/assets/javascripts/application.js', "
|
15
|
+
inject_into_file 'app/assets/javascripts/application.js', "//= require rails_script\n", before: '//= require_tree .'
|
22
16
|
else
|
23
|
-
append_file 'app/assets/javascripts/application.js', "\n//= require
|
17
|
+
append_file 'app/assets/javascripts/application.js', "\n//= require rails_script"
|
24
18
|
end
|
25
19
|
|
26
20
|
elsif File.exist?('app/assets/javascripts/application.js.coffee')
|
27
21
|
|
28
22
|
if File.readlines('app/assets/javascripts/application.js.coffee').grep('#= require_tree .').any?
|
29
|
-
inject_into_file 'app/assets/javascripts/application.js.coffee', "
|
23
|
+
inject_into_file 'app/assets/javascripts/application.js.coffee', "#= require rails_script\n", before: '#= require_tree .'
|
30
24
|
else
|
31
|
-
append_file 'app/assets/javascripts/application.js.coffee', "\n#= require
|
25
|
+
append_file 'app/assets/javascripts/application.js.coffee', "\n#= require rails_script"
|
32
26
|
end
|
33
27
|
end
|
34
28
|
end
|
data/lib/rails_script.rb
CHANGED
@@ -1,13 +1,9 @@
|
|
1
1
|
require 'rails_script/version'
|
2
|
+
require 'rails_script/engine'
|
2
3
|
require 'rails_script/loader_helper'
|
3
4
|
require 'rails_script/to_javascript'
|
4
5
|
require 'rails_script/railtie' if defined?(Rails)
|
5
6
|
|
6
7
|
module RailsScript
|
7
|
-
|
8
|
-
@@app_namespace = 'App'
|
9
|
-
|
10
|
-
def self.config
|
11
|
-
yield self
|
12
|
-
end
|
8
|
+
|
13
9
|
end
|
@@ -2,7 +2,11 @@ module RailsScript
|
|
2
2
|
module LoaderHelper
|
3
3
|
|
4
4
|
def include_rails_script
|
5
|
-
content_tag :div, nil, id: 'rails-script', data: {
|
5
|
+
content_tag :div, nil, id: 'rails-script', data: {
|
6
|
+
controller: controller_path.split(/\/|_/).map(&:capitalize).join(''),
|
7
|
+
action: action_name,
|
8
|
+
vars: @to_javascript.to_json
|
9
|
+
}
|
6
10
|
end
|
7
11
|
|
8
12
|
end
|
data/lib/rails_script/version.rb
CHANGED
File without changes
|
@@ -0,0 +1,25 @@
|
|
1
|
+
window.RailsScript ||= {}
|
2
|
+
window.App ||= {}
|
3
|
+
window.Element ||= {}
|
4
|
+
window.Utility ||= {}
|
5
|
+
|
6
|
+
$(document).on "turbolinks:load.rails_script", ->
|
7
|
+
Utility.RailsVars = $('#rails-script').data('vars')
|
8
|
+
window.$this = new (App["#{$('#rails-script').data('controller')}"] || App.Base)()
|
9
|
+
|
10
|
+
action = $('#rails-script').data('action')
|
11
|
+
|
12
|
+
if typeof $this.beforeAction == 'function'
|
13
|
+
$this.beforeAction action
|
14
|
+
if typeof $this[action] == 'function'
|
15
|
+
$this[action]()
|
16
|
+
if typeof $this.afterAction == 'function'
|
17
|
+
$this.afterAction action
|
18
|
+
|
19
|
+
RailsScript.setClearEventHandlers = ->
|
20
|
+
jQuery(document).on 'turbolinks:before-visit', ->
|
21
|
+
for element in [window, document]
|
22
|
+
for event, handlers of (jQuery._data(element, 'events') || {})
|
23
|
+
for handler in handlers
|
24
|
+
if handler? && handler.namespace == ''
|
25
|
+
jQuery(element).off event, handler.handler
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_script
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.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: 2016-05-
|
11
|
+
date: 2016-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -73,6 +73,11 @@ files:
|
|
73
73
|
- LICENSE.txt
|
74
74
|
- README.md
|
75
75
|
- Rakefile
|
76
|
+
- app/assets/javascripts/base.coffee
|
77
|
+
- app/assets/javascripts/elements/.keep
|
78
|
+
- app/assets/javascripts/global.coffee
|
79
|
+
- app/assets/javascripts/rails_script.coffee
|
80
|
+
- app/assets/javascripts/utilities/.keep
|
76
81
|
- lib/generators/rails_script/class/USAGE
|
77
82
|
- lib/generators/rails_script/class/class_generator.rb
|
78
83
|
- lib/generators/rails_script/class/templates/javascript.js.coffee
|
@@ -84,21 +89,18 @@ files:
|
|
84
89
|
- lib/generators/rails_script/element/templates/javascript.js.coffee
|
85
90
|
- lib/generators/rails_script/install/USAGE
|
86
91
|
- lib/generators/rails_script/install/install_generator.rb
|
87
|
-
- lib/generators/rails_script/install/templates/base.js.coffee
|
88
|
-
- lib/generators/rails_script/install/templates/elements/.keep
|
89
|
-
- lib/generators/rails_script/install/templates/global.js.coffee
|
90
|
-
- lib/generators/rails_script/install/templates/rails_script.rb
|
91
|
-
- lib/generators/rails_script/install/templates/utilities/.keep
|
92
92
|
- lib/generators/rails_script/utility/USAGE
|
93
93
|
- lib/generators/rails_script/utility/templates/javascript.js.coffee
|
94
94
|
- lib/generators/rails_script/utility/utility_generator.rb
|
95
95
|
- lib/rails_script.rb
|
96
|
+
- lib/rails_script/engine.rb
|
96
97
|
- lib/rails_script/loader_helper.rb
|
97
98
|
- lib/rails_script/railtie.rb
|
98
99
|
- lib/rails_script/to_javascript.rb
|
99
100
|
- lib/rails_script/version.rb
|
100
|
-
- lib/templates/coffee/assets/javascript.
|
101
|
+
- lib/templates/coffee/assets/javascript.coffee
|
101
102
|
- rails_script.gemspec
|
103
|
+
- vendor/assets/javascripts/rails_script/init.coffee
|
102
104
|
homepage: https://github.com/kpheasey/rails_script
|
103
105
|
licenses:
|
104
106
|
- MIT
|
@@ -1,45 +0,0 @@
|
|
1
|
-
window.<%= RailsScript.app_namespace %> ||= {}
|
2
|
-
window.Element ||= {}
|
3
|
-
window.Utility ||= {}
|
4
|
-
|
5
|
-
$(document).on "turbolinks:load.rails_script", ->
|
6
|
-
Utility.RailsVars = $('#rails-script').data('vars')
|
7
|
-
window.$this = new (<%= RailsScript.app_namespace %>["#{$('#rails-script').data('controller')}"] || <%= RailsScript.app_namespace %>.Base)()
|
8
|
-
|
9
|
-
class <%= RailsScript.app_namespace %>.Base
|
10
|
-
|
11
|
-
constructor: ->
|
12
|
-
if (window.jQuery) then @setClearEventHandlers() # clearing application event handlers only possible with jQuery
|
13
|
-
return this
|
14
|
-
|
15
|
-
|
16
|
-
###
|
17
|
-
Run the new action for the create action. Generally the create action will 'render :new' if there was a problem.
|
18
|
-
This prevents doubling the code for each action.
|
19
|
-
###
|
20
|
-
create: ->
|
21
|
-
if typeof $this.new == 'function'
|
22
|
-
return $this.new()
|
23
|
-
|
24
|
-
|
25
|
-
###
|
26
|
-
Run the edit action for the update action. Generally the update action will 'render :edit' if there was a problem.
|
27
|
-
This prevents doubling the code for each action.
|
28
|
-
###
|
29
|
-
update: ->
|
30
|
-
if typeof $this.edit == 'function'
|
31
|
-
return $this.edit()
|
32
|
-
|
33
|
-
|
34
|
-
###
|
35
|
-
Clear event handlers with a blank namespace. This will prevent window and document event handlers from stacking
|
36
|
-
when each new page is fetched. Adding a namespace to your events will prevent them from being removed between page
|
37
|
-
loads, i.e. "$(window).on 'scroll.app', myHandler"
|
38
|
-
###
|
39
|
-
setClearEventHandlers: ->
|
40
|
-
jQuery(document).on 'page:before-change', ->
|
41
|
-
for element in [window, document]
|
42
|
-
for event, handlers of (jQuery._data(element, 'events') || {})
|
43
|
-
for handler in handlers
|
44
|
-
if handler? && handler.namespace == ''
|
45
|
-
jQuery(element).off event, handler.handler
|