json_blob 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.travis.yml +20 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +158 -0
- data/LICENSE.txt +21 -0
- data/README.md +102 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/json_blob.gemspec +30 -0
- data/lib/json_blob.rb +20 -0
- data/lib/json_blob/action_view.rb +12 -0
- data/lib/json_blob/version.rb +3 -0
- metadata +159 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4596f1041f1679766f0aa61bb15751fa95423c726bb6d1fbce9beb3ff5773871
|
4
|
+
data.tar.gz: 8959458b40de7a372f0f496791dc908fde00b219eedcb8039b4db942ce198ca1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 195eb02d795c2f3d8b63f2aa49d450c01539765cbc90bac1f1ef4e07d368ec7ab928ddc8cd9cb53dd42676e8f6b6e0f82fc5529ecbbde9560977a0c64a094749
|
7
|
+
data.tar.gz: 80a84216ba08b31568a9f0bfc33981ed9569008a19f1f3a0e356a83b168fe69302911a0c7a9b8aae1613c193e10cf310a65b7212f435b96818a7a3099eadf0bd
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
language: ruby
|
2
|
+
sudo: false
|
3
|
+
cache: bundler
|
4
|
+
before_install:
|
5
|
+
- gem install bundler
|
6
|
+
before_script:
|
7
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
8
|
+
- chmod +x ./cc-test-reporter
|
9
|
+
- "./cc-test-reporter before-build"
|
10
|
+
rvm:
|
11
|
+
- 2.6.0
|
12
|
+
gemfile:
|
13
|
+
- Gemfile
|
14
|
+
notifications:
|
15
|
+
email: false
|
16
|
+
after_script:
|
17
|
+
- "./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT"
|
18
|
+
env:
|
19
|
+
global:
|
20
|
+
secure: ZnunE2KgRzlAJsJFpKIxPR+uKRoqKilut+XzMffvMDrHaJSqc5y1hsz8h3dnjoJrGJ5BeLpH2wFwe6OlxCV8ULdI6bhbGPLEth1PYOHMq7p4zarbuGH/kZCDnLPPAwUYqgWXcbnpV/UTgjLaYhX83H3DY5XwneeokuCuAxL+6r2SgoqNCTDvPPAAN2nIiUFyMX9T8n39zTpFQ+69PvYZjV5kis8llzFgUoTOuj+/55PKp94Yns0HPN4zddtYhmvWQVdAMU05M9PAxQZdcTXe9VAN6c1VDKZGHIzq5y94KTK0jQ+lItE3s/DgGiXYxvpgzcRi2zgo31wl860kV77W7r5fuEetQnbUE+zfIPDo+nROREUMBZe3/NfKXkHP/Iw8uZGzWRPLEq4A/0xxB7aWRcSY56X0CAcjpSCLqEs892SPQ4iQ57itEP/5NJIdyOIAqBj8kOLMhYiCAe0otrVb1yUP9EFQrr0GmUa9p+834/PTSSLAjNS05Var9kpn3duhwYrY9h75o1scOPvKiCuf9offWslEsWYHnYOrjpurl4AvXBdCiJXvvHKsCIe/JRsb07NHkY+nhu6dxMP/t47oDNsIBX2pUoYLIKRQvQO13+hkucfRNdCGN3EZSnTHiFvVVBRG+awj8LtEJb3xccJeEGsdFthfOQTpAXOQafVKK6Q=
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at me@fnando.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
json_blob (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
actioncable (5.2.2)
|
10
|
+
actionpack (= 5.2.2)
|
11
|
+
nio4r (~> 2.0)
|
12
|
+
websocket-driver (>= 0.6.1)
|
13
|
+
actionmailer (5.2.2)
|
14
|
+
actionpack (= 5.2.2)
|
15
|
+
actionview (= 5.2.2)
|
16
|
+
activejob (= 5.2.2)
|
17
|
+
mail (~> 2.5, >= 2.5.4)
|
18
|
+
rails-dom-testing (~> 2.0)
|
19
|
+
actionpack (5.2.2)
|
20
|
+
actionview (= 5.2.2)
|
21
|
+
activesupport (= 5.2.2)
|
22
|
+
rack (~> 2.0)
|
23
|
+
rack-test (>= 0.6.3)
|
24
|
+
rails-dom-testing (~> 2.0)
|
25
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
26
|
+
actionview (5.2.2)
|
27
|
+
activesupport (= 5.2.2)
|
28
|
+
builder (~> 3.1)
|
29
|
+
erubi (~> 1.4)
|
30
|
+
rails-dom-testing (~> 2.0)
|
31
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
32
|
+
activejob (5.2.2)
|
33
|
+
activesupport (= 5.2.2)
|
34
|
+
globalid (>= 0.3.6)
|
35
|
+
activemodel (5.2.2)
|
36
|
+
activesupport (= 5.2.2)
|
37
|
+
activerecord (5.2.2)
|
38
|
+
activemodel (= 5.2.2)
|
39
|
+
activesupport (= 5.2.2)
|
40
|
+
arel (>= 9.0)
|
41
|
+
activestorage (5.2.2)
|
42
|
+
actionpack (= 5.2.2)
|
43
|
+
activerecord (= 5.2.2)
|
44
|
+
marcel (~> 0.3.1)
|
45
|
+
activesupport (5.2.2)
|
46
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
47
|
+
i18n (>= 0.7, < 2)
|
48
|
+
minitest (~> 5.1)
|
49
|
+
tzinfo (~> 1.1)
|
50
|
+
arel (9.0.0)
|
51
|
+
awesome_print (1.8.0)
|
52
|
+
builder (3.2.3)
|
53
|
+
byebug (10.0.2)
|
54
|
+
coderay (1.1.2)
|
55
|
+
concurrent-ruby (1.1.4)
|
56
|
+
crass (1.0.4)
|
57
|
+
docile (1.3.1)
|
58
|
+
erubi (1.8.0)
|
59
|
+
globalid (0.4.1)
|
60
|
+
activesupport (>= 4.2.0)
|
61
|
+
i18n (1.3.0)
|
62
|
+
concurrent-ruby (~> 1.0)
|
63
|
+
json (2.1.0)
|
64
|
+
loofah (2.2.3)
|
65
|
+
crass (~> 1.0.2)
|
66
|
+
nokogiri (>= 1.5.9)
|
67
|
+
mail (2.7.1)
|
68
|
+
mini_mime (>= 0.1.1)
|
69
|
+
marcel (0.3.3)
|
70
|
+
mimemagic (~> 0.3.2)
|
71
|
+
method_source (0.9.2)
|
72
|
+
mimemagic (0.3.3)
|
73
|
+
mini_mime (1.0.1)
|
74
|
+
mini_portile2 (2.4.0)
|
75
|
+
minitest (5.11.3)
|
76
|
+
minitest-utils (0.4.4)
|
77
|
+
minitest
|
78
|
+
nio4r (2.3.1)
|
79
|
+
nokogiri (1.9.1)
|
80
|
+
mini_portile2 (~> 2.4.0)
|
81
|
+
pry (0.12.2)
|
82
|
+
coderay (~> 1.1.0)
|
83
|
+
method_source (~> 0.9.0)
|
84
|
+
pry-byebug (3.6.0)
|
85
|
+
byebug (~> 10.0)
|
86
|
+
pry (~> 0.10)
|
87
|
+
pry-meta (0.0.10)
|
88
|
+
awesome_print
|
89
|
+
pry
|
90
|
+
pry-byebug
|
91
|
+
pry-remote
|
92
|
+
pry-remote (0.1.8)
|
93
|
+
pry (~> 0.9)
|
94
|
+
slop (~> 3.0)
|
95
|
+
rack (2.0.6)
|
96
|
+
rack-test (1.1.0)
|
97
|
+
rack (>= 1.0, < 3)
|
98
|
+
rails (5.2.2)
|
99
|
+
actioncable (= 5.2.2)
|
100
|
+
actionmailer (= 5.2.2)
|
101
|
+
actionpack (= 5.2.2)
|
102
|
+
actionview (= 5.2.2)
|
103
|
+
activejob (= 5.2.2)
|
104
|
+
activemodel (= 5.2.2)
|
105
|
+
activerecord (= 5.2.2)
|
106
|
+
activestorage (= 5.2.2)
|
107
|
+
activesupport (= 5.2.2)
|
108
|
+
bundler (>= 1.3.0)
|
109
|
+
railties (= 5.2.2)
|
110
|
+
sprockets-rails (>= 2.0.0)
|
111
|
+
rails-dom-testing (2.0.3)
|
112
|
+
activesupport (>= 4.2.0)
|
113
|
+
nokogiri (>= 1.6)
|
114
|
+
rails-html-sanitizer (1.0.4)
|
115
|
+
loofah (~> 2.2, >= 2.2.2)
|
116
|
+
railties (5.2.2)
|
117
|
+
actionpack (= 5.2.2)
|
118
|
+
activesupport (= 5.2.2)
|
119
|
+
method_source
|
120
|
+
rake (>= 0.8.7)
|
121
|
+
thor (>= 0.19.0, < 2.0)
|
122
|
+
rake (12.3.2)
|
123
|
+
simplecov (0.16.1)
|
124
|
+
docile (~> 1.1)
|
125
|
+
json (>= 1.8, < 3)
|
126
|
+
simplecov-html (~> 0.10.0)
|
127
|
+
simplecov-html (0.10.2)
|
128
|
+
slop (3.6.0)
|
129
|
+
sprockets (3.7.2)
|
130
|
+
concurrent-ruby (~> 1.0)
|
131
|
+
rack (> 1, < 3)
|
132
|
+
sprockets-rails (3.2.1)
|
133
|
+
actionpack (>= 4.0)
|
134
|
+
activesupport (>= 4.0)
|
135
|
+
sprockets (>= 3.0.0)
|
136
|
+
thor (0.20.3)
|
137
|
+
thread_safe (0.3.6)
|
138
|
+
tzinfo (1.2.5)
|
139
|
+
thread_safe (~> 0.1)
|
140
|
+
websocket-driver (0.7.0)
|
141
|
+
websocket-extensions (>= 0.1.0)
|
142
|
+
websocket-extensions (0.1.3)
|
143
|
+
|
144
|
+
PLATFORMS
|
145
|
+
ruby
|
146
|
+
|
147
|
+
DEPENDENCIES
|
148
|
+
actionview
|
149
|
+
bundler
|
150
|
+
json_blob!
|
151
|
+
minitest-utils
|
152
|
+
pry-meta
|
153
|
+
rails
|
154
|
+
rake
|
155
|
+
simplecov
|
156
|
+
|
157
|
+
BUNDLED WITH
|
158
|
+
1.17.3
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Nando Vieira
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
# JSONBlob
|
2
|
+
|
3
|
+
[![Travis-CI](https://travis-ci.org/fnando/json_blob.svg)](https://travis-ci.org/fnando/json_blob)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/fnando/json_blob/badges/gpa.svg)](https://codeclimate.com/github/fnando/json_blob)
|
5
|
+
[![Test Coverage](https://codeclimate.com/github/fnando/json_blob/badges/coverage.svg)](https://codeclimate.com/github/fnando/json_blob/coverage)
|
6
|
+
[![Gem](https://img.shields.io/gem/v/json_blob.svg)](https://rubygems.org/gems/json_blob)
|
7
|
+
[![Gem](https://img.shields.io/gem/dt/json_blob.svg)](https://rubygems.org/gems/json_blob)
|
8
|
+
|
9
|
+
Create `<script type="application/json;base64">` tags to safely send data to the UI. You can then use <https://github.com/fnando/json_blob-js> to load this data on the client-side.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem "json_blob"
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install json_blob
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
To output data, use the `json_blob` method like the following:
|
30
|
+
|
31
|
+
```erb
|
32
|
+
<%= json_blob :user, @user %>
|
33
|
+
```
|
34
|
+
|
35
|
+
This will output something like:
|
36
|
+
|
37
|
+
```html
|
38
|
+
<script data-name="user" type="application/json;base64">eyJuYW1lIjoiSm9obiBEb2UifQ==</script>
|
39
|
+
```
|
40
|
+
|
41
|
+
On the client-side you can load the data with something like the following. You're better off using <https://github.com/fnando/json_blob-js> to avoid copying 'n' pasting code between projects.
|
42
|
+
|
43
|
+
```js
|
44
|
+
function loadJSONBlob(name, defaults = null) {
|
45
|
+
const element = document.querySelector(`script[type="application/json;base64"][data-name="${name}"]`);
|
46
|
+
|
47
|
+
if (!element) {
|
48
|
+
return defaults;
|
49
|
+
}
|
50
|
+
|
51
|
+
return JSON.parse(atob(element.innerHTML));
|
52
|
+
}
|
53
|
+
|
54
|
+
const user = loadJSONBlob("user");
|
55
|
+
```
|
56
|
+
|
57
|
+
### Ruby
|
58
|
+
|
59
|
+
You can use the methods to encode/decode payloads directly.
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
encoded = JSONBlob.dump(a: 1)
|
63
|
+
decoded = JSONBlob.parse(encoded)
|
64
|
+
```
|
65
|
+
|
66
|
+
You can also set your favorite JSON engine. The requirement is that it must implement the `dump(data)` and `parse(data)` methods.
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
module CustomJSONEngine
|
70
|
+
def self.dump(data)
|
71
|
+
JSON.dump(data.merge(dump: true))
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.parse(data)
|
75
|
+
JSON.parse(data).merge(parse: true)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
JSONBlob.json_engine = CustomJSONEngine
|
80
|
+
|
81
|
+
encoded = JSONBlob.dump(a: 1)
|
82
|
+
decoded = JSONBlob.parse(encoded)
|
83
|
+
#=> {"a" => 1, "dump": true, "parse": true}
|
84
|
+
```
|
85
|
+
|
86
|
+
## Development
|
87
|
+
|
88
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
89
|
+
|
90
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
91
|
+
|
92
|
+
## Contributing
|
93
|
+
|
94
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/fnando/json_blob. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
95
|
+
|
96
|
+
## License
|
97
|
+
|
98
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
99
|
+
|
100
|
+
## Code of Conduct
|
101
|
+
|
102
|
+
Everyone interacting in the JSONBlob project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/fnando/json_blob/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "json_blob"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/json_blob.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require "./lib/json_blob/version"
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "json_blob"
|
5
|
+
spec.version = JSONBlob::VERSION
|
6
|
+
spec.authors = ["Nando Vieira"]
|
7
|
+
spec.email = ["me@fnando.com"]
|
8
|
+
|
9
|
+
spec.summary = %[Create `<script type="application/json;base64">` tags to safely send data to the UI. You can then use https://github.com/fnando/json_blob-js to load this data on the client-side.]
|
10
|
+
spec.description = spec.summary
|
11
|
+
spec.homepage = "https://github.com/fnando/json_blob"
|
12
|
+
spec.license = "MIT"
|
13
|
+
|
14
|
+
# Specify which files should be added to the gem when it is released.
|
15
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
16
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
17
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "actionview"
|
24
|
+
spec.add_development_dependency "bundler"
|
25
|
+
spec.add_development_dependency "minitest-utils"
|
26
|
+
spec.add_development_dependency "pry-meta"
|
27
|
+
spec.add_development_dependency "rails"
|
28
|
+
spec.add_development_dependency "rake"
|
29
|
+
spec.add_development_dependency "simplecov"
|
30
|
+
end
|
data/lib/json_blob.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module JSONBlob
|
2
|
+
require "json"
|
3
|
+
require "json_blob/version"
|
4
|
+
|
5
|
+
class << self
|
6
|
+
attr_accessor :json_engine
|
7
|
+
end
|
8
|
+
|
9
|
+
self.json_engine = JSON
|
10
|
+
|
11
|
+
def self.dump(data)
|
12
|
+
Base64.strict_encode64(json_engine.dump(data))
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.parse(data)
|
16
|
+
json_engine.parse(Base64.strict_decode64(data))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
require "json_blob/action_view" if defined?(ActionView)
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "action_view/helpers"
|
2
|
+
|
3
|
+
module JSONBlob
|
4
|
+
module ActionView
|
5
|
+
def json_blob(name, data)
|
6
|
+
content = JSONBlob.dump(data)
|
7
|
+
content_tag(:script, content, data: {name: name}, type: "application/json;base64")
|
8
|
+
end
|
9
|
+
|
10
|
+
::ActionView::Helpers.include(self)
|
11
|
+
end
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: json_blob
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nando Vieira
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-12-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: actionview
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest-utils
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry-meta
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rails
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Create `<script type="application/json;base64">` tags to safely send
|
112
|
+
data to the UI. You can then use https://github.com/fnando/json_blob-js to load
|
113
|
+
this data on the client-side.
|
114
|
+
email:
|
115
|
+
- me@fnando.com
|
116
|
+
executables: []
|
117
|
+
extensions: []
|
118
|
+
extra_rdoc_files: []
|
119
|
+
files:
|
120
|
+
- ".gitignore"
|
121
|
+
- ".travis.yml"
|
122
|
+
- CODE_OF_CONDUCT.md
|
123
|
+
- Gemfile
|
124
|
+
- Gemfile.lock
|
125
|
+
- LICENSE.txt
|
126
|
+
- README.md
|
127
|
+
- Rakefile
|
128
|
+
- bin/console
|
129
|
+
- bin/setup
|
130
|
+
- json_blob.gemspec
|
131
|
+
- lib/json_blob.rb
|
132
|
+
- lib/json_blob/action_view.rb
|
133
|
+
- lib/json_blob/version.rb
|
134
|
+
homepage: https://github.com/fnando/json_blob
|
135
|
+
licenses:
|
136
|
+
- MIT
|
137
|
+
metadata: {}
|
138
|
+
post_install_message:
|
139
|
+
rdoc_options: []
|
140
|
+
require_paths:
|
141
|
+
- lib
|
142
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
requirements: []
|
153
|
+
rubygems_version: 3.0.1
|
154
|
+
signing_key:
|
155
|
+
specification_version: 4
|
156
|
+
summary: Create `<script type="application/json;base64">` tags to safely send data
|
157
|
+
to the UI. You can then use https://github.com/fnando/json_blob-js to load this
|
158
|
+
data on the client-side.
|
159
|
+
test_files: []
|