rails_script 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d5b46f04cb39d9d79a4f57d88e536c2f2527b179
4
- data.tar.gz: 0a9f9c488c7d8c0a6afe31a4b9afd13b2f2d4cd5
3
+ metadata.gz: 42da47403244af3f7022e32f31a41c67d525fdce
4
+ data.tar.gz: 3b2997d390db2520b960d7e292e7c1fa98ba6e62
5
5
  SHA512:
6
- metadata.gz: d3a613986d7760ce2d3e60b5b604c7760fb0d02590ef46be91a6d3d737288cfdf255ef60a4440cb70644111fb56cc4605dc6b1cc8bee052d248184c40f8ab16e
7
- data.tar.gz: 142aab5ca3b550b0b95c0745743fc5f108213287efc22a35113ecc5dba75c2dfebf4edaa1d7faf4d7830f920d0d06677247ba62a91722bbd7101c8b885d93065
6
+ metadata.gz: a6259364d8b6cc1ff284c5d27e89b740ea3f1b5c40cf182e8324c41bc74e413f4ee0cd3efdf2440c6a45fde288211e378d65cb7f6fb8ff83234c42f2643a2d59
7
+ data.tar.gz: 7a62b691ae316b692452bc8fa136d831a8b6e242f03fed4c2946d1e5feef3ea370a6f94d5ca3f707f9c3b3ff93ffc17f161a022648af3ac0a464bc4649d673e6
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # RailsScript
1
+ # Rails Script
2
2
 
3
- TODO: Write a gem description
3
+ Rails Script is a Rails-centric, object oriented, featherweight framework for writting CoffeeScript. It is optomized 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 maintanable page specific JavaScript.
4
4
 
5
5
  ## Installation
6
6
 
@@ -11,14 +11,156 @@ Add this line to your application's Gemfile:
11
11
  And then execute:
12
12
 
13
13
  $ bundle
14
+
15
+ After bundling you need to run the initial installation generator:
14
16
 
15
- Or install it yourself as:
17
+ $ rails g rails_script:install
18
+
19
+ After the generator finishes, you will be prompted to add some JavaScript to your application layout. The code is responsible for initializing and call the action specific JavaScript. This snippet should be added before the closing body tag.
16
20
 
17
- $ gem install rails_script
21
+ For ERB:
22
+ ```
23
+ <script>
24
+ jQuery(function() {
25
+ window.$this = new (App.<%= controller_path.split(/\/|_/).map(&:capitalize).join('') %> || App.Base)();
26
+ if (typeof $this.<%= action_name %> === 'function') {
27
+ return $this.<%= action_name%>.call();
28
+ }
29
+ });
30
+ </script>
31
+ ```
32
+
33
+ For HAML:
34
+ ```
35
+ :javascript
36
+ jQuery(function() {
37
+ window.$this = new (App.#{controller_path.split(/\/|_/).map(&:capitalize).join('')} || App.Base)();
38
+ if (typeof $this.#{action_name} === 'function') {
39
+ return $this.#{action_name}.call();
40
+ }
41
+ });
42
+ ```
18
43
 
19
44
  ## Usage
20
45
 
21
- TODO: Write usage instructions here
46
+ ### Global Functions
47
+
48
+ 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.
49
+
50
+ ```
51
+ # app/assets/javascripts/global.js.coffee
52
+ window.App ||= {}
53
+
54
+ App.remoteSubmission = ($form, onCompleteCallBack) ->
55
+ $.ajax
56
+ url: $form.attr('action')
57
+ type: $form.attr('method')
58
+ data: $form.serialize()
59
+ dataType: 'json'
60
+ complete: (result) ->
61
+ onCompleteCallBack(result)
62
+
63
+ return
64
+ ```
65
+
66
+ Now you can access this function from anywhere in the application by just calling ```App.remoteSubmission($('#myForm'), alert('Hello'))```
67
+
68
+
69
+ ### Page Specific JavaScript
70
+
71
+ This is where things get even easier, 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. This means on ```Users#show``` we can submit that 'follow' request in the background like so:
72
+
73
+ ```
74
+ # app/assets/javascripts/users.js.coffee
75
+
76
+ window.App ||= {}
77
+ class App.Users extends App.Base
78
+
79
+ show: ->
80
+ App.remoteSubmission($('#follow-user-form'), alert('You are now following them!'))
81
+ ```
82
+
83
+
84
+ ### Controller Specific JavaScript
85
+
86
+ Executing some JavaScript to run on all controller actions is just a matter of adding it to the class contstructor. In the below example we will change the background color of the page for all actions in ```UsersController```.
87
+
88
+ ```
89
+ # app/assets/javascripts/users.js.coffee
90
+ window.App ||= {}
91
+ class App.Example extends App.Base
92
+
93
+ constructor: ->
94
+ super
95
+ $('body').css('background-color', 'yellow')
96
+ return this
97
+ ```
98
+
99
+ Note the call to ```super``` and the ```return this```, it is very important to keep these. If you wanted your Controller specific JavaScript to run before Application wide JavaScript, then you would call ```super``` just before ```return this```. Returning ```this``` allows the Application layout JavaScript to call the action specific functions.
100
+
101
+
102
+ ### Application Wide JavaScript
103
+
104
+ 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.
105
+
106
+ ```
107
+ # app/assets/javascripts/base.js.coffee
108
+ window.App ||= {}
109
+ class App.Base
110
+
111
+ constructor: ->
112
+ @footerRollover()
113
+ return this
114
+
115
+ footerRollover: ->
116
+ $(".site-credit a").hoverIntent(
117
+ over: ->
118
+ $(".site-credit a").html("<div class='maui-logo'></div>")
119
+ out: ->
120
+ $(".site-credit a").html("SITE CREDIT")
121
+ )
122
+ ```
123
+
124
+ 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 contructor.
125
+
126
+
127
+ ### Generating New Controllers
128
+
129
+ When a new controller is generated, the JavaScript asset file will be generated with Rails Script. However, if you need to manually generate a Rails Script controller you can use:
130
+
131
+ $ rails g rails_script:controller Some::NewController
132
+
133
+ Since the above example includes a namespace, it would generate:
134
+
135
+ ```
136
+ # app/assets/javascripts/some/new_controller.js.coffee
137
+
138
+ window.App ||= {}
139
+ class App.SomeNewController extends App.Base
140
+
141
+ constructor: ->
142
+ super
143
+ return this
144
+
145
+
146
+ index: ->
147
+ return
148
+
149
+
150
+ show: ->
151
+ return
152
+
153
+
154
+ new: ->
155
+ return
156
+
157
+
158
+ edit: ->
159
+ return
160
+ ```
161
+
162
+ None of the pre-defined functions are necessary, you can remove the ones you don't want.
163
+
22
164
 
