gon 0.3.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of gon might be problematic. Click here for more details.

data/README.md CHANGED
@@ -21,9 +21,15 @@ In action of your controller you put something like this:
21
21
  @your_array = [1,2]
22
22
  @your_hash = {'a' => 1, 'b' => 2}
23
23
  Gon.your_int = @your_int
24
- Gon.your_other_int = 345 + @your_int
24
+ Gon.your_other_int = 345 + Gon.your_int
25
25
  Gon.your_array = @your_array
26
+ Gon.your_array << Gon.your_int
26
27
  Gon.your_hash = @your_hash
28
+
29
+ Gon.all_variables # > {:your_int => 123, :your_other_int => 468, :your_array => [1, 2, 123], :your_hash => {'a' => 1, 'b' => 2}}
30
+ Gon.your_array # > [1, 2, 123]
31
+
32
+ Gon.clear # Gon.all_variables now is {}
27
33
  ```
28
34
 
29
35
  In javascript file for view of this action write call to your variable:
@@ -40,13 +46,13 @@ alert(Gon.your_hash)
40
46
  Puts this line into `Gemfile` then run `$ bundle`:
41
47
 
42
48
  ``` ruby
43
- gem 'gon', '0.3.0'
49
+ gem 'gon', '1.0.0'
44
50
  ```
45
51
 
46
52
  Or if you are old-school Rails 2 developer put this into `config/environment.rb` and run `$ rake gems:install`:
47
53
 
48
54
  ``` ruby
49
- config.gem 'gon', :version => '0.3.0'
55
+ config.gem 'gon', :version => '1.0.0'
50
56
  ```
51
57
 
52
58
  Or manually install gon gem: `$ gem install gon`
data/lib/gon.rb CHANGED
@@ -1,18 +1,14 @@
1
1
  require 'action_view'
2
2
  require 'gon/helpers'
3
+ require 'ostruct'
3
4
 
4
- module Gon
5
- def self.method_missing(m, *args, &block)
6
- gon_variables(m.to_s, args[0])
5
+ Gon = OpenStruct.new
6
+
7
+ class << Gon
8
+ def all_variables
9
+ instance_variable_get :@table
7
10
  end
8
-
9
- def self.gon_variables(name=nil, value=nil)
10
- data = Rails.cache.read('gon_variables') || {}
11
-
12
- new_data = {}
13
- new_data[name] = value if name && value
14
-
15
- Rails.cache.delete('gon_variables')
16
- Rails.cache.write('gon_variables', (new_data.reverse_merge data))
11
+ def clear
12
+ instance_variable_set :@table, {}
17
13
  end
18
14
  end
data/lib/gon/helpers.rb CHANGED
@@ -6,11 +6,11 @@ module Gon
6
6
 
7
7
  module InstanceMethods
8
8
  def include_gon
9
- data = Rails.cache.read('gon_variables') || {}
9
+ data = Gon.all_variables || {}
10
10
 
11
11
  script = "<script>window.Gon = {};"
12
12
  data.each do |key, val|
13
- script += "Gon." + key.to_s + val.to_json + ";"
13
+ script += "Gon." + key.to_s + '=' + val.to_json + ";"
14
14
  end
15
15
  script += "</script>"
16
16
  script.html_safe
data/lib/gon/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Gon
2
- VERSION = '0.3.0'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -0,0 +1,35 @@
1
+ # gon_spec_rb
2
+ require 'gon'
3
+
4
+ describe Gon, '#all_variables' do
5
+ it 'returns all variables in hash' do
6
+ Gon.a = 1
7
+ Gon.b = 2
8
+ Gon.c = Gon.a + Gon.b
9
+ Gon.c.should == 3
10
+ Gon.all_variables.should == {:a => 1, :b => 2, :c => 3}
11
+ end
12
+
13
+ it 'supports all data types' do
14
+ Gon.clear
15
+ Gon.int = 1
16
+ Gon.float = 1.1
17
+ Gon.string = 'string'
18
+ Gon.array = [ 1, 'string' ]
19
+ Gon.hash = { :a => 1, :b => '2'}
20
+ Gon.hash_w_array = { :a => [ 2, 3 ] }
21
+ Gon.klass = OpenStruct.new
22
+
23
+ ActionView::Base.instance_methods.include?('include_gon').should == true
24
+ base = ActionView::Base.new
25
+ base.include_gon.should == "<script>window.Gon = {};" +
26
+ "Gon.klass={\"table\":{}};" +
27
+ "Gon.string=\"string\";" +
28
+ "Gon.array=[1,\"string\"];" +
29
+ "Gon.float=1.1;" +
30
+ "Gon.int=1;" +
31
+ "Gon.hash={\"a\":1,\"b\":\"2\"};" +
32
+ "Gon.hash_w_array={\"a\":[2,3]};" +
33
+ "</script>"
34
+ end
35
+ end
metadata CHANGED
@@ -1,25 +1,33 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: gon
3
- version: !ruby/object:Gem::Version
4
- version: 0.3.0
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
5
  prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - gazay
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2011-06-23 00:00:00.000000000 %:z
13
- default_executable:
17
+
18
+ date: 2011-06-24 00:00:00 Z
14
19
  dependencies: []
15
- description: If you need to send some data to your js files and you don't want to
16
- do this with long way trough views and parsing - use this force!
17
- email:
20
+
21
+ description: If you need to send some data to your js files and you don't want to do this with long way trough views and parsing - use this force!
22
+ email:
18
23
  - alex.gaziev@gmail.com
19
24
  executables: []
25
+
20
26
  extensions: []
27
+
21
28
  extra_rdoc_files: []
22
- files:
29
+
30
+ files:
23
31
  - .gitignore
24
32
  - Gemfile
25
33
  - README.md
@@ -28,29 +36,39 @@ files:
28
36
  - lib/gon.rb
29
37
  - lib/gon/helpers.rb
30
38
  - lib/gon/version.rb
31
- has_rdoc: true
32
- homepage: ''
39
+ - spec/gon/gon_spec.rb
40
+ homepage: ""
33
41
  licenses: []
42
+
34
43
  post_install_message:
35
44
  rdoc_options: []
36
- require_paths:
45
+
46
+ require_paths:
37
47
  - lib
38
- required_ruby_version: !ruby/object:Gem::Requirement
48
+ required_ruby_version: !ruby/object:Gem::Requirement
39
49
  none: false
40
- requirements:
41
- - - ! '>='
42
- - !ruby/object:Gem::Version
43
- version: '0'
44
- required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ hash: 3
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
58
  none: false
46
- requirements:
47
- - - ! '>='
48
- - !ruby/object:Gem::Version
49
- version: '0'
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 3
63
+ segments:
64
+ - 0
65
+ version: "0"
50
66
  requirements: []
67
+
51
68
  rubyforge_project: gon
52
- rubygems_version: 1.6.2
69
+ rubygems_version: 1.7.2
53
70
  signing_key:
54
71
  specification_version: 3
55
72
  summary: Get your Rails variables in your JS
56
- test_files: []
73
+ test_files:
74
+ - spec/gon/gon_spec.rb