prismic.io 1.4.5 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 638c0bf2d190dd248be27c4de12bef7abf3d93ba
4
- data.tar.gz: fc9492e8873f9a99d10b790f1f42fd1417e0c452
2
+ SHA256:
3
+ metadata.gz: 1f892385baa9ad4441d83552d88db0f1633aa97288324008e2e22dfd191b95b8
4
+ data.tar.gz: 74b6efa38bcb4c81be35a39af3ce6ae40448668babc2d1070724e47efdc09226
5
5
  SHA512:
6
- metadata.gz: 0ce934249d13db29217017242d1d03ddd6ad1dc86c96af0608701b12e87be4a1d81bdd91a8f9312e530d1de49378d9486d8efe065c053940ab984c5f2b56521c
7
- data.tar.gz: d390a13bb941be5bd819afcce1d1d78cd1a60905f46a7c7e0d376905d8ca25280112ec3973d2425e526143be47055c5515baf6cc4d6dd24d34d6270222e1e648
6
+ metadata.gz: 74bc269db0e3c96f088196b27f506f9c73109507a857e1e81e7754cddd8721425e98834df7517cd10577e539b496bfad9ff5ead09a39134fd1172c0aecd1cbab
7
+ data.tar.gz: 2cb1ad33ac5befb98b6f31d674d2753f83c2992581616b9c8360f230973e44cf14e4e02023e42ff779587f10a6b587ca6f87e00f2408cabe0c9ee44bd41acad4
@@ -1,17 +1,17 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.4.1
4
- - 2.3.4
5
- - 2.2.7
6
- - 2.1.1
7
- - 2.1.0
8
- - 2.0.0
9
- - 1.9.3
10
- - jruby-19mode
3
+ #- ruby-head
4
+ - 2.6.3
5
+ - 2.5.5
6
+ - 2.4.6
7
+ - jruby-head
8
+ - jruby-9.1.9.0
9
+ #- jruby-1.7.26
11
10
 
12
11
  sudo: false
13
12
  cache: bundler
14
13
 
14
+ before_install: gem install bundler:1.16.0
15
15
  script: bundle exec rspec spec
16
16
 
17
17
  notifications:
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- prismic.io (1.4.4)
4
+ prismic.io (1.7.0)
5
5
  hashery (~> 2.1.1)
6
6
 
7
7
  GEM
@@ -29,7 +29,7 @@ GEM
29
29
  multi_json (~> 1.0)
30
30
  simplecov-html (~> 0.7.1)
31
31
  simplecov-html (0.7.1)
32
- yajl-ruby (1.1.0)
32
+ yajl-ruby (1.3.1)
33
33
 
34
34
  PLATFORMS
35
35
  java
@@ -44,3 +44,6 @@ DEPENDENCIES
44
44
  rspec (~> 2.14)
45
45
  simplecov (~> 0.7)
46
46
  yajl-ruby
47
+
48
+ BUNDLED WITH
49
+ 1.17.2
@@ -15,3 +15,5 @@ require 'prismic/fragments/text'
15
15
  require 'prismic/fragments/timestamp'
16
16
  require 'prismic/fragments/slices'
17
17
  require 'prismic/fragments/separator'
18
+ require 'prismic/fragments/integration_field'
19
+ require 'prismic/fragments/boolean_field'
@@ -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
+
@@ -53,7 +53,7 @@ module Prismic
53
53
 
54
54
  def as_html(link_resolver=nil)
55
55
  html = []
56
- html << (link_to.nil? ? '' : link_to.start_html(link_resolver))
56
+ html << (link_to.nil? ? '' : link_to.start_html(link_resolver, link_to.target))
57
57
  html << %(<img src="#@url" alt="#@alt" width="#@width" height="#@height" />)
58
58
  html << (link_to.nil? ? '' : link_to.end_html)
59
59
  html.join
@@ -0,0 +1,19 @@
1
+ module Prismic
2
+ module Fragments
3
+ class IntegrationField < Fragment
4
+ attr_accessor :value
5
+
6
+ def initialize(value)
7
+ @value = value
8
+ end
9
+
10
+ def as_json
11
+ value.to_json
12
+ end
13
+
14
+ def as_text
15
+ value.to_s
16
+ end
17
+ end
18
+ end
19
+ end
@@ -3,8 +3,12 @@ module Prismic
3
3
  module Fragments
