babl-json 0.3.2 → 0.3.3
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/lib/babl.rb +12 -8
- data/lib/babl/builder/template_base.rb +2 -2
- data/lib/babl/operators/call.rb +3 -1
- data/lib/babl/operators/source.rb +2 -1
- data/lib/babl/utils.rb +1 -0
- data/lib/babl/utils/dsl_proxy.rb +44 -0
- data/lib/babl/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b410d536ca032602510a9af64d29a29dc91f536c
|
4
|
+
data.tar.gz: 9a002b4137992699842abce14054d9a21d48a92a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd1979b476227686cd13d3b994629a36fa95fbd1d55ff7d7cec466fa2304c1a414f5f1cec0a816d879d7eeb667e12934f18561c4a4920aa9be4dabd87d7d4ee0
|
7
|
+
data.tar.gz: 6b23b6086b16a94a5594cb1390fc0307881fd3fefeb8ee4e59ee67aede28c564ae7cce2d0d2a069c1417a0f108e426c16d7294bc9f5b717217fc425a546897fd
|
data/lib/babl.rb
CHANGED
@@ -11,25 +11,29 @@ module Babl
|
|
11
11
|
|
12
12
|
def initialize
|
13
13
|
@search_path = nil
|
14
|
-
@preloader =
|
14
|
+
@preloader = Rendering::NoopPreloader
|
15
15
|
@pretty = true
|
16
16
|
@cache_templates = false
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
class << self
|
21
|
-
def compile(
|
22
|
-
|
23
|
-
ctx = Babl::Operators::Partial::AbsoluteLookupContext.new(config.search_path)
|
24
|
-
template = template.with_lookup_context(ctx)
|
25
|
-
end
|
26
|
-
|
27
|
-
template.source(&source).compile(
|
21
|
+
def compile(&block)
|
22
|
+
source(&block).compile(
|
28
23
|
pretty: config.pretty,
|
29
24
|
preloader: config.preloader
|
30
25
|
)
|
31
26
|
end
|
32
27
|
|
28
|
+
def source(&block)
|
29
|
+
template = Template.new
|
30
|
+
if config.search_path
|
31
|
+
ctx = Operators::Partial::AbsoluteLookupContext.new(config.search_path)
|
32
|
+
template = template.with_lookup_context(ctx)
|
33
|
+
end
|
34
|
+
template.source(&block)
|
35
|
+
end
|
36
|
+
|
33
37
|
def configure
|
34
38
|
yield(config)
|
35
39
|
end
|
data/lib/babl/operators/call.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
require 'babl/utils'
|
2
3
|
require 'babl/errors'
|
3
4
|
|
4
5
|
module Babl
|
@@ -13,7 +14,8 @@ module Babl
|
|
13
14
|
arg = args.first
|
14
15
|
|
15
16
|
case arg
|
16
|
-
when
|
17
|
+
when Template then self.class.new(builder.wrap { |bound| arg.builder.bind(bound) })
|
18
|
+
when Utils::DslProxy then call(arg.itself)
|
17
19
|
when ::Symbol then nav(arg)
|
18
20
|
when ::Proc then call(&arg)
|
19
21
|
when ::Hash then object(**arg.map { |k, v| [:"#{k}", v] }.to_h)
|
@@ -1,11 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
require 'babl/utils'
|
2
3
|
module Babl
|
3
4
|
module Operators
|
4
5
|
module Source
|
5
6
|
module DSL
|
6
7
|
# Parse BABL source into a Template
|
7
8
|
def source(*args, &block)
|
8
|
-
call(
|
9
|
+
call(block ? Utils::DslProxy.eval(unscoped, &block) : unscoped.instance_eval(*args))
|
9
10
|
end
|
10
11
|
end
|
11
12
|
end
|
data/lib/babl/utils.rb
CHANGED
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'set'
|
3
|
+
|
4
|
+
module Babl
|
5
|
+
module Utils
|
6
|
+
# The idea is to make it possible to call method defined in block's context in addition to DSL methods.
|
7
|
+
# Inspired from https://github.com/ms-ati/docile/blob/master/lib/docile/fallback_context_proxy.rb, but
|
8
|
+
# here we do not try to handle instance variables, because as far as I know there is no way to do it
|
9
|
+
# correctly.
|
10
|
+
class DslProxy
|
11
|
+
NON_PROXIED_METHODS = Set[
|
12
|
+
:__send__, :send, :object_id, :__id__, :equal?, :instance_eval
|
13
|
+
]
|
14
|
+
|
15
|
+
instance_methods.each do |method|
|
16
|
+
undef_method(method) unless NON_PROXIED_METHODS.include?(method)
|
17
|
+
end
|
18
|
+
|
19
|
+
# rubocop:disable Style/MethodMissing
|
20
|
+
def method_missing(method, *args, &block)
|
21
|
+
if @__receiver__.respond_to?(method)
|
22
|
+
@__receiver__.__send__(method, *args, &block)
|
23
|
+
else
|
24
|
+
@__fallback__.__send__(method, *args, &block)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
# rubocop:enable Style/MethodMissing
|
28
|
+
|
29
|
+
def respond_to_missing?(method, include_private = false)
|
30
|
+
@__receiver__.respond_to?(method, include_private) ||
|
31
|
+
@__fallback__.respond_to?(method, include_private)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.eval(dsl, *args, &block)
|
35
|
+
new(dsl, block.binding.receiver).instance_eval(&block)
|
36
|
+
end
|
37
|
+
|
38
|
+
def initialize(receiver, fallback)
|
39
|
+
@__receiver__ = receiver
|
40
|
+
@__fallback__ = fallback
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/babl/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: babl-json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Frederic Terrazzoni
|
@@ -189,6 +189,7 @@ files:
|
|
189
189
|
- lib/babl/schema/typed.rb
|
190
190
|
- lib/babl/template.rb
|
191
191
|
- lib/babl/utils.rb
|
192
|
+
- lib/babl/utils/dsl_proxy.rb
|
192
193
|
- lib/babl/utils/hash.rb
|
193
194
|
- lib/babl/utils/ref.rb
|
194
195
|
- lib/babl/utils/value.rb
|