rails_script 0.3.2 → 0.4.0

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: e992abc59f4c61c61138d81747fd2f696d9eeb15
4
- data.tar.gz: e4f9ac79d9c520704107e873b2c5a1c42e2a0fc4
3
+ metadata.gz: 99e3ac859df56f6a1a24fcbcd60435ada0577b51
4
+ data.tar.gz: ec0d4b0d33619c34f668098177680e75ca149305
5
5
  SHA512:
6
- metadata.gz: e20b7739f2d1fb925de399d8ef56b970bd3ddbb0ef462692c26216b53b36815580bd234b775066b46a16ce65ad1859897bb5d448b10bae130de27c81362dc117
7
- data.tar.gz: 7b5c16458e222262e61e0f30f89e75fcd517535ba7694dd3dbba31f544e13a420bf23d30afe6d8e152472a79f955d94763b4fa503076947469ca8c4957f5f8e5
6
+ metadata.gz: d3b15d6077dc2e6a4276270a3b679bf66f2f1bb096342addcd425e9dae5c566c13bbdc6008f09baf9e456d4751452cb4982e2553f278071c6f764249838a97b0
7
+ data.tar.gz: 9772fc2344739626aff3c045254238eb1145aa38e5b56ca2594b977ad7514a5b2a2cc7a638cad2d7f814d484a11cbc439bc00d098372688b90e03dc7f456b5d0
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.3.1'
9
+ gem 'rails_script', '~> 0.3.2'
10
10
 
11
11
  And then execute:
12
12
 
@@ -282,9 +282,9 @@ class App.MyClassName
282
282
 
283
283
  ### Passing Rails Variables
284
284
 
285
- To pass data from Rails to JavaScript, just define ```@to_javascript```. This is then converted to a JSON object with ```@to_javascript.to_json``` and can be accessed with ```Utility.RailsVars```.
285
+ To pass data from Rails to JavaScript, just call ```to_javascript``` with your data. This is then converted to a JSON object with ```to_javascript.to_json``` and can be accessed with ```Utility.RailsVars```.
286
286
 
287
- Here's an example where ```@to_javascript``` is used in a ```before_filter``` to pass the current user and their friends:
287
+ Here's an example where ```to_javascript``` is used in a ```before_filter``` to pass the current user and their friends:
288
288
  ```
289
289
  # /app/controllers/application_controller.rb
290
290
 
@@ -295,7 +295,7 @@ class ApplicationController
295
295
  private
296
296
 
297
297
  def set_javascript_vars
298
- @to_javascript = { user: current_user, friends: current_user.friends }
298
+ to_javascript user: current_user, friends: current_user.friends
299
299
  end
300
300
 
301
301
  end
@@ -1,5 +1,6 @@
1
1
  require 'rails_script/version'
2
2
  require 'rails_script/loader_helper'
3
+ require 'rails_script/to_javascript'
3
4
  require 'rails_script/railtie' if defined?(Rails)
4
5
 
5
6
  module RailsScript
@@ -7,5 +7,10 @@ module RailsScript
7
7
  initializer 'rails_Script.loader_helper' do
8
8
  ActionView::Base.send :include, LoaderHelper
9
9
  end
10
+
11
+ initializer 'rails_script.to_javascript' do
12
+ ActionController::Base.send :include, ToJavascript
13
+ end
14
+
10
15
  end
11
16
  end
@@ -0,0 +1,16 @@
1
+ module RailsScript
2
+ module ToJavascript
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ before_action do
7
+ @to_javascript = {}
8
+ end
9
+ end
10
+
11
+ def to_javascript(variables = {})
12
+ @to_javascript.merge!(variables)
13
+ end
14
+
15
+ end
16
+ end
@@ -1,3 +1,3 @@
1
1
  module RailsScript
2
- VERSION = '0.3.2'
2
+ VERSION = '0.4.0'
3
3
  end
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: 0.3.2
4
+ version: 0.4.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: 2014-10-24 00:00:00.000000000 Z
11
+ date: 2014-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -95,6 +95,7 @@ files:
95
95
  - lib/rails_script.rb
96
96
  - lib/rails_script/loader_helper.rb
97
97
  - lib/rails_script/railtie.rb
98
+ - lib/rails_script/to_javascript.rb
98
99
  - lib/rails_script/version.rb
99
100
  - lib/templates/coffee/assets/javascript.js.coffee
100
101
  - rails_script.gemspec