prismic.io 1.7.0 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -2
- data/Gemfile.lock +2 -2
- data/lib/prismic/fragments.rb +1 -0
- data/lib/prismic/fragments/boolean_field.rb +21 -0
- data/lib/prismic/json_parsers.rb +6 -1
- data/lib/prismic/version.rb +1 -1
- data/lib/prismic/with_fragments.rb +7 -0
- data/spec/fragments_spec.rb +21 -0
- data/spec/json_parsers_spec.rb +18 -1
- data/spec/predicates_spec.rb +13 -0
- data/spec/responses_mocks/document.json +4 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f892385baa9ad4441d83552d88db0f1633aa97288324008e2e22dfd191b95b8
|
4
|
+
data.tar.gz: 74b6efa38bcb4c81be35a39af3ce6ae40448668babc2d1070724e47efdc09226
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74bc269db0e3c96f088196b27f506f9c73109507a857e1e81e7754cddd8721425e98834df7517cd10577e539b496bfad9ff5ead09a39134fd1172c0aecd1cbab
|
7
|
+
data.tar.gz: 2cb1ad33ac5befb98b6f31d674d2753f83c2992581616b9c8360f230973e44cf14e4e02023e42ff779587f10a6b587ca6f87e00f2408cabe0c9ee44bd41acad4
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
data/lib/prismic/fragments.rb
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Prismic
|
3
|
+
module Fragments
|
4
|
+
class BooleanField < Fragment
|
5
|
+
attr_accessor :value
|
6
|
+
|
7
|
+
def initialize(value)
|
8
|
+
@value = value
|
9
|
+
end
|
10
|
+
|
11
|
+
def as_html(link_resolver=nil)
|
12
|
+
if (@value === true)
|
13
|
+
%(<input type="checkbox" checked="checked" />)
|
14
|
+
else
|
15
|
+
%(<input type="checkbox" />)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
data/lib/prismic/json_parsers.rb
CHANGED
@@ -26,7 +26,8 @@ module Prismic
|
|
26
26
|
'Group' => method(:group_parser),
|
27
27
|
'SliceZone' => method(:slices_parser),
|
28
28
|
'Separator' => method(:separator_parser),
|
29
|
-
'IntegrationFields' => method(:integration_fields_parser)
|
29
|
+
'IntegrationFields' => method(:integration_fields_parser),
|
30
|
+
'Boolean' => method(:boolean_field_parser)
|
30
31
|
}
|
31
32
|
end
|
32
33
|
|
@@ -34,6 +35,10 @@ module Prismic
|
|
34
35
|
Prismic::Fragments::IntegrationField.new(json['value'])
|
35
36
|
end
|
36
37
|
|
38
|
+
def boolean_field_parser(json)
|
39
|
+
Prismic::Fragments::BooleanField.new(json['value'])
|
40
|
+
end
|
41
|
+
|
37
42
|
def document_link_parser(json)
|
38
43
|
doc = json['value']['document']
|
39
44
|
type = doc['type']
|
data/lib/prismic/version.rb
CHANGED
@@ -156,6 +156,13 @@ module Prismic
|
|
156
156
|
fragment
|
157
157
|
end
|
158
158
|
|
159
|
+
# @return [Fragments::BooleanField]
|
160
|
+
def get_boolean_field(field)
|
161
|
+
fragment = self[field]
|
162
|
+
return nil unless fragment.is_a? Prismic::Fragments::BooleanField
|
163
|
+
fragment
|
164
|
+
end
|
165
|
+
|
159
166
|
# @return [Array<LinkedDocument>]
|
160
167
|
def linked_documents
|
161
168
|
self.fragments.map { |name, fragment|
|
data/spec/fragments_spec.rb
CHANGED
@@ -779,3 +779,24 @@ describe 'Composite slice' do
|
|
779
779
|
@slices.slices[0].repeat[0]['label'].as_text.should == 'Start from Scratch'
|
780
780
|
end
|
781
781
|
end
|
782
|
+
|
783
|
+
describe 'Boolean Field' do
|
784
|
+
it 'get html: true' do
|
785
|
+
expected_boolean_field = %[<input type="checkbox" checked="checked" />]
|
786
|
+
@booleanfield = Prismic::Fragments::BooleanField::new(true)
|
787
|
+
@booleanfield.as_html.should == expected_boolean_field
|
788
|
+
end
|
789
|
+
|
790
|
+
it 'get html: false' do
|
791
|
+
expected_boolean_field = %[<input type="checkbox" />]
|
792
|
+
@booleanfield = Prismic::Fragments::BooleanField::new(false)
|
793
|
+
@booleanfield.as_html.should == expected_boolean_field
|
794
|
+
end
|
795
|
+
|
796
|
+
it 'value' do
|
797
|
+
expected_value = true
|
798
|
+
@booleanfield = Prismic::Fragments::BooleanField::new(true)
|
799
|
+
@booleanfield.value.should == expected_value
|
800
|
+
end
|
801
|
+
|
802
|
+
end
|
data/spec/json_parsers_spec.rb
CHANGED
@@ -381,7 +381,7 @@ describe 'document_parser' do
|
|
381
381
|
end
|
382
382
|
|
383
383
|
it "correctly parses the document's fragments" do
|
384
|
-
@document.fragments.size.should ==
|
384
|
+
@document.fragments.size.should == 15
|
385
385
|
@document.fragments['name'].should be_a Prismic::Fragments::StructuredText
|
386
386
|
end
|
387
387
|
end
|
@@ -495,3 +495,20 @@ describe 'structured_text_label_parser' do
|
|
495
495
|
end
|
496
496
|
|
497
497
|
end
|
498
|
+
|
499
|
+
describe 'boolean_field_parser' do
|
500
|
+
before do
|
501
|
+
raw_json = <<json
|
502
|
+
{
|
503
|
+
"type": "Boolean",
|
504
|
+
"value": true
|
505
|
+
}
|
506
|
+
json
|
507
|
+
@json = JSON.load(raw_json)
|
508
|
+
end
|
509
|
+
|
510
|
+
it "correctly parses Boolean objects" do
|
511
|
+
bool = Prismic::JsonParser.boolean_field_parser(@json)
|
512
|
+
bool.value.should == true
|
513
|
+
end
|
514
|
+
end
|
data/spec/predicates_spec.rb
CHANGED
@@ -8,6 +8,19 @@ describe 'predicates' do
|
|
8
8
|
@api = Prismic.api('https://micro.prismic.io/api', nil)
|
9
9
|
@master_ref = @api.master_ref
|
10
10
|
@link_resolver = Prismic.link_resolver('master'){|doc_link| "http://localhost/#{doc_link.id}" }
|
11
|
+
@boolean_api = Prismic.api("https://a-bool.prismic.io/api", nil)
|
12
|
+
@boolean_api_master_ref = @boolean_api.master_ref
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'boolean query' do
|
16
|
+
it "can query a boolean field with value true" do
|
17
|
+
form = @boolean_api.form('everything').query(['at', 'my.bools.set_to_true', true])
|
18
|
+
form.data['q'].should == ['[[:d = at(my.bools.set_to_true, true)]]']
|
19
|
+
end
|
20
|
+
it "can query a boolean field with value false" do
|
21
|
+
form = @boolean_api.form('everything').query(['at', 'my.bools.set_to_true', false])
|
22
|
+
form.data['q'].should == ['[[:d = at(my.bools.set_to_true, false)]]']
|
23
|
+
end
|
11
24
|
end
|
12
25
|
|
13
26
|
describe 'at predicate' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prismic.io
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Étienne Vallette d'Osia
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2020-07-06 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|
@@ -187,6 +187,7 @@ files:
|
|
187
187
|
- lib/prismic/experiments.rb
|
188
188
|
- lib/prismic/form.rb
|
189
189
|
- lib/prismic/fragments.rb
|
190
|
+
- lib/prismic/fragments/boolean_field.rb
|
190
191
|
- lib/prismic/fragments/color.rb
|
191
192
|
- lib/prismic/fragments/date.rb
|
192
193
|
- lib/prismic/fragments/embed.rb
|
@@ -252,8 +253,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
252
253
|
- !ruby/object:Gem::Version
|
253
254
|
version: '0'
|
254
255
|
requirements: []
|
255
|
-
|
256
|
-
rubygems_version: 2.7.7
|
256
|
+
rubygems_version: 3.1.2
|
257
257
|
signing_key:
|
258
258
|
specification_version: 4
|
259
259
|
summary: Prismic.io development kit
|