4
4
  class Link < Fragment
5
5
 
6
- def start_html(link_resolver = nil)
7
- %(<a href="#{url(link_resolver)}">)
6
+ def start_html(link_resolver = nil, target = nil)
7
+ unless target.nil?
8
+ %(<a href="#{url(link_resolver)}" target="#{target}" rel="noopener">)
9
+ else
10
+ %(<a href="#{url(link_resolver)}">)
11
+ end
8
12
  end
9
13
 
10
14
  def end_html
@@ -12,7 +16,7 @@ module Prismic
12
16
  end
13
17
 
14
18
  def as_html(link_resolver=nil)
15
- %(#{start_html(link_resolver)}#{url(link_resolver)}#{end_html})
19
+ %(#{start_html(link_resolver, @target)}#{url(link_resolver)}#{end_html})
16
20
  end
17
21
 
18
22
  # Returns the URL of the link
@@ -27,10 +31,11 @@ module Prismic
27
31
  end
28
32
 
29
33
  class WebLink < Link
30
- attr_accessor :url
34
+ attr_accessor :url, :target
31
35
 
32
- def initialize(url)
36
+ def initialize(url, target = nil)
33
37
  @url = url
38
+ @target = target
34
39
  end
35
40
 
36
41
  # Returns the URL of the link
@@ -47,13 +52,14 @@ module Prismic
47
52
  end
48
53
 
49
54
  class FileLink < Link
50
- attr_accessor :url, :name, :kind, :size
55
+ attr_accessor :url, :name, :kind, :size, :target
51
56
 
52
- def initialize(url, name, kind, size)
57
+ def initialize(url, name, kind, size, target = nil)
53
58
  @url = url
54
59
  @name = name
55
60
  @kind = kind
56
61
  @size = size
62
+ @target = target
57
63
  end
58
64
 
59
65
  def as_html(link_resolver=nil)
@@ -75,10 +81,11 @@ module Prismic
75
81
  end
76
82
 
77
83
  class ImageLink < Link
78
- attr_accessor :url
84
+ attr_accessor :url, :target
79
85
 
80
- def initialize(url)
86
+ def initialize(url, target = nil)
81
87
  @url = url
88
+ @target = target
82
89
  end
83
90
 
84
91
  # Returns the URL of the link
@@ -96,9 +103,9 @@ module Prismic
96
103
 
97
104
  class DocumentLink < Link
98
105
  include Prismic::WithFragments
99
- attr_accessor :id, :uid, :type, :tags, :slug, :lang, :fragments, :broken
106
+ attr_accessor :id, :uid, :type, :tags, :slug, :lang, :fragments, :broken, :target
100
107
 
101
- def initialize(id, uid, type, tags, slug, lang, fragments, broken)
108
+ def initialize(id, uid, type, tags, slug, lang, fragments, broken, target = nil)
102
109
  @id = id
103
110
  @uid = uid
104
111
  @type = type
@@ -107,9 +114,10 @@ module Prismic
107
114
  @lang = lang
108
115
  @fragments = fragments
109
116
  @broken = broken
117
+ @target = target
110
118
  end
111
119
 
112
- def start_html(link_resolver)
120
+ def start_html(link_resolver, target = nil)
113
121
  broken? ? %(<span>) : super
114
122
  end
115
123
 
@@ -2,8 +2,57 @@
2
2
  module Prismic
3
3
  module Fragments
4
4
 
5
- # A fragment of type Slice, an item in a SliceZone
6
- class Slice < Fragment
5
+ # A fragment of type CompositeSlice, an item in a SliceZone
6
+ class CompositeSlice < Fragment
7
+ attr_accessor :slice_type
8
+ attr_accessor :slice_label
9
+ attr_accessor :non_repeat
10
+ attr_accessor :repeat
11
+
12
+ def initialize(slice_type, slice_label, non_repeat, repeat)
13
+ @slice_type = slice_type
14
+ @slice_label = slice_label
15
+ @non_repeat = non_repeat
16
+ @repeat = repeat
17
+ end
18
+
19
+ # Generate an text representation of the group
20
+ #
21
+ # @return [String] the text representation
22
+ def as_text
23
+ non_repeat_text = ''
24
+ @non_repeat.each do |fragment_key, fragment_value|
25
+ non_repeat_text += fragment_value.as_text
26
+ end
27
+
28
+ "#{non_repeat_text}\n#{@repeat.as_text}"
29
+ end
30
+
31
+ # Generate an HTML representation of the group
32
+ #
33
+ # @param link_resolver [LinkResolver] The LinkResolver used to build
34
+ # application's specific URL
35
+ #
36
+ # @return [String] the HTML representation
37
+ def as_html(link_resolver=nil)
38
+ classes = ['slice']
39
+ unless (@slice_label.nil?)
40
+ classes.push(@slice_label)
41
+ end
42
+
43
+ non_repeat_html = ''
44
+ @non_repeat.each do |fragment_key, fragment_value|
45
+ non_repeat_html += fragment_value.as_html(link_resolver)
46
+ end
47
+
48
+ repeat_html = repeat.as_html(link_resolver)
49
+
50
+ %[<div data-slicetype="#{@slice_type}" class="#{classes.join(' ')}">#{non_repeat_html + repeat_html}</div>]
51
+ end
52
+ end
53
+
54
+ # A fragment of type SimpleSlice, an item in a SliceZone
55
+ class SimpleSlice < Fragment
7
56
  attr_accessor :slice_type
8
57
  attr_accessor :slice_label
9
58
  attr_accessor :value
@@ -138,6 +138,8 @@ module Prismic
138
138
  def serialize(text, link_resolver = nil)
139
139
  if link.is_a? Prismic::Fragments::DocumentLink and link.broken
140
140
  "<span>#{text}</span>"
141
+ elsif !link.target.nil?
142
+ %(<a href="#{link.url(link_resolver)}" target="#{link.target}" rel="noopener">#{text}</a>)
141
143
  else
142
144
  %(<a href="#{link.url(link_resolver)}">#{text}</a>)
143
145
  end
@@ -370,13 +372,29 @@ module Prismic
370
372
  end
371
373
 
372
374
  class Embed < Block
373
- attr_accessor :label
375
+ attr_accessor :embed, :label
374
376
 
375
377
  def initialize(embed, label)
376
378
  @embed = embed
377
379
  @label = label
378
380
  end
379
381
 
382
+ def embed_type
383
+ @embed.embed_type
384
+ end
385
+
386
+ def provider
387
+ @embed.provider
388
+ end
389
+
390
+ def url
391
+ @embed.url
392
+ end
393
+
394
+ def html
395
+ @embed.html
396
+ end
397
+
380
398
  def as_html(link_resolver, html_serializer = nil)
381
399
  custom = nil
382
400
  unless html_serializer.nil?
@@ -25,10 +25,20 @@ module Prismic
25
25
  'Multiple' => method(:multiple_parser),
26
26
  'Group' => method(:group_parser),
27
27
  'SliceZone' => method(:slices_parser),
28
- 'Separator' => method(:separator_parser)
28
+ 'Separator' => method(:separator_parser),
29
+ 'IntegrationFields' => method(:integration_fields_parser),
30
+ 'Boolean' => method(:boolean_field_parser)
29
31
  }
30
32
  end
31
33
 
34
+ def integration_fields_parser(json)
35
+ Prismic::Fragments::IntegrationField.new(json['value'])
36
+ end
37
+
38
+ def boolean_field_parser(json)
39
+ Prismic::Fragments::BooleanField.new(json['value'])
40
+ end
41
+
32
42
  def document_link_parser(json)
33
43
  doc = json['value']['document']
34
44
  type = doc['type']
@@ -50,15 +60,23 @@ module Prismic
50
60
  URI.unescape(doc['slug']),
51
61
  doc['lang'],
52
62
  fragments,
53
- json['value']['isBroken'])
63
+ json['value']['isBroken'],
64
+ json['value']['target'] ? json['value']['target'] : nil)
54
65
  end
55
66
 
56
67
  def image_link_parser(json)
57
- Prismic::Fragments::ImageLink.new(json['value']['image']['url'])
68
+ Prismic::Fragments::ImageLink.new(
69
+ json['value']['image']['url'],
70
+ json['value']['target'] ? json['value']['target'] : nil)
58
71
  end
59
72
 
60
73
  def file_link_parser(json)
61
- Prismic::Fragments::FileLink.new(json['value']['file']['url'], json['value']['file']['name'], json['value']['file']['kind'], json['value']['file']['size'])
74
+ Prismic::Fragments::FileLink.new(
75
+ json['value']['file']['url'],
76
+ json['value']['file']['name'],
77
+ json['value']['file']['kind'],
78
+ json['value']['file']['size'],
79
+ json['value']['target'] ? json['value']['target'] : nil )
62
80
  end
63
81
 
64
82
  def text_parser(json)
@@ -74,7 +92,7 @@ module Prismic
74
92
  end
75
93
 
76
94
  def web_link_parser(json)
77
- Prismic::Fragments::WebLink.new(json['value']['url'])
95
+ Prismic::Fragments::WebLink.new(json['value']['url'], json['value']['target'])
78
96
  end
79
97
 
80
98
  def date_parser(json)
@@ -90,14 +108,7 @@ module Prismic
90
108
  end
91
109
 
92
110
  def embed_parser(json)
93
- oembed = json['value']['oembed']
94
- Prismic::Fragments::Embed.new(
95
- oembed['type'],
96
- oembed['provider_name'],
97
- oembed['provider_url'],
98
- oembed['html'],
99
- oembed
100
- )
111
+ embed_object_parser(json['value']['oembed'])
101
112
  end
102
113
 
103
114
  def geo_point_parser(json)
@@ -171,17 +182,13 @@ module Prismic
171
182
  )
172
183
  when 'image'
173
184
  Prismic::Fragments::StructuredText::Block::Image.new(
174
- view_parser(block),
175
- block['label']
185
+ view_parser(block),
186
+ block['label']
176
187
  )
177
188
  when 'embed'
178
- boembed = block['oembed']
179
- Prismic::Fragments::Embed.new(
180
- boembed['type'],
181
- boembed['provider_name'],
182
- boembed['provider_url'],
183
- boembed['html'],
184
- boembed
189
+ Prismic::Fragments::StructuredText::Block::Embed.new(
190
+ embed_object_parser(block['oembed']),
191
+ block['label']
185
192
  )
186
193
  else
187
194
  puts "Unknown bloc type: #{block['type']}"
@@ -208,8 +215,23 @@ module Prismic
208
215
 
209
216
  def slices_parser(json)
210
217
  slices = []
218
+
211
219
  json['value'].each do |data|
212
- slices << Prismic::Fragments::Slice.new(data['slice_type'], data['slice_label'], fragment_parser(data['value']))
220
+ slice_type = data['slice_type']
221
+ slice_label = data['slice_label']
222
+
223
+ if data.key?('value')
224
+ slices << Prismic::Fragments::SimpleSlice.new(slice_type, slice_label, fragment_parser(data['value']))
225
+ else
226
+ non_repeat = {}
227
+ data['non-repeat'].each do |fragment_key, fragment_value|
228
+ non_repeat[fragment_key] = fragment_parser(fragment_value)
229
+ end
230
+
231
+ repeat = group_parser({ 'type' => 'Group', 'value' => data['repeat']})
232
+
233
+ slices << Prismic::Fragments::CompositeSlice.new(slice_type, slice_label, non_repeat, repeat)
234
+ end
213
235
  end
214
236
  Prismic::Fragments::SliceZone.new(slices)
215
237
  end
@@ -223,7 +245,7 @@ module Prismic
223
245
  end
224
246
 
225
247
  def alternate_language_parser(alternate_language)
226
- Prismic::AlternateLanguage.new(alternate_language)
248
+ Prismic::AlternateLanguage.new(alternate_language)
227
249
  end
228
250
 
229
251
  def document_parser(json)
@@ -241,7 +263,7 @@ module Prismic
241
263
 
242
264
  alternate_languages = nil
243
265
  if json.key?('alternate_languages')
244
- alternate_languages = Hash[json['alternate_languages'].map { |doc|
266
+ alternate_languages = Hash[json['alternate_languages'].map { |doc|
245
267
  [doc['lang'], alternate_language_parser(doc)]
246
268
  }]
247
269
  end
@@ -316,6 +338,16 @@ module Prismic
316
338
  file_link_parser(json)
317
339
  end
318
340
  end
341
+
342
+ def embed_object_parser(json)
343
+ Prismic::Fragments::Embed.new(
344
+ json['type'],
345
+ json['provider_name'],
346
+ json['provider_url'],
347
+ json['html'],
348
+ json
349
+ )
350
+ end
319
351
  end
320
352
  end
321
353
  end
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  module Prismic
3
3
 
4
- VERSION = '1.4.5'
4
+ VERSION = '1.8.0'
5
5
 
6
6
  end
@@ -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|
@@ -11,6 +11,7 @@ end
11
11
  describe 'WebLink' do
12
12
  before do
13
13
  @web_link = Prismic::Fragments::WebLink.new('my_url')
14
+ @target_blank = Prismic::Fragments::WebLink.new('my_url', '_blank')
14
15
  end
15
16
  describe 'as_html' do
16
17
  it "returns an <a> HTML element" do
@@ -28,6 +29,14 @@ describe 'WebLink' do
28
29
  it "returns a HTML element whose content is the link" do
29
30
  Nokogiri::XML(@web_link.as_html).child.content.should == 'my_url'
30
31
  end
32
+
33
+ it "returns an <a> HTML element with a target attribute" do
34
+ Nokogiri::XML(@target_blank.as_html).child.has_attribute?('target').should be_true
35
+ end
36
+
37
+ it "returns an <a> HTML element with an target blank attribute" do
38
+ Nokogiri::XML(@target_blank.as_html).child.attribute('target').value.should == '_blank'
39
+ end
31
40
  end
32
41
 
33
42
  describe 'as_text' do
@@ -650,6 +659,8 @@ describe 'StructuredText::Hyperlink' do
650
659
  )
651
660
  @hyperlink = Prismic::Fragments::StructuredText::Span::Hyperlink.new(0, 0, @link)
652
661
  @link_resolver = Prismic.link_resolver("master"){|doc_link| "http://localhost/#{doc_link.id}" }
662
+ @target_blank = Prismic::Fragments::WebLink.new("link_url", "_blank")
663
+ @target_hyperlink = Prismic::Fragments::StructuredText::Span::Hyperlink.new(0, 0, @target_blank)
653
664
  end
654
665
 
655
666
  describe 'as_html' do
@@ -663,6 +674,9 @@ describe 'StructuredText::Hyperlink' do
663
674
  @link.broken = true
664
675
  @hyperlink.serialize('', @link_resolver).should == '<span></span>'
665
676
  end
677
+ it "can generate valid html for target blank" do
678
+ @target_hyperlink.serialize('', @link_resolver).should == '<a href="link_url" target="_blank" rel="noopener"></a>'
679
+ end
666
680
  end
667
681
  end
668
682
 
@@ -720,9 +734,9 @@ describe 'Group' do
720
734
 
721
735
  end
722
736
 
723
- describe 'Slices' do
737
+ describe 'Simple slice' do
724
738
  before do
725
- @raw_json_slices = File.read("#{File.dirname(__FILE__)}/responses_mocks/slices.json")
739
+ @raw_json_slices = File.read("#{File.dirname(__FILE__)}/responses_mocks/simple_slice.json")
726
740
  @json_slices = JSON.load(@raw_json_slices)
727
741
  @doc = Prismic::JsonParser.document_parser(@json_slices)
728
742
  @slices = @doc.get_slice_zone("article.blocks")
@@ -734,4 +748,55 @@ describe 'Slices' do
734
748
  @slices.as_html(@link_resolver).gsub('&#39;', "'").should == %[<div data-slicetype="features" class="slice features-label"><section data-field="illustration"><img src="https://wroomdev.s3.amazonaws.com/toto/db3775edb44f9818c54baa72bbfc8d3d6394b6ef_hsf_evilsquall.jpg" alt="" width="4285" height="709" /></section>\n<section data-field="title"><span class="text">c'est un bloc features</span></section></div>\n<div data-slicetype="text" class="slice"><p>C'est un bloc content</p></div>\n<div data-slicetype="separator" class="slice"><section data-field="sep"><hr class="separator" /></section></div>]
735
749
  end
736
750
 
751
+ it 'get item correctly' do
752
+ expected_url = 'https://wroomdev.s3.amazonaws.com/toto/db3775edb44f9818c54baa72bbfc8d3d6394b6ef_hsf_evilsquall.jpg'
753
+ @slices.slices[0].value[0]["illustration"].url.should == expected_url
754
+ end
755
+ end
756
+
757
+ describe 'Composite slice' do
758
+ before do
759
+ @raw_json_slices = File.read("#{File.dirname(__FILE__)}/responses_mocks/composite_slice.json")
760
+ @json_slices = JSON.load(@raw_json_slices)
761
+ @doc = Prismic::JsonParser.document_parser(@json_slices)
762
+ @slices = @doc.get_slice_zone("nav-nodejs.items")
763
+ @link_resolver = Prismic.link_resolver('master'){|doc_link| "http://localhost/#{doc_link.type}/#{doc_link.id}" }
764
+ end
765
+
766
+ it 'get html' do
767
+ @slices.as_html(@link_resolver).gsub('&#39;', "'").should == %[<div data-slicetype="with-submenu" class="slice"><p>Getting Started</p><section data-field="label"><p>Start from Scratch</p></section>\n<section data-field="link"><a href="http://localhost/page-nodejs/WPeD0SoAACsABzNC">page---nodejs---getting-started-with-the-starter-kit</a></section></div>]
768
+ end
769
+
770
+ it 'get text' do
771
+ @slices.as_text.should == %[Getting Started\nStart from Scratch\n]
772
+ end
773
+
774
+ it 'get item in non-repeat correctly' do
775
+ @slices.slices[0].non_repeat['label'].as_text.should == 'Getting Started'
776
+ end
777
+
778
+ it 'get item in repeat correctly' do
779
+ @slices.slices[0].repeat[0]['label'].as_text.should == 'Start from Scratch'
780
+ end
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
+
737
802
  end
@@ -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 == 14
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
@@ -11,7 +11,7 @@ describe 'micro' do
11
11
  describe 'embed block in structured text fragments' do
12
12
  it 'is of the right Embed object, and serializes well' do
13
13
  fragment = @api.form('everything').query(%w(at document.id UrjI1gEAALOCeO5i)).submit(@master_ref)[0]['article.body']
14
- fragment.blocks[4].is_a?(Prismic::Fragments::Embed).should == true
14
+ fragment.blocks[4].is_a?(Prismic::Fragments::StructuredText::Block::Embed).should == true
15
15
  fragment.as_html(@link_resolver).gsub(/[\n\r]+/, '').gsub(/ +/, ' ').gsub(/&#39;/, "'").should == %(<h2>The meta-micro mailing-list</h2><p>This is where you go to give feedback, and discuss the future of micro. <a href="https://groups.google.com/forum/?hl=en#!forum/micro-meta-framework">Subscribe to the list now</a>!</p><h2>The micro GitHub repository</h2><p>This is where you get truly active, by forking the project's source code, and making it better. Please always feel free to send us pull requests.</p><div data-oembed="" data-oembed-type="link" data-oembed-provider="object"><div data-type="object"><a href="https://github.com/rudyrigot/meta-micro"><h1>rudyrigot/meta-micro</h1><img src="https://avatars2.githubusercontent.com/u/552279?s=400"><p>The meta-micro-framework you simply need</p></a></div></div><h2>Report bugs on micro</h2><p>If you think micro isn't working properly in one of its features, <a href="https://github.com/rudyrigot/meta-micro/issues">open a new issue in the micro GitHub repository</a>.</p><h2>Ask for help</h2><p>Feel free to ask a new question <a href="http://stackoverflow.com/questions/tagged/meta-micro">on StackOverflow</a>.</p>)
16
16
  end
17
17
  end
@@ -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
@@ -0,0 +1,63 @@
1
+ {
2
+ "id": "WPeLbyoAACsAB1Su",
3
+ "uid": null,
4
+ "type": "nav-nodejs",
5
+ "href": "http://prismicio-docs.prismic.io/api/v1/documents/search?ref=WXnqmigAALs3V7Kx&q=%5B%5B%3Ad+%3D+at%28document.id%2C+%22WPeLbyoAACsAB1Su%22%29+%5D%5D",
6
+ "tags": [],
7
+ "first_publication_date": "2017-04-19T16:08:43+0000",
8
+ "last_publication_date": "2017-07-07T11:26:27+0000",
9
+ "slugs": ["navigation---nodejs", "navigation-nodejs"],
10
+ "data": {
11
+ "nav-nodejs": {
12
+ "display-name": {
13
+ "type": "StructuredText",
14
+ "value": [{
15
+ "type": "paragraph",
16
+ "text": "Navigation - NodeJS",
17
+ "spans": []
18
+ }]
19
+ },
20
+ "items": {
21
+ "type": "SliceZone",
22
+ "value": [{
23
+ "type": "Slice",
24
+ "slice_type": "with-submenu",
25
+ "slice_label": null,
26
+ "repeat": [{
27
+ "label": {
28
+ "type": "StructuredText",
29
+ "value": [{
30
+ "type": "paragraph",
31
+ "text": "Start from Scratch",
32
+ "spans": []
33
+ }]
34
+ },
35
+ "link": {
36
+ "type": "Link.document",
37
+ "value": {
38
+ "document": {
39
+ "id": "WPeD0SoAACsABzNC",
40
+ "type": "page-nodejs",
41
+ "tags": [],
42
+ "slug": "page---nodejs---getting-started-with-the-starter-kit",
43
+ "uid": "prismic-from-scratch-with-nodejs"
44
+ },
45
+ "isBroken": false
46
+ }
47
+ }
48
+ }],
49
+ "non-repeat": {
50
+ "label": {
51
+ "type": "StructuredText",
52
+ "value": [{
53
+ "type": "paragraph",
54
+ "text": "Getting Started",
55
+ "spans": []
56
+ }]
57
+ }
58
+ }
59
+ }]
60
+ }
61
+ }
62
+ }
63
+ }
@@ -36,6 +36,10 @@
36
36
  }
37
37
  ]
38
38
  },
39
+ "checkbox": {
40
+ "type": "Boolean",
41
+ "value": true
42
+ },
39
43
  "short_lede": {
40
44
  "type": "StructuredText",
41
45
  "value": [
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prismic.io
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.5
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
- - "Étienne Vallette d'Osia"
7
+ - Étienne Vallette d'Osia
8
8
  - Erwan Loisant
9
9
  - Samy Dindane
10
10
  - Rudy Rigot
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2017-07-05 00:00:00.000000000 Z
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
@@ -194,6 +195,7 @@ files:
194
195
  - lib/prismic/fragments/geopoint.rb
195
196
  - lib/prismic/fragments/group.rb
196
197
  - lib/prismic/fragments/image.rb
198
+ - lib/prismic/fragments/integration_field.rb
197
199
  - lib/prismic/fragments/link.rb
198
200
  - lib/prismic/fragments/multiple.rb
199
201
  - lib/prismic/fragments/number.rb
@@ -218,11 +220,12 @@ files:
218
220
  - spec/predicates_spec.rb
219
221
  - spec/prismic_spec.rb
220
222
  - spec/responses_mocks/api.json
223
+ - spec/responses_mocks/composite_slice.json
221
224
  - spec/responses_mocks/document.json
222
225
  - spec/responses_mocks/document_with_unknown_fragment.json
223
226
  - spec/responses_mocks/experiments.json
224
227
  - spec/responses_mocks/fragments.json
225
- - spec/responses_mocks/slices.json
228
+ - spec/responses_mocks/simple_slice.json
226
229
  - spec/responses_mocks/structured_text_heading.json
227
230
  - spec/responses_mocks/structured_text_image_with_link.json
228
231
  - spec/responses_mocks/structured_text_linkfile.json
@@ -250,8 +253,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
250
253
  - !ruby/object:Gem::Version
251
254
  version: '0'
252
255
  requirements: []
253
- rubyforge_project:
254
- rubygems_version: 2.2.2
256
+ rubygems_version: 3.1.2
255
257
  signing_key:
256
258
  specification_version: 4
257
259
  summary: Prismic.io development kit
@@ -265,11 +267,12 @@ test_files:
265
267
  - spec/predicates_spec.rb
266
268
  - spec/prismic_spec.rb
267
269
  - spec/responses_mocks/api.json
270
+ - spec/responses_mocks/composite_slice.json
268
271
  - spec/responses_mocks/document.json
269
272
  - spec/responses_mocks/document_with_unknown_fragment.json
270
273
  - spec/responses_mocks/experiments.json
271
274
  - spec/responses_mocks/fragments.json
272
- - spec/responses_mocks/slices.json
275
+ - spec/responses_mocks/simple_slice.json
273
276
  - spec/responses_mocks/structured_text_heading.json
274
277
  - spec/responses_mocks/structured_text_image_with_link.json
275
278
  - spec/responses_mocks/structured_text_linkfile.json