23
165
  ## Contributing
24
166
 
@@ -26,18 +26,18 @@ In order to complete installation, you must add the following JavaScript snippet
26
26
 
27
27
  ERB:
28
28
  <script>
29
- jQuery(function() {
30
- window.$this = new (App.\#{controller_path.split(/\/|_/).map(&:capitalize).join('')} || App.Base)();
31
- if (typeof $this.\#{action_name} === 'function') {
32
- return $this.\#{action_name}.call();
29
+ jQuery(function() {
30
+ window.$this = new (App.<%= controller_path.split(/\\/|_/).map(&:capitalize).join('') %> || App.Base)();
31
+ if (typeof $this.<%= action_name %> === 'function') {
32
+ return $this.<%= action_name%>.call();
33
33
  }
34
- });
34
+ });
35
35
  </script>
36
36
 
37
37
  HAML:
38
38
  :javascript
39
39
  jQuery(function() {
40
- window.$this = new (App.\#{controller_path.split(/\/|_/).map(&:capitalize).join('')} || App.Base)();
40
+ window.$this = new (App.\#{controller_path.split(/\\/|_/).map(&:capitalize).join('')} || App.Base)();
41
41
  if (typeof $this.\#{action_name} === 'function') {
42
42
  return $this.\#{action_name}.call();
43
43
  }
@@ -1,3 +1,3 @@
1
1
  module RailsScript
2
- VERSION = "0.0.1"
2
+ VERSION = '0.0.2'
3
3
  end
@@ -1,5 +1,5 @@
1
1
  window.App ||= {}
2
- class App.<%= class_name %> extends App.Base
2
+ class App.<%= class_name %> extends App.Base
3
3
 
4
4
  constructor: ->
5
5
  super
data/rails_script.gemspec CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.version = RailsScript::VERSION
9
9
  spec.authors = ['Kevin Pheasey']
10
10
  spec.email = ['kevin.pheasey@gmail.com']
11
- spec.summary = %q{A CoffeeScript framework for the Rails asset pipeline.}
12
- spec.description = %q{A CoffeeScript framework for the Rails asset pipeline.}
11
+ spec.summary = %q{A Rails-centric, object oriented, featherweight framework for writting CoffeeScript}
12
+ 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
13
  spec.homepage = 'https://github.com/gemgento/rails_script'
14
14
  spec.license = 'MIT'
15
15
 
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ['lib']
20
20
 
21
21
  spec.add_development_dependency 'bundler', '~> 1.6'
22
- spec.add_development_dependency 'rake'
22
+ spec.add_development_dependency 'rake', '~> 0'
23
23
 
24
- spec.add_dependency 'coffee-rails', '~> 4.0.0'
24
+ spec.add_dependency 'coffee-rails', '~> 4.0', '>= 4.0.0'
25
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_script
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Pheasey
@@ -28,14 +28,14 @@ dependencies:
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
@@ -43,6 +43,9 @@ dependencies:
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.0'
48
+ - - ">="
46
49
  - !ruby/object:Gem::Version
47
50
  version: 4.0.0
48
51
  type: :runtime
@@ -50,9 +53,15 @@ dependencies:
50
53
  version_requirements: !ruby/object:Gem::Requirement
51
54
  requirements:
52
55
  - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '4.0'
58
+ - - ">="
53
59
  - !ruby/object:Gem::Version
54
60
  version: 4.0.0
55
- description: A CoffeeScript framework for the Rails asset pipeline.
61
+ description: Rails Script is a Rails-centric, object oriented, featherweight framework
62
+ for writting CoffeeScript. It is optomized for the Rails Asset Pipeline and is compatible
63
+ with TurboLinks. Using Rails controller names and actions to call JavaScript, it
64
+ has never been easier to write clean, concise, and maintanable page specific JavaScript.
56
65
  email:
57
66
  - kevin.pheasey@gmail.com
58
67
  executables: []
@@ -99,5 +108,5 @@ rubyforge_project:
99
108
  rubygems_version: 2.2.2
100
109
  signing_key:
101
110
  specification_version: 4
102
- summary: A CoffeeScript framework for the Rails asset pipeline.
111
+ summary: A Rails-centric, object oriented, featherweight framework for writting CoffeeScript
103
112
  test_files: []