prismic.io 1.5.0 → 1.8.1

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: 8474490a3982e6d9d3b995b3a848f08ecc9dda67
4
- data.tar.gz: da268f235d65b3bf88fef8a5fb8d18d37f3556fc
2
+ SHA256:
3
+ metadata.gz: a195b1324df58d0b91d81b1dbff3e17afc26b122faa7d2722a536260b9e1a5fc
4
+ data.tar.gz: 534ff3e25a57939300ca7477c267708a82083bdfde8ebd588b6911d3689884ad
5
5
  SHA512:
6
- metadata.gz: 8d4282305f84eb5ec333a80559ffe8691bd3ff3224e4042af1fe6f04cf4824f4b3c0f5595992af71eefc63c8f5b8f4b029ccf3bd6ba29e46d284392e29d5e29b
7
- data.tar.gz: 9600c487806277d86ada6b55a02c3e86768ca5bc477dcd75310a03f2cb72f98faba2dc72cd33fe75d4e0d58467f0d6e25937edde7733cfd70455326041098284
6
+ metadata.gz: e9b4ea41ae0a9684d4827221974a32421ac8a060ca3c82d9b9c29c5be740b8ef8b458aa3799c71cb37fd7a517ce67a8cec025de42f458f6c96586850f3156946
7
+ data.tar.gz: f370301b34679faa236c6491301ec080e0a079171ff4ef3d398c086bbe27ec442ccd7470cee36445287df9df09fad314936b7a1918225a9e7113128bc56ad01b
data/.travis.yml CHANGED
@@ -1,26 +1,18 @@
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
+ - 2.6
4
+ - 2.5
5
+ - jruby-head
11
6
 
12
7
  sudo: false
13
8
  cache: bundler
14
9
 
10
+ before_install: gem install bundler
15
11
  script: bundle exec rspec spec
16
12
 
17
13
  notifications:
18
14
  email:
19
- - evo@zenexity.com
20
-
21
- addons:
22
- code_climate:
23
- repo_token: f46a7e216896abddbc4877ce065239e8ac9f575af7a120bdaa61a42be70777e9
15
+ - sebastien@prismic.io
24
16
 
25
17
  deploy:
26
18
  provider: rubygems
data/Gemfile CHANGED
@@ -4,7 +4,6 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  group :test do
7
- gem "codeclimate-test-reporter", require: nil
8
7
  gem 'hashery', '~> 2.1.1'
9
8
  gem "yajl-ruby", require: 'yajl', platforms: [:ruby_19, :ruby_20, :ruby_21]
10
9
  end
data/Gemfile.lock CHANGED
@@ -1,46 +1,38 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- prismic.io (1.4.5)
4
+ prismic.io (1.8.1)
5
5
  hashery (~> 2.1.1)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- codeclimate-test-reporter (0.4.1)
11
- simplecov (>= 0.7.1, < 1.0.0)
12
- diff-lcs (1.2.4)
13
- hashery (2.1.1)
14
- mini_portile (0.5.1)
15
- multi_json (1.8.0)
16
- nokogiri (1.6.0)
17
- mini_portile (~> 0.5.0)
18
- nokogiri (1.6.0-java)
19
- mini_portile (~> 0.5.0)
20
- rspec (2.14.1)
21
- rspec-core (~> 2.14.0)
22
- rspec-expectations (~> 2.14.0)
23
- rspec-mocks (~> 2.14.0)
24
- rspec-core (2.14.4)
25
- rspec-expectations (2.14.0)
10
+ diff-lcs (1.4.4)
11
+ hashery (2.1.2)
12
+ mini_portile2 (2.5.0)
13
+ nokogiri (1.11.1)
14
+ mini_portile2 (~> 2.5.0)
15
+ racc (~> 1.4)
16
+ racc (1.5.2)
17
+ rspec (2.99.0)
18
+ rspec-core (~> 2.99.0)
19
+ rspec-expectations (~> 2.99.0)
20
+ rspec-mocks (~> 2.99.0)
21
+ rspec-core (2.99.2)
22
+ rspec-expectations (2.99.2)
26
23
  diff-lcs (>= 1.1.3, < 2.0)
