client_variable 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: 04b108517497bd64e9c3e19151c98b4f428bb5b5
4
- data.tar.gz: 7b976422e928a650392a40606537885bcb7e09b6
3
+ metadata.gz: 1b85d71ba87d5046e5f0417785e4f07a999ce8e9
4
+ data.tar.gz: 6702fc165ac316407db2c1eb0e1a2424c76fcd6a
5
5
  SHA512:
6
- metadata.gz: 323eb3e245c79a985a685130070a930434e230c5360c1d0f32792028b73b09fff468c737df84d0faf7a218b14e7359bffc8307909fdaab79cdb79ce9b93bda94
7
- data.tar.gz: 9e7b71aa97e6382596517f341d351188a615675747c69ce939bd274c4fd0ce6525039be2c81b80338571caa54e4953b63940a39a113f265710706cd477bc9790
6
+ metadata.gz: 6e075763da4abeb67738a3f7813e3bc7f3aab6f528290db65eccb983ab9f9508ee1eab2fd13c098fe02bb867d4f6dd3a30bde5938d5ffafb238a5168a0bf3752
7
+ data.tar.gz: 34552e0195ef3d3bbbcadc5fdd78b495e0a9b1f5c5c1a3c57d9db91987bee1b2782a0b81278a7b4fe157c2cdfdd60f021a914343e32d3e3dec1fedf81ddcff22
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/Gemfile CHANGED
@@ -1,4 +1,22 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in client_variable.gemspec
4
3
  gemspec
4
+
5
+ gem 'rails'
6
+
7
+ group :test do
8
+ gem 'coveralls', :require => false
9
+ gem 'rack-test'
10
+ gem 'rspec'
11
+ gem 'rspec-rails'
12
+ gem 'simplecov', :require => false
13
+ end
14
+
15
+ group :development, :test do
16
+ gem 'debugger'
17
+ gem 'pry'
18
+ gem 'pry-debugger'
19
+ gem 'pry-stack_explorer'
20
+ gem 'pry-rails'
21
+ gem 'pry-remote'
22
+ end
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # ClientVariable
2
2
 
3
- TODO: Write a gem description
3
+ exports your rails variables to client-side
4
4
 
5
5
  ## Installation
6
6
 
@@ -8,22 +8,51 @@ Add this line to your application's Gemfile:
8
8
 
9
9
  gem 'client_variable'
10
10
 
11
- And then execute:
11
+ After you install and add it to your Gemfile, you need to run the generator:
12
12
 
13
- $ bundle
13
+ rails g client_variable:install
14
14
 
15
- Or install it yourself as:
16
-
17
- $ gem install client_variable
15
+ It will create client_variable.yml in config folder, these variable in this file will be merged with variables defined through controller, exported to client-side
18
16
 
19
17
  ## Usage
20
18
 
21
- TODO: Write usage instructions here
22
-
23
- ## Contributing
24
-
25
- 1. Fork it
26
- 2. Create your feature branch (`git checkout -b my-new-feature`)
27
- 3. Commit your changes (`git commit -am 'Add some feature'`)
28
- 4. Push to the branch (`git push origin my-new-feature`)
29
- 5. Create new Pull Request
19
+ Add this line to `app/views/layouts/application.html.erb`
20
+
21
+ ``` erb
22
+ <head>
23
+ <title>some title</title>
24
+ <%= include_variable %>
25
+ <!-- include your action js code -->
26
+ ...
27
+ ```
28
+
29
+ Inspired from gon - https://github.com/gazay/gon, you can also do these in your controller
30
+
31
+ 1. Write variables by(change each request)
32
+
33
+ ```ruby
34
+ client.variable_name = variable_value
35
+
36
+ client.push({
37
+ :user_id => 1,
38
+ :user_role => "admin"
39
+ })
40
+ ```
41
+
42
+ 2. Or global
43
+ You can use client.global for sending your data to js from anywhere! It's really great for some init data.
44
+ ``` ruby
45
+ client.global.variable_name = variable_value
46
+ ```
47
+
48
+ Add this line on top of `app/assets/javascripts/application.js`
49
+ ``` js
50
+ //= require variable.js.erb
51
+ ```
52
+ I also define global variable in javascript `rails`
53
+ Access the varaibles from your JavaScript file:
54
+
55
+ ``` js
56
+ rails.set('a.b.c.d', '123') # rails.values => {a: {b: {c: {d: '123'}}}}
57
+ rails.get('a.b.c.d') # => '123'
58
+ ```
@@ -8,9 +8,9 @@ Gem::Specification.new do |spec|
8
8
  spec.version = ClientVariable::VERSION
9
9
  spec.authors = ["MQuy"]
10
10
  spec.email = ["sugiacupit@gmail.com"]
11
- spec.description = %q{export variable from rails}
11
+ spec.description = %q{export variable in rails to client-side}
12
12
  spec.summary = %q{variable rails in client}
13
- spec.homepage = ""
13
+ spec.homepage = "https://github.com/MQuy"
14
14
  spec.license = "MIT"
15
15
  spec.rubyforge_project = "client_variable"
16
16
 
@@ -1,4 +1,5 @@
1
- require "client_variable/version"
1
+ require 'client_variable/version'
2
+ require 'rails/engine'
2
3
 
3
4
  module Client
4
5
  class Variable
@@ -23,6 +24,14 @@ module Client
23
24
  Request.clear
24
25
  end
25
26
 
27
+ def push(data = {})
28
+ raise "Object must have each_pair method" unless data.respond_to? :each_pair
29
+
30
+ data.each_pair do |name, value|
31
+ set_variable(name.to_s, value)
32
+ end
33
+ end
34
+
26
35
  def method_missing(method, *args, &block)
27
36
  if ( method.to_s =~ /=$/ )
28
37
  if public_methods? method
@@ -37,8 +46,8 @@ module Client
37
46
  end
38
47
 
39
48
  def self.generate
40
- data = YAML.load(ERB.new(File.new("#{Rails.root}/config/client_variable.yml").read).result)[Rails.env]
41
- data.merge([Global.values, Request.values].inject(:merge)).to_json
49
+ data = YAML.load(ERB.new(File.new("#{Rails.root}/config/client_variable.yml").read).result)
50
+ data[Rails.env].to_json
42
51
  end
43
52
 
44
53
  class Engine < ::Rails::Engine; end
@@ -1,3 +1,6 @@
1
+ require 'action_view'
2
+ require 'action_controller'
3
+
1
4
  module Client
2
5
  module Helpers
3
6
  module View
@@ -1,3 +1,3 @@
1
1
  module ClientVariable
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,4 @@
1
+ require "spec_helper"
2
+
3
+ describe Client do
4
+ end
@@ -0,0 +1,23 @@
1
+ require 'simplecov'
2
+ require 'coveralls'
3
+
4
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
5
+ SimpleCov::Formatter::HTMLFormatter,
6
+ Coveralls::SimpleCov::Formatter
7
+ ]
8
+ SimpleCov.start
9
+
10
+ require 'rspec'
11
+ require 'client_variable'
12
+
13
+ RSpec.configure do |config|
14
+ config.treat_symbols_as_metadata_keys_with_true_values = true
15
+ config.run_all_when_everything_filtered = true
16
+ config.filter_run :focus
17
+
18
+ # Run specs in random order to surface order dependencies. If you find an
19
+ # order dependency and want to debug it, you can fix the order by providing
20
+ # the seed, which is printed after each run.
21
+ # --seed 1234
22
+ config.order = 'random'
23
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: client_variable
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
  - MQuy
@@ -38,7 +38,7 @@ dependencies:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- description: export variable from rails
41
+ description: export variable in rails to client-side
42
42
  email:
43
43
  - sugiacupit@gmail.com
44
44
  executables: []
@@ -46,6 +46,7 @@ extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
48
  - .gitignore
49
+ - .rspec
49
50
  - Gemfile
50
51
  - LICENSE.txt
51
52
  - README.md
@@ -59,8 +60,10 @@ files:
59
60
  - lib/client_variable/version.rb
60
61
  - lib/generators/client_variable/install/install_generator.rb
61
62
  - lib/generators/client_variable/install/templates/config.yml
63
+ - spec/client_variable_spec.rb
64
+ - spec/spec_helper.rb
62
65
  - vendor/assets/javascripts/variable.js.erb
63
- homepage: ''
66
+ homepage: https://github.com/MQuy
64
67
  licenses:
65
68
  - MIT
66
69
  metadata: {}
@@ -84,4 +87,6 @@ rubygems_version: 2.1.3
84
87
  signing_key:
85
88
  specification_version: 4
86
89
  summary: variable rails in client
87
- test_files: []
90
+ test_files:
91
+ - spec/client_variable_spec.rb
92
+ - spec/spec_helper.rb