activejson 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +8 -8
- data/lib/activejson/activejson_template.rb +7 -2
- data/lib/activejson/version.rb +1 -1
- metadata +47 -62
data/README.md
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
#ActiveJSON
|
1
|
+
# ActiveJSON
|
2
2
|
|
3
|
-
##Introduction
|
3
|
+
## Introduction
|
4
4
|
|
5
5
|
A lightweight JSON view renderer in the style of the usual Rails ActiveView engine.
|
6
6
|
|
7
7
|
Uses yajl to encode the JSON to text for extra speed.
|
8
8
|
|
9
|
-
##Installation
|
9
|
+
## Installation
|
10
10
|
|
11
11
|
Installation is easy, just add `gem "activejson"` to your Gemfile and let bundle do the rest. Alternatively `gem install activejson` will install the gem globally on your system.
|
12
12
|
|
13
|
-
##Example
|
13
|
+
## Example
|
14
14
|
|
15
15
|
Create a view, something like `user.activejson` and fill it with something like this:
|
16
16
|
|
@@ -53,9 +53,9 @@ And, assuming your `@user` object has a name, an age and an array of pets, this
|
|
53
53
|
|
54
54
|
...except not-pretty printed (for speed).
|
55
55
|
|
56
|
-
##Usage
|
56
|
+
## Usage
|
57
57
|
|
58
|
-
###Introduction
|
58
|
+
### Introduction
|
59
59
|
|
60
60
|
In its simplest use case, ActiveJSON allows the view code to create JSON labels using (almost) any name, just by calling the label name as a method on an ActiveJSON object.
|
61
61
|
|
@@ -68,7 +68,7 @@ For example, to give a name and a date, use the following:
|
|
68
68
|
|
69
69
|
This is sufficient for simple, flat JSON data blocks but will never create arrays or JSON objects within other objects.
|
70
70
|
|
71
|
-
###Sub-Objects
|
71
|
+
### Sub-Objects
|
72
72
|
|
73
73
|
To mark a JSON label as being a JSON object, any function called on an ActiveJSON object can be called with a block, taking one parameter. Within the block, the parameter can be used to add labels to the JSON sub-object.
|
74
74
|
|
@@ -84,7 +84,7 @@ Will render:
|
|
84
84
|
|
85
85
|
{ object : { name : "Widget 1", flavour : "Lemon" }, title : "Objects" }
|
86
86
|
|
87
|
-
###Arrays
|
87
|
+
### Arrays
|
88
88
|
|
89
89
|
To mark a JSON label as containing an array, pass any object that responds to `map` as an argument to the label's function and supply a block taking two parameters, the first of which will be the ActiveJSON object for the array element and the second of which will be the corresponding element from the argument.
|
90
90
|
|
@@ -2,14 +2,19 @@ require 'activejson/activejson_core'
|
|
2
2
|
|
3
3
|
module ActionView
|
4
4
|
module Template::Handlers
|
5
|
-
class ActiveJsonTemplate
|
6
|
-
|
5
|
+
class ActiveJsonTemplate
|
6
|
+
class_attribute :default_format
|
7
|
+
self.default_format = 'text/json'
|
7
8
|
|
8
9
|
def compile(template)
|
9
10
|
%{ActiveJson::Core.new do |json|
|
10
11
|
#{template.source}
|
11
12
|
end.to_json }
|
12
13
|
end
|
14
|
+
|
15
|
+
def self.call(template)
|
16
|
+
new.compile(template)
|
17
|
+
end
|
13
18
|
end
|
14
19
|
end
|
15
20
|
end
|
data/lib/activejson/version.rb
CHANGED
metadata
CHANGED
@@ -1,60 +1,55 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: activejson
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.4
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 3
|
10
|
-
version: 0.1.3
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Andy Caldwell
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-08-28 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: multi_json
|
22
|
-
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
24
17
|
none: false
|
25
|
-
requirements:
|
26
|
-
- -
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
segments:
|
30
|
-
- 0
|
31
|
-
version: "0"
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
32
22
|
type: :runtime
|
33
|
-
version_requirements: *id001
|
34
|
-
- !ruby/object:Gem::Dependency
|
35
|
-
name: yajl-ruby
|
36
23
|
prerelease: false
|
37
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: yajl-ruby
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
38
33
|
none: false
|
39
|
-
requirements:
|
40
|
-
- -
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
|
43
|
-
segments:
|
44
|
-
- 0
|
45
|
-
version: "0"
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
46
38
|
type: :runtime
|
47
|
-
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
48
46
|
description: Simple template engine for JSON views
|
49
|
-
email:
|
47
|
+
email:
|
50
48
|
- andy.m.caldwell@googlemail.com
|
51
49
|
executables: []
|
52
|
-
|
53
50
|
extensions: []
|
54
|
-
|
55
51
|
extra_rdoc_files: []
|
56
|
-
|
57
|
-
files:
|
52
|
+
files:
|
58
53
|
- .gitignore
|
59
54
|
- Gemfile
|
60
55
|
- README.md
|
@@ -64,38 +59,28 @@ files:
|
|
64
59
|
- lib/activejson/activejson_core.rb
|
65
60
|
- lib/activejson/activejson_template.rb
|
66
61
|
- lib/activejson/version.rb
|
67
|
-
homepage:
|
62
|
+
homepage: ''
|
68
63
|
licenses: []
|
69
|
-
|
70
64
|
post_install_message:
|
71
65
|
rdoc_options: []
|
72
|
-
|
73
|
-
require_paths:
|
66
|
+
require_paths:
|
74
67
|
- lib
|
75
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
69
|
none: false
|
77
|
-
requirements:
|
78
|
-
- -
|
79
|
-
- !ruby/object:Gem::Version
|
80
|
-
|
81
|
-
|
82
|
-
- 0
|
83
|
-
version: "0"
|
84
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ! '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
75
|
none: false
|
86
|
-
requirements:
|
87
|
-
- -
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
|
90
|
-
segments:
|
91
|
-
- 0
|
92
|
-
version: "0"
|
76
|
+
requirements:
|
77
|
+
- - ! '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
93
80
|
requirements: []
|
94
|
-
|
95
81
|
rubyforge_project:
|
96
|
-
rubygems_version: 1.8.
|
82
|
+
rubygems_version: 1.8.24
|
97
83
|
signing_key:
|
98
84
|
specification_version: 3
|
99
85
|
summary: Simple template engine for JSON views
|
100
86
|
test_files: []
|
101
|
-
|