Skip to content

Commit 2d68b7a

Browse files
committed
Merge pull request #13 from kpheasey/master
v1.0
2 parents c97922b + 54bee20 commit 2d68b7a

File tree

8 files changed

+10
-29
lines changed

8 files changed

+10
-29
lines changed

README.md

+6-14
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ RailsScript is a Rails-centric, object oriented, featherweight framework for wri
44

55
## Installation
66

7-
NOTE: RailsScript is not currently compatible with Turbolinks 5 (the Rails 5 default). This is becase inline JS is ignored. A future release will fix this issue.
8-
97
Add this line to your application's Gemfile:
108

119
gem 'rails_script', '~> 0.6.1'
@@ -38,7 +36,6 @@ Your JavaScript class is named after your Controller and there is a method for e
3836
```coffeescript
3937
# app/assets/javascripts/users.js.coffee
4038

41-
window.App ||= {}
4239
class App.Users extends App.Base
4340

4441
show: =>
@@ -53,7 +50,7 @@ Executing some JavaScript to run on all controller actions is just a matter of a
5350

5451
```coffeescript
5552
# app/assets/javascripts/users.js.coffee
56-
window.App ||= {}
53+
5754
class App.Users extends App.Base
5855

5956
beforeAction: (action) =>
@@ -70,7 +67,8 @@ Running some JavaScript on every page of an Application is a common need. For e
7067

7168
```coffeescript
7269
# app/assets/javascripts/base.js.coffee
73-
window.App ||= {}
70+
71+
...
7472
class App.Base
7573

7674
constructor: ->
@@ -84,6 +82,7 @@ class App.Base
8482
out: ->
8583
$(".site-credit a").html("SITE CREDIT")
8684
)
85+
...
8786
```
8887

8988
In this example we extracted the rollover action into a new function. Doing so will make the class cleaner and easier to maintain as the application grows. Once again note the ```return this``` in the constructor.
@@ -96,7 +95,6 @@ Any functions that need to be accessible in the global scope should be defined i
9695

9796
```coffeescript
9897
# app/assets/javascripts/global.js.coffee
99-
window.App ||= {}
10098

10199
App.remoteSubmission = ($form) ->
102100
return $.ajax
@@ -122,7 +120,7 @@ This will create the following in ```/app/assets/javascripts/utilities/modal.js.
122120

123121
```coffeescript
124122
# /app/assets/javascripts/utilities/modal.js.coffee
125-
window.Utility ||= {}
123+
126124
class Utility.Modal
127125

128126
constructor: ->
@@ -133,7 +131,7 @@ Let's add some basic functionality:
133131

134132
```coffeescript
135133
# /app/assets/javascripts/utilities/modal.js.coffee
136-
window.Utility ||= {}
134+
137135
class Utility.Modal
138136
isOpen: false
139137

@@ -164,7 +162,6 @@ Now, here's how we use the utility from ```users#show```
164162
```coffeescript
165163
# app/assets/javascripts/users.js.coffee
166164

167-
window.App ||= {}
168165
class App.Users extends App.Base
169166

170167
show: ->
@@ -187,7 +184,6 @@ This will create the following in ```/app/assets/javascripts/elements/main_menu.
187184
```coffeescript
188185
# /app/assets/javascripts/elements/main_menu.js.coffee```
189186

190-
window.Element ||= {}
191187
class Element.MainMenu
192188

193189
constructor: ->
@@ -199,7 +195,6 @@ We can now add all the logic for the main menu in a separate class and call it o
199195
```coffeescript
200196
# app/assets/javascripts/base.js.coffee
201197

202-
window.App ||= {}
203198
class App.Base
204199

205200
constructor: ->
@@ -220,7 +215,6 @@ Which generates:
220215
````coffeescript
221216
# /app/assets/javascripts/elements/main_menu.js.coffee
222217

223-
window.Element ||= {}
224218
class Element.MainMenu extends Utility.Modal
225219

226220
constructor: ->
@@ -284,7 +278,6 @@ Which generates:
284278
```coffeescript
285279
# /app/assets/javascripts/my/class_name.js.coffee
286280

287-
window.App ||= {}
288281
class App.MyClassName
289282

290283
constructor: ->
@@ -320,7 +313,6 @@ And here's how we print that data to the console on the ```users#index``` action
320313
```coffeescript
321314
# /app/assets/javascripts/users.js.coffee
322315

323-
window.App ||= {}
324316
class App.Users extends App.Base
325317

326318
index: =>

include_rails_script.js.coffee

-9
This file was deleted.

lib/generators/rails_script/class/templates/javascript.js.coffee

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
window.<%= RailsScript.app_namespace %> ||= {}
21
class <%= RailsScript.app_namespace %>.<%= class_name.gsub('::', '') %>
32

43
constructor: ->

lib/generators/rails_script/controller/templates/javascript.js.coffee

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
window.<%= RailsScript.app_namespace %> ||= {}
21
class <%= RailsScript.app_namespace %>.<%= controller.gsub('::', '') %> extends <%= RailsScript.app_namespace %>.Base
32

43
beforeAction: (action) =>

lib/generators/rails_script/install/templates/base.js.coffee

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ window.Element ||= {}
33
window.Utility ||= {}
44

55
$(document).on "turbolinks:load.rails_script", ->
6+
Utility.RailsVars = $('#rails-script').data('vars')
67
window.$this = new (<%= RailsScript.app_namespace %>["#{$('#rails-script').data('controller')}"] || <%= RailsScript.app_namespace %>.Base)()
78

89
class <%= RailsScript.app_namespace %>.Base
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
window.<%= RailsScript.app_namespace %> ||= {}

lib/rails_script/loader_helper.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module RailsScript
22
module LoaderHelper
33

44
def include_rails_script
5-
content_tag :div, nil, id: 'rails-script', data: { controller: controller_path.split(/\/|_/).map(&:capitalize).join('') }
5+
content_tag :div, nil, id: 'rails-script', data: { controller: controller_path.split(/\/|_/).map(&:capitalize).join(''), vars: @to_javascript.to_json }
66
end
77

88
end

rails_script.gemspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ Gem::Specification.new do |spec|
77
spec.name = 'rails_script'
88
spec.version = RailsScript::VERSION
99
spec.authors = ['Kevin Pheasey']
10-
spec.email = ['kevin.pheasey@gmail.com']
10+
spec.email = ['kevin@kpheasey.com']
1111
spec.summary = %q{A Rails-centric, object oriented, featherweight framework for writting CoffeeScript}
1212
spec.description = %q{Rails Script is a Rails-centric, object oriented, featherweight framework for writting CoffeeScript. It is optomized for the Rails Asset Pipeline and is compatible with TurboLinks. Using Rails controller names and actions to call JavaScript, it has never been easier to write clean, concise, and maintanable page specific JavaScript.}
13-
spec.homepage = 'https://github.com/gemgento/rails_script'
13+
spec.homepage = 'https://github.com/kpheasey/rails_script'
1414
spec.license = 'MIT'
1515

1616
spec.files = `git ls-files -z`.split("\u0000")

0 commit comments

Comments
 (0)