27
- rspec-mocks (2.14.2)
28
- simplecov (0.7.1)
29
- multi_json (~> 1.0)
30
- simplecov-html (~> 0.7.1)
31
- simplecov-html (0.7.1)
32
- yajl-ruby (1.1.0)
24
+ rspec-mocks (2.99.4)
25
+ yajl-ruby (1.4.1)
33
26
 
34
27
  PLATFORMS
35
- java
36
28
  ruby
37
29
 
38
30
  DEPENDENCIES
39
- bundler (~> 1.3)
40
- codeclimate-test-reporter
41
31
  hashery (~> 2.1.1)
42
32
  nokogiri (~> 1.6)
43
33
  prismic.io!
44
34
  rspec (~> 2.14)
45
- simplecov (~> 0.7)
46
35
  yajl-ruby
36
+
37
+ BUNDLED WITH
38
+ 2.1.4
data/README.md CHANGED
@@ -2,8 +2,6 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/prismic.io.png)](http://badge.fury.io/rb/prismic.io)
4
4
  [![Build Status](https://api.travis-ci.org/prismicio/ruby-kit.png)](https://travis-ci.org/prismicio/ruby-kit)
5
- [![Code Climate](https://codeclimate.com/github/prismicio/ruby-kit/badges/gpa.svg)](https://codeclimate.com/github/prismicio/ruby-kit)
6
- [![Test Coverage](https://codeclimate.com/github/prismicio/ruby-kit/badges/coverage.svg)](https://codeclimate.com/github/prismicio/ruby-kit)
7
5
 
8
6
  ### Getting Started
9
7
 
data/lib/prismic/api.rb CHANGED
@@ -135,6 +135,19 @@ module Prismic
135
135
  end
136
136
  alias :getByIDs :get_by_ids
137
137
 
138
+ # Retrieve multiple documents by their uids
139
+ # @param typ [String] the document type's name
140
+ # @param uids [String] the uids to search
141
+ # @param opts [Hash] query options (ref, etc.)
142
+
143
+ def get_by_uids(typ, uids, opts = {})
144
+ unless opts.key?("lang")
145
+ opts["lang"] = '*'
146
+ end
147
+ query(Prismic::Predicates::in('my.'+typ+'.uid', uids), opts)
148
+ end
149
+ alias :getByUIDs :get_by_uids
150
+
138
151
  # Retrieve one single typed document by its type
139
152
  # @param typ [String] the document type's name
140
153
  # @param opts [Hash] query options (ref, etc.)
@@ -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,15 @@ 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
39
+ end
40
+
41
+ def as_text
42
+ @url
34
43
  end
35
44
 
36
45
  # Returns the URL of the link
@@ -47,13 +56,14 @@ module Prismic
47
56
  end
48
57
 
49
58
  class FileLink < Link
50
- attr_accessor :url, :name, :kind, :size
59
+ attr_accessor :url, :name, :kind, :size, :target
51
60
 
52
- def initialize(url, name, kind, size)
61
+ def initialize(url, name, kind, size, target = nil)
53
62
  @url = url
54
63
  @name = name
55
64
  @kind = kind
56
65
  @size = size
66
+ @target = target
57
67
  end
58
68
 
59
69
  def as_html(link_resolver=nil)
@@ -75,10 +85,11 @@ module Prismic
75
85
  end
76
86
 
77
87
  class ImageLink < Link
78
- attr_accessor :url
88
+ attr_accessor :url, :target
79
89
 
80
- def initialize(url)
90
+ def initialize(url, target = nil)
81
91
  @url = url
92
+ @target = target
82
93
  end
83
94
 
84
95
  # Returns the URL of the link
@@ -96,9 +107,9 @@ module Prismic
96
107
 
97
108
  class DocumentLink < Link
98
109
  include Prismic::WithFragments
99
- attr_accessor :id, :uid, :type, :tags, :slug, :lang, :fragments, :broken
110
+ attr_accessor :id, :uid, :type, :tags, :slug, :lang, :fragments, :broken, :target
100
111
 
101
- def initialize(id, uid, type, tags, slug, lang, fragments, broken)
112
+ def initialize(id, uid, type, tags, slug, lang, fragments, broken, target = nil)
102
113
  @id = id
103
114
  @uid = uid
104
115
  @type = type
@@ -107,9 +118,10 @@ module Prismic
107
118
  @lang = lang
108
119
  @fragments = fragments
109
120
  @broken = broken
121
+ @target = target
110
122
  end
111
123
 
112
- def start_html(link_resolver)
124
+ def start_html(link_resolver, target = nil)
113
125
  broken? ? %(<span>) : super
114
126
  end
115
127
 
@@ -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?
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'uri'
3
+ require 'cgi'
4
+ require 'time'
4
5
 
5
6
  module Prismic
6
7
  module JsonParser
@@ -25,10 +26,20 @@ module Prismic
25
26
  'Multiple' => method(:multiple_parser),
26
27
  'Group' => method(:group_parser),
27
28
  'SliceZone' => method(:slices_parser),
28
- 'Separator' => method(:separator_parser)
29
+ 'Separator' => method(:separator_parser),
30
+ 'IntegrationFields' => method(:integration_fields_parser),
31
+ 'Boolean' => method(:boolean_field_parser)
29
32
  }
30
33
  end
31
34
 
35
+ def integration_fields_parser(json)
36
+ Prismic::Fragments::IntegrationField.new(json['value'])
37
+ end
38
+
39
+ def boolean_field_parser(json)
40
+ Prismic::Fragments::BooleanField.new(json['value'])
41
+ end
42
+
32
43
  def document_link_parser(json)
33
44
  doc = json['value']['document']
34
45
  type = doc['type']
@@ -47,18 +58,26 @@ module Prismic
47
58
  doc['uid'],
48
59
  type,
49
60
  doc['tags'],
50
- URI.unescape(doc['slug']),
61
+ CGI.unescape(doc['slug']),
51
62
  doc['lang'],
52
63
  fragments,
53
- json['value']['isBroken'])
64
+ json['value']['isBroken'],
65
+ json['value']['target'] ? json['value']['target'] : nil)
54
66
  end
55
67
 
56
68
  def image_link_parser(json)
57
- Prismic::Fragments::ImageLink.new(json['value']['image']['url'])
69
+ Prismic::Fragments::ImageLink.new(
70
+ json['value']['image']['url'],
71
+ json['value']['target'] ? json['value']['target'] : nil)
58
72
  end
59
73
 
60
74
  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'])
75
+ Prismic::Fragments::FileLink.new(
76
+ json['value']['file']['url'],
77
+ json['value']['file']['name'],
78
+ json['value']['file']['kind'],
79
+ json['value']['file']['size'],
80
+ json['value']['target'] ? json['value']['target'] : nil )
62
81
  end
63
82
 
64
83
  def text_parser(json)
@@ -74,7 +93,7 @@ module Prismic
74
93
  end
75
94
 
76
95
  def web_link_parser(json)
77
- Prismic::Fragments::WebLink.new(json['value']['url'])
96
+ Prismic::Fragments::WebLink.new(json['value']['url'], json['value']['target'])
78
97
  end
79
98
 
80
99
  def date_parser(json)
@@ -90,14 +109,7 @@ module Prismic
90
109
  end
91
110
 
92
111
  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
- )
112
+ embed_object_parser(json['value']['oembed'])
101
113
  end
102
114
 
103
115
  def geo_point_parser(json)
@@ -171,17 +183,13 @@ module Prismic
171
183
  )
172
184
  when 'image'
173
185
  Prismic::Fragments::StructuredText::Block::Image.new(
174
- view_parser(block),
175
- block['label']
186
+ view_parser(block),
187
+ block['label']
176
188
  )
177
189
  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
190
+ Prismic::Fragments::StructuredText::Block::Embed.new(
191
+ embed_object_parser(block['oembed']),
192
+ block['label']
185
193
  )
186
194
  else
187
195
  puts "Unknown bloc type: #{block['type']}"
@@ -223,7 +231,7 @@ module Prismic
223
231
 
224
232
  repeat = group_parser({ 'type' => 'Group', 'value' => data['repeat']})
225
233
 
226
- slices << Prismic::Fragments::CompositeSlice.new(slice_type, slice_label, non_repeat, repeat)
234
+ slices << Prismic::Fragments::CompositeSlice.new(slice_type, slice_label, non_repeat, repeat)
227
235
  end
228
236
  end
229
237
  Prismic::Fragments::SliceZone.new(slices)
@@ -238,7 +246,7 @@ module Prismic
238
246
  end
239
247
 
240
248
  def alternate_language_parser(alternate_language)
241
- Prismic::AlternateLanguage.new(alternate_language)
249
+ Prismic::AlternateLanguage.new(alternate_language)
242
250
  end
243
251
 
244
252
  def document_parser(json)
@@ -256,7 +264,7 @@ module Prismic
256
264
 
257
265
  alternate_languages = nil
258
266
  if json.key?('alternate_languages')
259
- alternate_languages = Hash[json['alternate_languages'].map { |doc|
267
+ alternate_languages = Hash[json['alternate_languages'].map { |doc|
260
268
  [doc['lang'], alternate_language_parser(doc)]
261
269
  }]
262
270
  end
@@ -271,7 +279,7 @@ module Prismic
271
279
  json['type'],
272
280
  json['href'],
273
281
  json['tags'],
274
- json['slugs'].map { |slug| URI.unescape(slug) },
282
+ json['slugs'].map { |slug| CGI.unescape(slug) },
275
283
  json['first_publication_date'] && Time.parse(json['first_publication_date']),
276
284
  json['last_publication_date'] && Time.parse(json['last_publication_date']),
277
285
  json['lang'],
@@ -331,6 +339,16 @@ module Prismic
331
339
  file_link_parser(json)
332
340
  end
333
341
  end
342
+
343
+ def embed_object_parser(json)
344
+ Prismic::Fragments::Embed.new(
345
+ json['type'],
346
+ json['provider_name'],
347
+ json['provider_url'],
348
+ json['html'],
349
+ json
350
+ )
351
+ end
334
352
  end
335
353
  end
336
354
  end
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  module Prismic
3
3
 
4
- VERSION = '1.5.0'
4
+ VERSION = '1.8.1'
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|
data/prismic.gemspec CHANGED
@@ -18,9 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ['lib']
20
20
 
21
- spec.add_development_dependency 'bundler', '~> 1.3'
22
21
  spec.add_development_dependency 'rspec', '~> 2.14'
23
22
  spec.add_development_dependency 'nokogiri', '~> 1.6'
24
- spec.add_development_dependency 'simplecov', '~> 0.7'
25
23
  spec.add_runtime_dependency 'hashery', '~> 2.1.1'
26
24
  end
data/spec/cache_spec.rb CHANGED
@@ -41,7 +41,7 @@ describe "Cache's" do
41
41
  @cache['fake_key3'] = 3
42
42
  end
43
43
  it 'contains some keys' do
44
- @cache.include?('fake_key1').should be_true
44
+ @cache.include?('fake_key1').should be true
45
45
  end
46
46
  it 'contains all keys' do
47
47
  @cache.intern.size.should == 3
@@ -52,8 +52,8 @@ describe "Cache's" do
52
52
  it 'keeps readed keys alive' do
53
53
  @cache['fake_key1']
54
54
  @cache['fake_key4'] = 4
55
- @cache.include?('fake_key1').should be_true
56
- @cache.include?('fake_key2').should be_false
55
+ @cache.include?('fake_key1').should be true
56
+ @cache.include?('fake_key2').should be false
57
57
  end
58
58
  end
59
59
 
@@ -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
@@ -18,7 +19,7 @@ describe 'WebLink' do
18
19
  end
19
20
 
20
21
  it "returns a HTML element with an href attribute" do
21
- Nokogiri::XML(@web_link.as_html).child.has_attribute?('href').should be_true
22
+ Nokogiri::XML(@web_link.as_html).child.has_attribute?('href').should be true
22
23
  end
23
24
 
24
25
  it "returns a HTML element with an href attribute pointing to the url" do
@@ -28,11 +29,19 @@ 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
34
- it 'raises an NotImplementedError' do
35
- expect { @web_link.as_text }.to raise_error NotImplementedError
43
+ it 'returns the url' do
44
+ @web_link.as_text.should == 'my_url'
36
45
  end
37
46
  end
38
47
 
@@ -79,7 +88,7 @@ describe 'ImageLink' do
79
88
  end
80
89
 
81
90
  it "returns a HTML element with an href attribute" do
82
- Nokogiri::XML(@image_link.as_html).child.has_attribute?('href').should be_true
91
+ Nokogiri::XML(@image_link.as_html).child.has_attribute?('href').should be true
83
92
  end
84
93
 
85
94
  it "returns a HTML element with an href attribute pointing to the url" do
@@ -360,11 +369,11 @@ describe 'Color' do
360
369
 
361
370
  describe 'self.valid?' do
362
371
  it "returns true if the color is valid" do
363
- Prismic::Fragments::Color.valid?(@hex_value).should be_true
372
+ Prismic::Fragments::Color.valid?(@hex_value).should be true
364
373
  end
365
374
 
366
375
  it "returns false if the color is not valid" do
367
- Prismic::Fragments::Color.valid?("I'm a murloc").should be_false
376
+ Prismic::Fragments::Color.valid?("I'm a murloc").should be false
368
377
  end
369
378
  end
370
379
  end
@@ -386,7 +395,7 @@ describe 'Embed' do
386
395
  end
387
396
 
388
397
  it "returns an element with a data-oembed attribute" do
389
- Nokogiri::XML(@embed.as_html).child.has_attribute?('data-oembed').should be_true
398
+ Nokogiri::XML(@embed.as_html).child.has_attribute?('data-oembed').should be true
390
399
  end
391
400
 
392
401
  it "returns an element with a data-oembed attribute containing the url" do
@@ -394,7 +403,7 @@ describe 'Embed' do
394
403
  end
395
404
 
396
405
  it "returns an element with a data-oembed-type attribute" do
397
- Nokogiri::XML(@embed.as_html).child.has_attribute?('data-oembed-type').should be_true
406
+ Nokogiri::XML(@embed.as_html).child.has_attribute?('data-oembed-type').should be true
398
407
  end
399
408
 
400
409
  it "returns an element with a data-oembed-type attribute containing the type in lowercase" do
@@ -402,7 +411,7 @@ describe 'Embed' do
402
411
  end
403
412
 
404
413
  it "returns an element with a data-oembed-provider attribute" do
405
- Nokogiri::XML(@embed.as_html).child.has_attribute?('data-oembed-provider').should be_true
414
+ Nokogiri::XML(@embed.as_html).child.has_attribute?('data-oembed-provider').should be true
406
415
  end
407
416
 
408
417
  it "returns an element with a data-oembed-provider attribute containing the provider in lowercase" 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
 
@@ -765,3 +779,24 @@ describe 'Composite slice' do
765
779
  @slices.slices[0].repeat[0]['label'].as_text.should == 'Start from Scratch'
766
780
  end
767
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
@@ -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
data/spec/micro_spec.rb CHANGED
@@ -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
data/spec/prismic_spec.rb CHANGED
@@ -118,7 +118,7 @@ describe 'Api' do
118
118
 
119
119
  describe 'master' do
120
120
  it 'returns a master Ref' do
121
- @api.master.master?.should be_true
121
+ @api.master.master?.should be true
122
122
  end
123
123
  end
124
124
 
@@ -219,11 +219,11 @@ describe 'Api' do
219
219
  end
220
220
 
221
221
  it "create fields (other than 'q') as non repeatable" do
222
- @parsed.forms['pies'].fields['ref'].repeatable.should be_false
222
+ @parsed.forms['pies'].fields['ref'].repeatable.should be false
223
223
  end
224
224
 
225
225
  it "create 'q' fields as repeatable" do
226
- @parsed.forms['pies'].fields['q'].repeatable.should be_true
226
+ @parsed.forms['pies'].fields['q'].repeatable.should be true
227
227
  end
228
228
 
229
229
  end
@@ -341,7 +341,7 @@ describe 'Document' do
341
341
  end
342
342
 
343
343
  it "returns a HTML element with a 'data-field' attribute" do
344
- Nokogiri::XML(@document.as_html(@link_resolver)).child.has_attribute?('data-field').should be_true
344
+ Nokogiri::XML(@document.as_html(@link_resolver)).child.has_attribute?('data-field').should be true
345
345
  end
346
346
 
347
347
  it "returns a HTML element with a 'data-field' attribute containing the name of the field" do
@@ -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": [
@@ -53,6 +53,15 @@ describe Prismic::API do
53
53
  end
54
54
  end
55
55
 
56
+ describe '#get_by_uids' do
57
+ it 'returns the right documents' do
58
+ docs = @api.get_by_uids('all', ['all1', 'all2'])
59
+ docs.size.should == 2
60
+ docs[0].id.should == 'WHyJqyYAAHgyXbcj'
61
+ docs[1].id.should == 'WH2PaioAALYBEgug'
62
+ end
63
+ end
64
+
56
65
  describe '#get_single' do
57
66
  it 'returns the singleton document of a type' do
58
67
  # 'single' is the type name
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'codeclimate-test-reporter'
3
- CodeClimate::TestReporter.start
4
-
5
2
  require 'nokogiri'
6
3
  begin
7
4
  require 'yajl/json_gem'
@@ -9,15 +6,12 @@ rescue LoadError
9
6
  # ok not a big deal
10
7
  require 'json'
11
8
  end
12
- require 'simplecov'
13
9
 
14
10
  RSpec.configure do |c|
15
11
  # Stop after the first failure
16
12
  # c.fail_fast = true
17
13
  end
18
14
 
19
- SimpleCov.start
20
-
21
15
  $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
22
16
 
23
17
  require 'prismic'
metadata CHANGED
@@ -1,32 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prismic.io
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.8.1
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
- autorequire:
11
+ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2017-07-28 00:00:00.000000000 Z
14
+ date: 2021-04-09 00:00:00.000000000 Z
15
15
  dependencies:
16
- - !ruby/object:Gem::Dependency
17
- name: bundler
18
- requirement: !ruby/object:Gem::Requirement
19
- requirements:
20
- - - "~>"
21
- - !ruby/object:Gem::Version
22
- version: '1.3'
23
- type: :development
24
- prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
26
- requirements:
27
- - - "~>"
28
- - !ruby/object:Gem::Version
29
- version: '1.3'
30
16
  - !ruby/object:Gem::Dependency
31
17
  name: rspec
32
18
  requirement: !ruby/object:Gem::Requirement
@@ -55,20 +41,6 @@ dependencies:
55
41
  - - "~>"
56
42
  - !ruby/object:Gem::Version
57
43
  version: '1.6'
58
- - !ruby/object:Gem::Dependency
59
- name: simplecov
60
- requirement: !ruby/object:Gem::Requirement
61
- requirements:
62
- - - "~>"
63
- - !ruby/object:Gem::Version
64
- version: '0.7'
65
- type: :development
66
- prerelease: false
67
- version_requirements: !ruby/object:Gem::Requirement
68
- requirements:
69
- - - "~>"
70
- - !ruby/object:Gem::Version
71
- version: '0.7'
72
44
  - !ruby/object:Gem::Dependency
73
45
  name: hashery
74
46
  requirement: !ruby/object:Gem::Requirement
@@ -187,6 +159,7 @@ files:
187
159
  - lib/prismic/experiments.rb
188
160
  - lib/prismic/form.rb
189
161
  - lib/prismic/fragments.rb
162
+ - lib/prismic/fragments/boolean_field.rb
190
163
  - lib/prismic/fragments/color.rb
191
164
  - lib/prismic/fragments/date.rb
192
165
  - lib/prismic/fragments/embed.rb
@@ -194,6 +167,7 @@ files:
194
167
  - lib/prismic/fragments/geopoint.rb
195
168
  - lib/prismic/fragments/group.rb
196
169
  - lib/prismic/fragments/image.rb
170
+ - lib/prismic/fragments/integration_field.rb
197
171
  - lib/prismic/fragments/link.rb
198
172
  - lib/prismic/fragments/multiple.rb
199
173
  - lib/prismic/fragments/number.rb
@@ -236,7 +210,7 @@ homepage: http://prismic.io
236
210
  licenses:
237
211
  - Apache-2
238
212
  metadata: {}
239
- post_install_message:
213
+ post_install_message:
240
214
  rdoc_options: []
241
215
  require_paths:
242
216
  - lib
@@ -251,9 +225,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
251
225
  - !ruby/object:Gem::Version
252
226
  version: '0'
253
227
  requirements: []
254
- rubyforge_project:
255
- rubygems_version: 2.2.2
256
- signing_key:
228
+ rubygems_version: 3.1.2
229
+ signing_key:
257
230
  specification_version: 4
258
231
  summary: Prismic.io development kit
259
232
  test_files: