babl-json 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.
- checksums.yaml +4 -4
- data/.rubocop.yml +31 -58
- data/.ruby-version +1 -1
- data/CHANGELOG.md +6 -2
- data/README.md +4 -4
- data/lib/babl/operators/extends.rb +11 -0
- data/lib/babl/template.rb +2 -0
- data/lib/babl/version.rb +1 -1
- data/spec/operators/extends_spec.rb +16 -0
- data/spec/operators/partial_spec.rb +0 -17
- data/spec/spec_helper.rb +17 -0
- metadata +6 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2e6fcf82a20874d904622914b9253af7377adcbe
|
|
4
|
+
data.tar.gz: e74d60dee7726f6efd41d02bd1b6777673087c0e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c73c9e24b87d003d01f29bc1670d189fd449e3f74012141c835b833d9e657da96bbd6a1285e419ada89dd69bfc73207c0451f6ba97320d2793c082f553b43c25
|
|
7
|
+
data.tar.gz: 2863794485cca3b329105e717c76b1f69124221176f732bd9a17065cf81f2d57c17b9c8d5bd056174b9a5b89f84c088f3f7856fcb06eb08c88538d2b8fe4631f
|
data/.rubocop.yml
CHANGED
|
@@ -8,12 +8,6 @@ AllCops:
|
|
|
8
8
|
CaseIndentation:
|
|
9
9
|
EnforcedStyle: end
|
|
10
10
|
|
|
11
|
-
Metrics/LineLength:
|
|
12
|
-
Max: 130
|
|
13
|
-
|
|
14
|
-
Metrics/PerceivedComplexity:
|
|
15
|
-
Max: 12
|
|
16
|
-
|
|
17
11
|
ParameterLists:
|
|
18
12
|
Max: 5
|
|
19
13
|
CountKeywordArgs: false
|
|
@@ -21,9 +15,6 @@ ParameterLists:
|
|
|
21
15
|
Rails:
|
|
22
16
|
Enabled: False
|
|
23
17
|
|
|
24
|
-
Style/AlignParameters:
|
|
25
|
-
EnforcedStyle: with_fixed_indentation
|
|
26
|
-
|
|
27
18
|
Style/AndOr:
|
|
28
19
|
EnforcedStyle: conditionals
|
|
29
20
|
|
|
@@ -36,30 +27,44 @@ Style/CollectionMethods:
|
|
|
36
27
|
Style/Documentation:
|
|
37
28
|
Enabled: False
|
|
38
29
|
|
|
39
|
-
Style/
|
|
30
|
+
Style/Lambda:
|
|
31
|
+
Enabled: False
|
|
32
|
+
|
|
33
|
+
Style/MultilineIfModifier:
|
|
34
|
+
Enabled: False
|
|
35
|
+
|
|
36
|
+
Style/NumericLiterals:
|
|
37
|
+
Enabled: False
|
|
38
|
+
|
|
39
|
+
Style/SignalException:
|
|
40
|
+
EnforcedStyle: only_raise
|
|
41
|
+
|
|
42
|
+
Layout/AlignParameters:
|
|
43
|
+
EnforcedStyle: with_fixed_indentation
|
|
44
|
+
|
|
45
|
+
Layout/ExtraSpacing:
|
|
40
46
|
Enabled: True
|
|
41
47
|
|
|
42
|
-
|
|
48
|
+
Layout/IndentationWidth:
|
|
43
49
|
Width: 4
|
|
44
50
|
|
|
45
|
-
|
|
51
|
+
Layout/IndentHash:
|
|
46
52
|
EnforcedStyle: consistent
|
|
47
53
|
|
|
48
|
-
|
|
49
|
-
|
|
54
|
+
Layout/MultilineOperationIndentation:
|
|
55
|
+
EnforcedStyle: indented
|
|
50
56
|
|
|
51
|
-
|
|
57
|
+
Layout/EmptyLineAfterMagicComment:
|
|
52
58
|
Enabled: False
|
|
53
59
|
|
|
54
|
-
|
|
55
|
-
|
|
60
|
+
Layout/IndentArray:
|
|
61
|
+
Enabled: False
|
|
56
62
|
|
|
57
|
-
|
|
63
|
+
Layout/IndentHeredoc:
|
|
58
64
|
Enabled: False
|
|
59
65
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
# End -- Keep the following
|
|
66
|
+
Layout/MultilineMethodCallIndentation:
|
|
67
|
+
Enabled: False
|
|
63
68
|
|
|
64
69
|
Lint/AmbiguousBlockAssociation:
|
|
65
70
|
Enabled: False
|
|
@@ -85,6 +90,11 @@ Lint/UnneededSplatExpansion:
|
|
|
85
90
|
Lint/UselessAccessModifier:
|
|
86
91
|
Enabled: False
|
|
87
92
|
|
|
93
|
+
Metrics/LineLength:
|
|
94
|
+
Max: 130
|
|
95
|
+
|
|
96
|
+
Metrics/PerceivedComplexity:
|
|
97
|
+
Max: 12
|
|
88
98
|
|
|
89
99
|
Metrics/AbcSize:
|
|
90
100
|
Enabled: False
|
|
@@ -109,40 +119,15 @@ Metrics/MethodLength:
|
|
|
109
119
|
Metrics/ModuleLength:
|
|
110
120
|
Enabled: False
|
|
111
121
|
|
|
112
|
-
|
|
113
122
|
Performance/Casecmp:
|
|
114
123
|
Enabled: False
|
|
115
124
|
|
|
116
|
-
|
|
117
|
-
Rails/Blank:
|
|
118
|
-
Enabled: False
|
|
119
|
-
|
|
120
|
-
Rails/Date:
|
|
121
|
-
Enabled: False
|
|
122
|
-
|
|
123
|
-
Rails/DynamicFindBy:
|
|
124
|
-
Enabled: False
|
|
125
|
-
|
|
126
|
-
Rails/FilePath:
|
|
127
|
-
Enabled: False
|
|
128
|
-
|
|
129
|
-
Rails/PluralizationGrammar:
|
|
130
|
-
Enabled: False
|
|
131
|
-
|
|
132
|
-
Rails/RelativeDateConstant:
|
|
133
|
-
Enabled: False
|
|
134
|
-
|
|
135
|
-
Rails/SkipsModelValidations:
|
|
136
|
-
Enabled: False
|
|
137
|
-
|
|
138
125
|
Rails/TimeZone:
|
|
139
126
|
Enabled: False
|
|
140
127
|
|
|
141
|
-
|
|
142
128
|
Security/YAMLLoad:
|
|
143
129
|
Enabled: False
|
|
144
130
|
|
|
145
|
-
|
|
146
131
|
Style/Alias:
|
|
147
132
|
Enabled: False
|
|
148
133
|
|
|
@@ -155,9 +140,6 @@ Style/ClassVars:
|
|
|
155
140
|
Style/EmptyCaseCondition:
|
|
156
141
|
Enabled: False
|
|
157
142
|
|
|
158
|
-
Style/EmptyLineAfterMagicComment:
|
|
159
|
-
Enabled: False
|
|
160
|
-
|
|
161
143
|
Style/EmptyMethod:
|
|
162
144
|
Enabled: False
|
|
163
145
|
|
|
@@ -170,12 +152,6 @@ Style/FrozenStringLiteralComment:
|
|
|
170
152
|
Style/GuardClause:
|
|
171
153
|
Enabled: False
|
|
172
154
|
|
|
173
|
-
Style/IndentArray:
|
|
174
|
-
Enabled: False
|
|
175
|
-
|
|
176
|
-
Style/IndentHeredoc:
|
|
177
|
-
Enabled: False
|
|
178
|
-
|
|
179
155
|
Style/MixinGrouping:
|
|
180
156
|
Enabled: False
|
|
181
157
|
|
|
@@ -185,9 +161,6 @@ Style/MultilineBlockChain:
|
|
|
185
161
|
Style/MultilineMemoization:
|
|
186
162
|
Enabled: False
|
|
187
163
|
|
|
188
|
-
Style/MultilineMethodCallIndentation:
|
|
189
|
-
Enabled: False
|
|
190
|
-
|
|
191
164
|
Style/MutableConstant:
|
|
192
165
|
Enabled: False
|
|
193
166
|
|
data/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.
|
|
1
|
+
2.4.1
|
data/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
# BABL Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.4 (July 6, 2017)
|
|
4
|
+
|
|
5
|
+
- Added operator `extends`, to simplify the common usage pattern `merge(partial(...), ...)`.
|
|
6
|
+
|
|
3
7
|
## 0.1.3 (June 19, 2017)
|
|
4
8
|
|
|
5
|
-
- Added
|
|
9
|
+
- Added operator `null`, in order to make any JSON file a valid BABL template.
|
|
6
10
|
|
|
7
11
|
## 0.1.2 (May 22, 2017)
|
|
8
12
|
|
|
9
|
-
- Fixed a bug in
|
|
13
|
+
- Fixed a bug in `call(primitive)`
|
|
10
14
|
- Improved test suite
|
|
11
15
|
|
|
12
16
|
## 0.1.1 (May 16, 2017)
|
data/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
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 existing tools, BABL has several advantages.
|
|
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), [AMS](https://github.com/rails-api/active_model_serializers), and many others. However, unlike existing tools, BABL has several advantages.
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
### Static compilation
|
|
@@ -50,11 +50,11 @@ Output:
|
|
|
50
50
|
}
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
-
Interestingly, this JSON output is also a valid BABL template.
|
|
53
|
+
Interestingly, this JSON output is also a valid BABL template. This property makes it very easy to mix static JSON and dynamic content during developpement.
|
|
54
54
|
|
|
55
55
|
## Documentation
|
|
56
56
|
|
|
57
|
-
|
|
57
|
+
Not yet available.
|
|
58
58
|
|
|
59
59
|
## Current limitations
|
|
60
60
|
|
|
@@ -68,7 +68,7 @@ As of today, the only compatible preloader implementation *has not been released
|
|
|
68
68
|
|
|
69
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.
|
|
70
70
|
|
|
71
|
-
Mid-term goal is to generate a [JSON schema](http://json-schema.org/)
|
|
71
|
+
Mid-term goal is to generate a [JSON schema](http://json-schema.org/).
|
|
72
72
|
|
|
73
73
|
### Rails integration
|
|
74
74
|
|
data/lib/babl/template.rb
CHANGED
|
@@ -5,6 +5,7 @@ require 'babl/operators/call'
|
|
|
5
5
|
require 'babl/operators/dep'
|
|
6
6
|
require 'babl/operators/each'
|
|
7
7
|
require 'babl/operators/enter'
|
|
8
|
+
require 'babl/operators/extends'
|
|
8
9
|
require 'babl/operators/merge'
|
|
9
10
|
require 'babl/operators/nav'
|
|
10
11
|
require 'babl/operators/null'
|
|
@@ -34,6 +35,7 @@ module Babl
|
|
|
34
35
|
include Operators::Dep::DSL
|
|
35
36
|
include Operators::Each::DSL
|
|
36
37
|
include Operators::Enter::DSL
|
|
38
|
+
include Operators::Extends::DSL
|
|
37
39
|
include Operators::Merge::DSL
|
|
38
40
|
include Operators::Nav::DSL
|
|
39
41
|
include Operators::Null::DSL
|
data/lib/babl/version.rb
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe ::Babl::Operators::Extends do
|
|
4
|
+
include SpecHelper::Operators
|
|
5
|
+
|
|
6
|
+
let(:custom_lookup_context) {
|
|
7
|
+
TestLookupContext.new(base_partial: TestLookupContext.new('object(a: 1, b: 3)'))
|
|
8
|
+
}
|
|
9
|
+
let(:ctx_dsl) { dsl.with_lookup_context(custom_lookup_context) }
|
|
10
|
+
let(:object) { [nil] }
|
|
11
|
+
|
|
12
|
+
context 'simple use case' do
|
|
13
|
+
let(:template) { ctx_dsl.source { each.extends('base_partial', object(x: 1), b: 34) } }
|
|
14
|
+
it { expect(json).to eq(['a' => 1, 'x' => 1, 'b' => 34]) }
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -3,23 +3,6 @@ require 'spec_helper'
|
|
|
3
3
|
describe ::Babl::Operators::Partial do
|
|
4
4
|
include SpecHelper::Operators
|
|
5
5
|
|
|
6
|
-
before {
|
|
7
|
-
stub_const('TestLookupContext', Class.new {
|
|
8
|
-
attr_reader :code, :childs
|
|
9
|
-
|
|
10
|
-
def initialize(code = nil, **childs)
|
|
11
|
-
@code = code
|
|
12
|
-
@childs = childs
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def find(name)
|
|
16
|
-
name = name.to_sym
|
|
17
|
-
return unless childs[name]
|
|
18
|
-
[name.to_s, childs[name].code, childs[name]]
|
|
19
|
-
end
|
|
20
|
-
})
|
|
21
|
-
}
|
|
22
|
-
|
|
23
6
|
let(:custom_lookup_context) {
|
|
24
7
|
TestLookupContext.new(
|
|
25
8
|
blabla: TestLookupContext.new(
|
data/spec/spec_helper.rb
CHANGED
|
@@ -9,6 +9,23 @@ module SpecHelper
|
|
|
9
9
|
base.let(:json) { ::Oj.load(compiled.json(object)) }
|
|
10
10
|
base.let(:dependencies) { compiled.dependencies }
|
|
11
11
|
base.let(:documentation) { compiled.documentation }
|
|
12
|
+
|
|
13
|
+
base.before {
|
|
14
|
+
stub_const('TestLookupContext', Class.new {
|
|
15
|
+
attr_reader :code, :childs
|
|
16
|
+
|
|
17
|
+
def initialize(code = nil, **childs)
|
|
18
|
+
@code = code
|
|
19
|
+
@childs = childs
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def find(name)
|
|
23
|
+
name = name.to_sym
|
|
24
|
+
return unless childs[name]
|
|
25
|
+
[name.to_s, childs[name].code, childs[name]]
|
|
26
|
+
end
|
|
27
|
+
})
|
|
28
|
+
}
|
|
12
29
|
end
|
|
13
30
|
end
|
|
14
31
|
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.4
|
|
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-06
|
|
11
|
+
date: 2017-07-06 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: pry
|
|
@@ -90,6 +90,7 @@ files:
|
|
|
90
90
|
- lib/babl/operators/dep.rb
|
|
91
91
|
- lib/babl/operators/each.rb
|
|
92
92
|
- lib/babl/operators/enter.rb
|
|
93
|
+
- lib/babl/operators/extends.rb
|
|
93
94
|
- lib/babl/operators/merge.rb
|
|
94
95
|
- lib/babl/operators/nav.rb
|
|
95
96
|
- lib/babl/operators/null.rb
|
|
@@ -116,6 +117,7 @@ files:
|
|
|
116
117
|
- spec/operators/dep_spec.rb
|
|
117
118
|
- spec/operators/each_spec.rb
|
|
118
119
|
- spec/operators/enter_spec.rb
|
|
120
|
+
- spec/operators/extends_spec.rb
|
|
119
121
|
- spec/operators/merge_spec.rb
|
|
120
122
|
- spec/operators/nav_spec.rb
|
|
121
123
|
- spec/operators/null_spec.rb
|
|
@@ -149,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
149
151
|
version: '0'
|
|
150
152
|
requirements: []
|
|
151
153
|
rubyforge_project:
|
|
152
|
-
rubygems_version: 2.6.
|
|
154
|
+
rubygems_version: 2.6.11
|
|
153
155
|
signing_key:
|
|
154
156
|
specification_version: 4
|
|
155
157
|
summary: JSON templating on steroids
|
|
@@ -159,6 +161,7 @@ test_files:
|
|
|
159
161
|
- spec/operators/dep_spec.rb
|
|
160
162
|
- spec/operators/each_spec.rb
|
|
161
163
|
- spec/operators/enter_spec.rb
|
|
164
|
+
- spec/operators/extends_spec.rb
|
|
162
165
|
- spec/operators/merge_spec.rb
|
|
163
166
|
- spec/operators/nav_spec.rb
|
|
164
167
|
- spec/operators/null_spec.rb
|