jsonify-rails 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +63 -0
- data/LICENSE +21 -0
- data/README.md +93 -0
- data/Rakefile +5 -0
- data/jsonify-rails.gemspec +27 -0
- data/lib/jsonify-rails.rb +2 -0
- data/lib/jsonify-rails/jsonify_builder.rb +18 -0
- data/lib/jsonify-rails/version.rb +4 -0
- metadata +127 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pkg/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
jsonify-rails (0.0.5)
|
5
|
+
actionpack (~> 3.0.0)
|
6
|
+
jsonify
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
specs:
|
11
|
+
ZenTest (4.6.0)
|
12
|
+
abstract (1.0.0)
|
13
|
+
actionpack (3.0.9)
|
14
|
+
activemodel (= 3.0.9)
|
15
|
+
activesupport (= 3.0.9)
|
16
|
+
builder (~> 2.1.2)
|
17
|
+
erubis (~> 2.6.6)
|
18
|
+
i18n (~> 0.5.0)
|
19
|
+
rack (~> 1.2.1)
|
20
|
+
rack-mount (~> 0.6.14)
|
21
|
+
rack-test (~> 0.5.7)
|
22
|
+
tzinfo (~> 0.3.23)
|
23
|
+
activemodel (3.0.9)
|
24
|
+
activesupport (= 3.0.9)
|
25
|
+
builder (~> 2.1.2)
|
26
|
+
i18n (~> 0.5.0)
|
27
|
+
activesupport (3.0.9)
|
28
|
+
autotest (4.4.6)
|
29
|
+
ZenTest (>= 4.4.1)
|
30
|
+
builder (2.1.2)
|
31
|
+
diff-lcs (1.1.2)
|
32
|
+
erubis (2.6.6)
|
33
|
+
abstract (>= 1.0.0)
|
34
|
+
i18n (0.5.0)
|
35
|
+
json (1.5.3)
|
36
|
+
jsonify (0.0.4)
|
37
|
+
actionpack (~> 3.0.0)
|
38
|
+
json
|
39
|
+
rack (1.2.3)
|
40
|
+
rack-mount (0.6.14)
|
41
|
+
rack (>= 1.0.0)
|
42
|
+
rack-test (0.5.7)
|
43
|
+
rack (>= 1.0)
|
44
|
+
rake (0.9.2)
|
45
|
+
rspec (2.6.0)
|
46
|
+
rspec-core (~> 2.6.0)
|
47
|
+
rspec-expectations (~> 2.6.0)
|
48
|
+
rspec-mocks (~> 2.6.0)
|
49
|
+
rspec-core (2.6.4)
|
50
|
+
rspec-expectations (2.6.0)
|
51
|
+
diff-lcs (~> 1.1.2)
|
52
|
+
rspec-mocks (2.6.0)
|
53
|
+
tzinfo (0.3.29)
|
54
|
+
|
55
|
+
PLATFORMS
|
56
|
+
ruby
|
57
|
+
|
58
|
+
DEPENDENCIES
|
59
|
+
autotest
|
60
|
+
bundler
|
61
|
+
jsonify-rails!
|
62
|
+
rake
|
63
|
+
rspec
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2011 Bill Siggelkow
|
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,93 @@
|
|
1
|
+
# Jsonify-Rails — Use Jsonify templates for Rails view
|
2
|
+
|
3
|
+
[Jsonify](https://github.com/bsiggelkow/jsonify) is to JSON as [Builder](https://github.com/jimweirich/builder) is to XML.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
`gem install jsonify-rails`
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
Jsonify-rails provides a Rails 3 template handler allowing you to create
|
12
|
+
view templates using Jsonify. Any template with a `.jsonify` will be handled by Rails.
|
13
|
+
|
14
|
+
The Jsonify template handler exposes a `Jsonify::Builder` instance to your template with the `json` variable:
|
15
|
+
|
16
|
+
json.hello do
|
17
|
+
json.world "Jsonify is Working!"
|
18
|
+
end
|
19
|
+
|
20
|
+
Just like with any other template, your Jsonify template will have access to
|
21
|
+
any instance variables that are exposed through the controller.
|
22
|
+
|
23
|
+
#### Partials
|
24
|
+
|
25
|
+
You can use partials from Jsonify views, and you can create Jsonify partials. How your Jsonify template uses a partial depends on how the information the partial returns is structured. Keep in mind that any paritial, be it a Jsonify template, erb, or anything else, always a returns its result as a string.
|
26
|
+
|
27
|
+
##### Jsonify partials
|
28
|
+
|
29
|
+
Any Jsonify partial — that is, the file has a `.jsonify` extension —
|
30
|
+
will return, by design, a string that is valid JSON. It will represent either a JSON object,wrapped in curly braces ( {} ), or a JSON array, wrapped in square brackets ( [] ).
|
31
|
+
|
32
|
+
To incorporate such a value into a Jsonify template, use the `ingest!` method.
|
33
|
+
|
34
|
+
`ingest!` assumes that the value it receives is valid JSON representation. It parses the JSON into a Jsonify object graph, and then adds it to the current Jsonify builder.
|
35
|
+
|
36
|
+
Let's assume this this is your main template, `index.jsonify`:
|
37
|
+
|
38
|
+
json << 1
|
39
|
+
json.ingest! (render :partial=>'my_partial')
|
40
|
+
|
41
|
+
From the first line, you can tell that an array will be created as this line uses the append operator.
|
42
|
+
On the second line, a partial is being added to the builder. Note that you cannot simply place `render :parial ...` on a line by itself as you can do with other templates like `erb` and `haml`. You have to explicitly tell Jsonify to add it to the builder.
|
43
|
+
|
44
|
+
Let's say that the partial file, `_my_partial.jsonify`, is as follows:
|
45
|
+
|
46
|
+
json << 3
|
47
|
+
json << 4
|
48
|
+
|
49
|
+
This `json` variable in this partial is a separate distinct `Jsonify::Builder` instance from the `json` variable in the main template.
|
50
|
+
|
51
|
+
> Note: Figure out if a the `json` instance can be passed to the Jsonify partial.
|
52
|
+
> It would make things easier and we wouldn't have to ingest the result.
|
53
|
+
|
54
|
+
This partial results in the following string:
|
55
|
+
|
56
|
+
"[3,4]"
|
57
|
+
|
58
|
+
The `ingest!` method will actually parse this string back into a Jsonify-based object, and adds it to the builder's current state. The resulting output will be:
|
59
|
+
|
60
|
+
"[1,[3,4]]"
|
61
|
+
|
62
|
+
##### Other partials
|
63
|
+
|
64
|
+
You can also use output from non-Jsonify templates (e.g. erb); just remember that the output from a template is always a string and that you have to tell the builder how to include the result of the partial.
|
65
|
+
|
66
|
+
For example, suppose you have the partial `_today.erb` with the following content:
|
67
|
+
|
68
|
+
<%= Date.today %>
|
69
|
+
|
70
|
+
You can then incorporate this partial into your Jsonify template just as you would any other string value:
|
71
|
+
|
72
|
+
json << 1
|
73
|
+
json << {:date => (render :partial => 'today')}
|
74
|
+
|
75
|
+
renders ...
|
76
|
+
|
77
|
+
[1,{"date":"2011-07-30"}]
|
78
|
+
|
79
|
+
|
80
|
+
## Related Projects
|
81
|
+
- [Argonaut](https://github.com/jbr/argonaut)
|
82
|
+
- [JSON Builder](https://github.com/dewski/json_builder)
|
83
|
+
- [RABL](https://github.com/nesquena/rabl)
|
84
|
+
- [Representative](https://github.com/mdub/representative)
|
85
|
+
- [Tokamak](https://github.com/abril/tokamak)
|
86
|
+
|
87
|
+
## License
|
88
|
+
|
89
|
+
This project is released under the MIT license.
|
90
|
+
|
91
|
+
## Authors
|
92
|
+
|
93
|
+
* [Bill Siggelkow](https://github.com/bsiggelkow)
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "jsonify-rails/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "jsonify-rails"
|
7
|
+
s.version = JsonifyRails::VERSION
|
8
|
+
s.authors = ["Bill Siggelkow"]
|
9
|
+
s.email = ["bsiggelkow@me.com"]
|
10
|
+
s.homepage = "http://github.com/bsiggelkow/jsonify-rails"
|
11
|
+
s.summary = %q{Use Jsonify for Rails View templates}
|
12
|
+
s.description = s.summary
|
13
|
+
|
14
|
+
s.rubyforge_project = s.name
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
s.add_dependency 'jsonify'
|
21
|
+
s.add_dependency "actionpack", "~> 3.0.0"
|
22
|
+
|
23
|
+
s.add_development_dependency 'bundler'
|
24
|
+
s.add_development_dependency 'rake'
|
25
|
+
s.add_development_dependency 'rspec'
|
26
|
+
s.add_development_dependency 'autotest'
|
27
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'action_view'
|
2
|
+
module ActionView
|
3
|
+
module Template::Handlers
|
4
|
+
class JsonifyBuilder < Template::Handler
|
5
|
+
include Compilable
|
6
|
+
|
7
|
+
self.default_format = Mime::JSON
|
8
|
+
|
9
|
+
def compile(template)
|
10
|
+
"json = ::Jsonify::Builder.new();" +
|
11
|
+
template.source +
|
12
|
+
";json.compile!;"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
ActionView::Template.register_template_handler :jsonify, ActionView::Template::Handlers::JsonifyBuilder
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jsonify-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.5
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Bill Siggelkow
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-08-02 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: jsonify
|
16
|
+
requirement: &70250138969280 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70250138969280
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: actionpack
|
27
|
+
requirement: &70250138968380 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 3.0.0
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70250138968380
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: bundler
|
38
|
+
requirement: &70250138967640 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70250138967640
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: &70250138966820 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70250138966820
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: rspec
|
60
|
+
requirement: &70250138966140 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70250138966140
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: autotest
|
71
|
+
requirement: &70250138965460 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70250138965460
|
80
|
+
description: Use Jsonify for Rails View templates
|
81
|
+
email:
|
82
|
+
- bsiggelkow@me.com
|
83
|
+
executables: []
|
84
|
+
extensions: []
|
85
|
+
extra_rdoc_files: []
|
86
|
+
files:
|
87
|
+
- .gitignore
|
88
|
+
- Gemfile
|
89
|
+
- Gemfile.lock
|
90
|
+
- LICENSE
|
91
|
+
- README.md
|
92
|
+
- Rakefile
|
93
|
+
- jsonify-rails.gemspec
|
94
|
+
- lib/jsonify-rails.rb
|
95
|
+
- lib/jsonify-rails/jsonify_builder.rb
|
96
|
+
- lib/jsonify-rails/version.rb
|
97
|
+
homepage: http://github.com/bsiggelkow/jsonify-rails
|
98
|
+
licenses: []
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options: []
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
none: false
|
105
|
+
requirements:
|
106
|
+
- - ! '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
segments:
|
110
|
+
- 0
|
111
|
+
hash: -2006394600352275057
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
segments:
|
119
|
+
- 0
|
120
|
+
hash: -2006394600352275057
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project: jsonify-rails
|
123
|
+
rubygems_version: 1.8.6
|
124
|
+
signing_key:
|
125
|
+
specification_version: 3
|
126
|
+
summary: Use Jsonify for Rails View templates
|
127
|
+
test_files: []
|