babl-json 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +8 -6
- data/lib/babl/operators/null.rb +15 -0
- data/lib/babl/operators/switch.rb +1 -1
- data/lib/babl/template.rb +2 -0
- data/lib/babl/version.rb +1 -1
- data/spec/operators/null_spec.rb +14 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ba5482718ee00f9ac1b05baf788ccd39843509a
|
4
|
+
data.tar.gz: 1fe2a5916eff6f5e589c9e77c30815aee64f8dd2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2cefeca1a634f8392ebdff3743606a8a2e3b6e2fbd1e13159426ffc1ad353a29fe96cbbdb7929a739f051e1c1d6015b7e1424008f9a920f70b9084d4eb849266
|
7
|
+
data.tar.gz: 898b5da6cd62aed43df0350106d7f9ceaf65a4cd4359c3081768a1f86040b392d82ae590551ee44036557cc4cfdafd1dfe63d3ca9820f0620710e27cf6dec290
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -4,20 +4,20 @@
|
|
4
4
|
|
5
5
|
BABL (Bannerman API Builder Language) is a templating langage for generating JSON in APIs.
|
6
6
|
|
7
|
-
It plays a role similar to [RABL](https://github.com/nesquena/rabl), [JBuilder](https://github.com/rails/jbuilder), [Grape Entity](https://github.com/ruby-grape/grape-entity), and many others. However, unlike
|
7
|
+
It plays a role similar to [RABL](https://github.com/nesquena/rabl), [JBuilder](https://github.com/rails/jbuilder), [Grape Entity](https://github.com/ruby-grape/grape-entity), and many others. However, unlike existing tools, BABL has several advantages.
|
8
8
|
|
9
9
|
|
10
10
|
### Static compilation
|
11
11
|
|
12
|
-
BABL is a simple Ruby DSL. Unlike RABL, the template code is fully parsed and executed before any data is available.
|
12
|
+
BABL is a simple Ruby DSL. Unlike RABL, the template code is fully parsed and executed before any data is available. This approach makes it possible to detect errors earlier and document the output schema automatically, without data. Experimentally, it also makes partials evaluation much faster, because partials are loaded only once.
|
13
13
|
|
14
14
|
### Automatic preloading
|
15
15
|
|
16
|
-
BABL is also able to infer the "input schema". It can loosely be seen as the list of properties we need to read from the models to construct the JSON output. These *dependencies* can be used to retrieve data more efficiently. For instance,all ActiveRecord associations can be preloaded automatically using this mechanism.
|
16
|
+
BABL is also able to infer the "input schema". It can loosely be seen as the list of properties we need to read from the models to construct the JSON output. These *dependencies* can be used to retrieve data more efficiently. For instance, all ActiveRecord associations can be preloaded automatically using this mechanism.
|
17
17
|
|
18
18
|
### Simple syntax
|
19
19
|
|
20
|
-
JSON is simple, and generating JSON should be as simple as possible.
|
20
|
+
JSON is simple, and generating JSON should be as simple as possible.
|
21
21
|
|
22
22
|
BABL template:
|
23
23
|
|
@@ -50,6 +50,8 @@ Output:
|
|
50
50
|
}
|
51
51
|
```
|
52
52
|
|
53
|
+
Interestingly, this JSON output is also a valid BABL template. It makes it very easy to mix static JSON and dynamic content during developpement.
|
54
|
+
|
53
55
|
## Documentation
|
54
56
|
|
55
57
|
TODO
|
@@ -60,13 +62,13 @@ TODO
|
|
60
62
|
|
61
63
|
This feature only works if BABL is configured to use an external preloader.
|
62
64
|
|
63
|
-
As of today, the only compatible preloader implementation *has not been released* yet. Hopefully, it will be available soon :-)
|
65
|
+
As of today, the only compatible preloader implementation *has not been released* yet, because it has severe limitations. Hopefully, it will be available soon :-)
|
64
66
|
|
65
67
|
### Automatic documentation
|
66
68
|
|
67
69
|
Support for automatic documentation is very limited, and the output is indecently ugly. It is more a proof-of-concept than a useful feature.
|
68
70
|
|
69
|
-
|
71
|
+
Mid-term goal is to generate a [JSON schema](http://json-schema.org/) documentation.
|
70
72
|
|
71
73
|
### Rails integration
|
72
74
|
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Babl
|
2
|
+
module Operators
|
3
|
+
module Null
|
4
|
+
module DSL
|
5
|
+
# This operator always produces a JSON 'null'.
|
6
|
+
# We need it because a JSON file is also a valid
|
7
|
+
# BABL file (only if it is also a valid Ruby file,
|
8
|
+
# of course)
|
9
|
+
def null
|
10
|
+
static(nil)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -5,7 +5,7 @@ module Babl
|
|
5
5
|
# To be used as a switch(...) condition. It is strictly equivalent to write 'true' instead,
|
6
6
|
# but convey more meaning.
|
7
7
|
def default
|
8
|
-
|
8
|
+
static(true)
|
9
9
|
end
|
10
10
|
|
11
11
|
# Return a special placeholder that can be used as a switch(...) value. It tells BABL to continue
|
data/lib/babl/template.rb
CHANGED
@@ -7,6 +7,7 @@ require 'babl/operators/each'
|
|
7
7
|
require 'babl/operators/enter'
|
8
8
|
require 'babl/operators/merge'
|
9
9
|
require 'babl/operators/nav'
|
10
|
+
require 'babl/operators/null'
|
10
11
|
require 'babl/operators/nullable'
|
11
12
|
require 'babl/operators/object'
|
12
13
|
require 'babl/operators/parent'
|
@@ -35,6 +36,7 @@ module Babl
|
|
35
36
|
include Operators::Enter::DSL
|
36
37
|
include Operators::Merge::DSL
|
37
38
|
include Operators::Nav::DSL
|
39
|
+
include Operators::Null::DSL
|
38
40
|
include Operators::Nullable::DSL
|
39
41
|
include Operators::Object::DSL
|
40
42
|
include Operators::Parent::DSL
|
data/lib/babl/version.rb
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ::Babl::Operators::Null do
|
4
|
+
include SpecHelper::Operators
|
5
|
+
|
6
|
+
describe '#null' do
|
7
|
+
let(:template) { dsl.source { { val: null } } }
|
8
|
+
let(:object) { {} }
|
9
|
+
|
10
|
+
it { expect(documentation).to eq(val: nil) }
|
11
|
+
it { expect(dependencies).to eq({}) }
|
12
|
+
it { expect(json).to eq('val' => nil) }
|
13
|
+
end
|
14
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: babl-json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Frederic Terrazzoni
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-06-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|
@@ -92,6 +92,7 @@ files:
|
|
92
92
|
- lib/babl/operators/enter.rb
|
93
93
|
- lib/babl/operators/merge.rb
|
94
94
|
- lib/babl/operators/nav.rb
|
95
|
+
- lib/babl/operators/null.rb
|
95
96
|
- lib/babl/operators/nullable.rb
|
96
97
|
- lib/babl/operators/object.rb
|
97
98
|
- lib/babl/operators/parent.rb
|
@@ -117,6 +118,7 @@ files:
|
|
117
118
|
- spec/operators/enter_spec.rb
|
118
119
|
- spec/operators/merge_spec.rb
|
119
120
|
- spec/operators/nav_spec.rb
|
121
|
+
- spec/operators/null_spec.rb
|
120
122
|
- spec/operators/nullable_spec.rb
|
121
123
|
- spec/operators/object_spec.rb
|
122
124
|
- spec/operators/parent_spec.rb
|
@@ -159,6 +161,7 @@ test_files:
|
|
159
161
|
- spec/operators/enter_spec.rb
|
160
162
|
- spec/operators/merge_spec.rb
|
161
163
|
- spec/operators/nav_spec.rb
|
164
|
+
- spec/operators/null_spec.rb
|
162
165
|
- spec/operators/nullable_spec.rb
|
163
166
|
- spec/operators/object_spec.rb
|
164
167
|
- spec/operators/parent_spec.rb
|