gon-sinatra 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +7 -7
- data/LICENSE +9 -0
- data/README.md +4 -12
- data/lib/gon/sinatra/helpers.rb +8 -6
- data/lib/gon/sinatra/store.rb +6 -7
- data/lib/gon/sinatra/version.rb +1 -1
- data/spec/gon/gon_spec.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48a929a541425dc61a6e8ec572c62caa66056394
|
4
|
+
data.tar.gz: add74e37966566d93edc8fbea0ea5464a81b2446
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48f28ad1e81c047f64281af6c183048f5a9191be772adadebf2eb1c726dfe3abc59c5b5f4af313a7e3999f92ebf6998efe7b483857a9eebf35de384dda3046da
|
7
|
+
data.tar.gz: f0382c08e607372cd121c26b9bc1b4c17affe38eb04a266e09843029991a335ddfbea63afd119489bf74e135b2c6b116a96175c79bb5d4aac633f589ce211442
|
data/.travis.yml
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
- 1.8.7
|
4
|
-
- 1.9.2
|
5
3
|
- 1.9.3
|
6
|
-
-
|
4
|
+
- 2.0.0
|
5
|
+
- 2.1.0
|
6
|
+
- 2.1.4
|
7
7
|
- jruby-19mode # JRuby in 1.9 mode
|
8
|
-
- rbx
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
- rbx
|
9
|
+
matrix:
|
10
|
+
allow_failures:
|
11
|
+
- rvm: rbx
|
data/LICENSE
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2014 gazay
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
6
|
+
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
8
|
+
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -10,6 +10,10 @@ Now with [Padrino](https://github.com/padrino/padrino-framework) support as well
|
|
10
10
|
|
11
11
|
For rails use [gon](https://github.com/gazay/gon).
|
12
12
|
|
13
|
+
<a href="https://evilmartians.com/?utm_source=gon-sinatra">
|
14
|
+
<img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" alt="Sponsored by Evil Martians" width="236" height="54">
|
15
|
+
</a>
|
16
|
+
|
13
17
|
## Usage
|
14
18
|
|
15
19
|
`my_sinatra_application.rb`
|
@@ -205,15 +209,3 @@ require 'gon-sinatra'
|
|
205
209
|
* @skade
|
206
210
|
|
207
211
|
Special thanks to @brainopia, @kossnocorp and @ai.
|
208
|
-
|
209
|
-
## License
|
210
|
-
|
211
|
-
The MIT License
|
212
|
-
|
213
|
-
Copyright (c) 2014 gazay
|
214
|
-
|
215
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
216
|
-
|
217
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
218
|
-
|
219
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/gon/sinatra/helpers.rb
CHANGED
@@ -2,32 +2,34 @@ require 'json'
|
|
2
2
|
|
3
3
|
module Gon
|
4
4
|
module Sinatra
|
5
|
+
|
5
6
|
module Helpers
|
6
7
|
def include_gon(options = {})
|
7
8
|
return '' if gon.all_variables.empty?
|
8
9
|
|
9
10
|
data = gon.all_variables
|
10
11
|
namespace = options[:namespace] || 'gon'
|
11
|
-
script = "<script>window
|
12
|
+
script = "<script>window.#{namespace} = {};"
|
12
13
|
unless options[:camel_case]
|
13
14
|
data.each do |key, val|
|
14
|
-
script
|
15
|
+
script << "#{namespace}.#{key}=#{val.to_json};"
|
15
16
|
end
|
16
17
|
else
|
17
18
|
data.each do |key, val|
|
18
|
-
script
|
19
|
+
script << "#{namespace}.#{key.to_s.camelize(:lower)}=#{val.to_json};"
|
19
20
|
end
|
20
21
|
end
|
21
|
-
script
|
22
|
+
script << '</script>'
|
22
23
|
script
|
23
24
|
end
|
24
25
|
end
|
25
26
|
|
26
27
|
module GonHelpers
|
27
28
|
def gon
|
28
|
-
env[
|
29
|
-
@gon = env[
|
29
|
+
env['gon'] ||= Gon::Sinatra::Store.new({})
|
30
|
+
@gon = env['gon']
|
30
31
|
end
|
31
32
|
end
|
33
|
+
|
32
34
|
end
|
33
35
|
end
|
data/lib/gon/sinatra/store.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
module Gon
|
3
2
|
module Sinatra
|
4
3
|
class Store
|
@@ -16,19 +15,19 @@ module Gon
|
|
16
15
|
@env.clear
|
17
16
|
end
|
18
17
|
|
19
|
-
def method_missing(
|
20
|
-
if (
|
21
|
-
if public_methods.include?
|
18
|
+
def method_missing(method, *args, &block)
|
19
|
+
if ( method.to_s =~ /=$/ )
|
20
|
+
if public_methods.include? method.to_s[0..-2].to_sym
|
22
21
|
raise "You can't use Gon public methods for storing data"
|
23
22
|
end
|
24
|
-
set_variable(
|
23
|
+
set_variable(method.to_s.delete('='), args[0])
|
25
24
|
else
|
26
|
-
get_variable(
|
25
|
+
get_variable(method.to_s)
|
27
26
|
end
|
28
27
|
end
|
29
28
|
|
30
29
|
def get_variable(name)
|
31
|
-
@env[name]
|
30
|
+
@env && @env[name]
|
32
31
|
end
|
33
32
|
alias :get :get_variable
|
34
33
|
|
data/lib/gon/sinatra/version.rb
CHANGED
data/spec/gon/gon_spec.rb
CHANGED
@@ -62,7 +62,7 @@ describe Gon::Sinatra, '#all_variables' do
|
|
62
62
|
expect(instance1.gon.test).to eq("foo")
|
63
63
|
end
|
64
64
|
|
65
|
-
it '
|
65
|
+
it 'renders json from rabl template' do
|
66
66
|
@gon.clear
|
67
67
|
@objects = [1,2]
|
68
68
|
@gon.rabl 'spec/test_data/sample.rabl', :instance => self
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gon-sinatra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- gazay
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|
@@ -106,6 +106,7 @@ files:
|
|
106
106
|
- ".travis.yml"
|
107
107
|
- Gemfile
|
108
108
|
- Gemfile.lock
|
109
|
+
- LICENSE
|
109
110
|
- README.md
|
110
111
|
- Rakefile
|
111
112
|
- gon-sinatra.gemspec
|
@@ -142,4 +143,3 @@ summary: Get your Sinatra variables in your JS
|
|
142
143
|
test_files:
|
143
144
|
- spec/gon/gon_spec.rb
|
144
145
|
- spec/test_data/sample.rabl
|
145
|
-
has_rdoc:
|