prismic.io 1.3.5 → 1.4.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4c967051cf02c9b32c0efea073d4180ded1daa9c
4
- data.tar.gz: 4a5fcb9e4d376fc317e8cc53bdcc84478130dc36
3
+ metadata.gz: a60dbb4b693926554c328099d394411b071b4a65
4
+ data.tar.gz: 9c8dfd97d137e2d40caae80449853fae4acabf15
5
5
  SHA512:
6
- metadata.gz: 07b4f1a729ee39850383da4356f55b5b3443f48c7c5ba21a97e7576af5ba664081fb35040499832ae67382b10ea6e444bf3dfefcc05aa2a975f46a702a078ade
7
- data.tar.gz: c38b558b6035ffeb43b296db4afe6a756158a5080cbcd0f77398ed6f35061b715ac91fd9502c302de20b3de26891c299b82f2cb841cb80d8eb09f41e8a6f8242
6
+ metadata.gz: 80ebc8910d0034882ff8ed3d7a75a26412c30be715a386f50d4194476b8d57e048ef17182003d113fb000b67b1f399dc33b32bb6bb3d17f1f13c191bcda69110
7
+ data.tar.gz: 8ade34a126227b09778476b7cc1b2683a7c61e6baf7e9656c7469c2c87916087d0fd045c1380686d0082a61affe31436acaeb7dea3fa5c76ee11911f8824d307
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- prismic.io (1.3.5)
4
+ prismic.io (1.4.0)
5
5
  hashery (~> 2.1.1)
6
6
 
7
7
  GEM
data/lib/prismic/api.rb CHANGED
@@ -83,6 +83,38 @@ module Prismic
83
83
  form(name, data, ref)
84
84
  end
85
85
 
86
+ # Perform a query on this API. Use the master reference is no ref is specified in data.
87
+ # @param q [String] the query to perform
88
+ # @param data [Hash] query options (page, pageSize, ref, etc.)
89
+ def query(q, data={})
90
+ ref = data['ref'] || self.master.ref
91
+ form('everything', data).query(q).submit(ref)
92
+ end
93
+
94
+ # Retrieve one document by its id
95
+ # @param q [String] the query to perform
96
+ # @param data [Hash] query options (page, pageSize, ref, etc.)
97
+ # @return the document, or nil if not found
98
+ def getByID(id, data={})
99
+ query(Prismic::Predicates::at('document.id', id), data)[0]
100
+ end
101
+
102
+ # Retrieve one document by its uid
103
+ # @param q [String] the query to perform
104
+ # @param data [Hash] query options (page, pageSize, ref, etc.)
105
+ # @return the document, or nil if not found
106
+ def getByUID(typ, uid, data={})
107
+ query(Prismic::Predicates::at('my.'+typ+'.uid', uid), data)[0]
108
+ end
109
+
110
+ # Retrieve multiple documents by their ids
111
+ # @param q [String] the query to perform
112
+ # @param data [Hash] query options (page, pageSize, ref, etc.)
113
+ # @return the document, or nil if not found
114
+ def getByIDs(ids, data={})
115
+ query(Prismic::Predicates::in('document.id', ids), data)
116
+ end
117
+
86
118
  # Return the URL to display a given preview
87
119
  # @param token [String] as received from Prismic server to identify the content to preview
88
120
  # @param link_resolver the link resolver to build URL for your site
@@ -5,6 +5,10 @@ module Prismic
5
5
  ['at', fragment, value]
6
6
  end
7
7
 
8
+ def self.in(fragment, value)
9
+ ['in', fragment, value]
10
+ end
11
+
8
12
  def self.any(fragment, values)
9
13
  ['any', fragment, values]
10
14
  end
@@ -17,6 +21,14 @@ module Prismic
17
21
  ['similar', fragment, value]
18
22
  end
19
23
 
24
+ def self.has(fragment)
25
+ ['has', fragment]
26
+ end
27
+
28
+ def self.missing(fragment)
29
+ ['missing', fragment]
30
+ end
31
+
20
32
  def self.gt(fragment, value)
21
33
  ['number.gt', fragment, value]
22
34
  end
@@ -81,6 +93,14 @@ module Prismic
81
93
  ['date.year', fragment, year]
82
94
  end
83
95
 
96
+ def self.year_before(fragment, year)
97
+ ['date.year-before', fragment, year]
98
+ end
99
+
100
+ def self.year_after(fragment, year)
101
+ ['date.year-after', fragment, year]
102
+ end
103
+
84
104
  def self.hour(fragment, hour)
85
105
  ['date.hour', fragment, hour]
86
106
  end
@@ -110,4 +130,4 @@ module Prismic
110
130
  private_class_method :as_timestamp
111
131
 
112
132
  end
113
- end
133
+ end
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  module Prismic
3
3
 
4
- VERSION = '1.3.5'
4
+ VERSION = '1.4.0'
5
5
 
6
6
  end
data/spec/doc_spec.rb CHANGED
@@ -28,10 +28,7 @@ describe 'Documentation' do
28
28
  api = Prismic.api('https://lesbonneschoses.cdn.prismic.io/api', preview_token)
29
29
  st_patrick_ref = api.ref('St-Patrick specials')
30
30
  # Now we'll use this reference for all our calls
31
- response = api.form('everything')
32
- .ref(st_patrick_ref)
33
- .query(Prismic::Predicates::at('document.type', 'product'))
34
- .submit
31
+ response = api.query(Prismic::Predicates::at('document.type', 'product'), 'ref' => st_patrick_ref)
35
32
  # The Response object contains all documents of type "product"
36
33
  # including the new "Saint-Patrick's Cupcake"
37
34
  # endgist
@@ -105,11 +102,7 @@ describe 'Documentation' do
105
102
 
106
103
  it 'text' do
107
104
  api = Prismic::api('https://lesbonneschoses.cdn.prismic.io/api')
108
- response = api.form('everything')
109
- .query(Predicates::at('document.id', 'UlfoxUnM0wkXYXbl'))
110
- .ref(api.master_ref)
111
- .submit
112
- doc = response[0]
105
+ doc = api.getByID('UlfoxUnM0wkXYXbl')
113
106
  # startgist:4cbc1abffe7cc1209f95:prismic-getText.rb
114
107
  author = doc.get_text('blog-post.author')
115
108
  if author == nil
@@ -668,11 +668,11 @@ describe 'Group' do
668
668
  @micro_api = Prismic.api('https://micro.prismic.io/api', nil)
669
669
  @master_ref = @micro_api.master_ref
670
670
  @docchapter = @micro_api.form('everything').query('[[:d = at(document.type, "docchapter")]]').orderings('[my.docchapter.priority]').submit(@master_ref)[0]
671
- @link_resolver = Prismic.link_resolver('master'){|doc_link| "http://localhost/#{doc_link.link_type}/#{doc_link.id}" }
671
+ @link_resolver = Prismic.link_resolver('master'){|doc_link| "http://localhost/#{doc_link.type}/#{doc_link.id}" }
672
672
  end
673
673
 
674
674
  it 'accesses fields the proper way' do
675
- @docchapter['docchapter.docs'][0]['linktodoc'].link_type.should == 'doc'
675
+ @docchapter['docchapter.docs'][0]['linktodoc'].type.should == 'doc'
676
676
  end
677
677
 
678
678
  it 'serializes towards HTML as expected' do
@@ -708,7 +708,7 @@ describe 'Slices' do
708
708
  @json_slices = JSON.load(@raw_json_slices)
709
709
  @doc = Prismic::JsonParser.document_parser(@json_slices)
710
710
  @slices = @doc.get_slice_zone("article.blocks")
711
- @link_resolver = Prismic.link_resolver('master'){|doc_link| "http://localhost/#{doc_link.link_type}/#{doc_link.id}" }
711
+ @link_resolver = Prismic.link_resolver('master'){|doc_link| "http://localhost/#{doc_link.type}/#{doc_link.id}" }
712
712
  end
713
713
 
714
714
  it 'parses correctly' do
@@ -23,7 +23,7 @@ json
23
23
  it "correctly parses DocumentLinks" do
24
24
  document_link = Prismic::JsonParser.document_link_parser(@json)
25
25
  document_link.id.should == "UdUjvt_mqVNObPeO"
26
- document_link.link_type.should == "product"
26
+ document_link.type.should == "product"
27
27
  document_link.tags.should == ['Macaron']
28
28
  document_link.slug.should == "dark-chocolate-macaron"
29
29
  document_link.broken?.should == false
@@ -20,12 +20,9 @@ describe 'LesBonnesChoses' do
20
20
  end
21
21
 
22
22
  it 'queries macarons (using a predicate) and returns 7 documents' do
23
- @api.form('everything')
24
- .query('[[:d = any(document.tags, ["Macaron"])]]')
25
- .submit(@master_ref).results.size.should == 7
26
- @api.form('everything')
27
- .query('[[:d = any(document.tags, ["Macaron"])]]')
28
- .submit(@master_ref).size.should == 7
23
+ @api.query('[[:d = any(document.tags, ["Macaron"])]]')
24
+ .results.size.should == 7
25
+ @api.query('[[:d = any(document.tags, ["Macaron"])]]').size.should == 7
29
26
  end
30
27
 
31
28
  it 'queries macarons (using a form) and returns 7 documents' do
@@ -28,6 +28,13 @@ describe 'predicates' do
28
28
  end
29
29
  end
30
30
 
31
+ describe 'fulltext predicate' do
32
+ it 'with helper serializes well' do
33
+ form = @api.form('everything').query(Predicates.fulltext('document.type', ['article', 'blog-post']))
34
+ form.data['q'].should == ['[[:d = fulltext(document.type, ["article", "blog-post"])]]']
35
+ end
36
+ end
37
+
31
38
  describe 'similar predicate' do
32
39
  it 'as an array serializes well' do
33
40
  form = @api.form('everything').query(['similar', 'idOfSomeDocument', 10])
@@ -39,6 +46,28 @@ describe 'predicates' do
39
46
  end
40
47
  end
41
48
 
49
+ describe 'has predicate' do
50
+ it 'as an array serializes well' do
51
+ form = @api.form('everything').query(['has', 'my.blog-post.author'])
52
+ form.data['q'].should == ['[[:d = has(my.blog-post.author)]]']
53
+ end
54
+ it 'with helpers serializes well' do
55
+ form = @api.form('everything').query(Predicates.has('my.blog-post.author'))
56
+ form.data['q'].should == ['[[:d = has(my.blog-post.author)]]']
57
+ end
58
+ end
59
+
60
+ describe 'missing predicate' do
61
+ it 'as an array serializes well' do
62
+ form = @api.form('everything').query(['missing', 'my.blog-post.author'])
63
+ form.data['q'].should == ['[[:d = missing(my.blog-post.author)]]']
64
+ end
65
+ it 'with helpers serializes well' do
66
+ form = @api.form('everything').query(Predicates.missing('my.blog-post.author'))
67
+ form.data['q'].should == ['[[:d = missing(my.blog-post.author)]]']
68
+ end
69
+ end
70
+
42
71
  describe 'multiple predicates' do
43
72
  it 'as an array serializes well' do
44
73
  form = @api.form('everything').query(
@@ -56,6 +85,15 @@ describe 'predicates' do
56
85
  end
57
86
  end
58
87
 
88
+ describe 'number GT' do
89
+ it 'with helpers serializes well' do
90
+ form = @api.form('everything').query(
91
+ Predicates.gt('my.blog-post.publication-date', 4)
92
+ )
93
+ form.data['q'].should == ['[[:d = number.gt(my.blog-post.publication-date, 4)]]']
94
+ end
95
+ end
96
+
59
97
  describe 'number LT' do
60
98
  it 'with helpers serializes well' do
61
99
  form = @api.form('everything').query(
@@ -74,6 +112,186 @@ describe 'predicates' do
74
112
  end
75
113
  end
76
114
 
115
+ describe 'date is before' do
116
+ it 'with helpers serializes well' do
117
+ form = @api.form('everything').query(
118
+ Predicates.date_before('my.blog-post.publication-date', Date.parse('2016-03-02') )
119
+ )
120
+ form.data['q'].should == ["[[:d = date.before(my.blog-post.publication-date, #{Date.parse('2016-03-02').to_time.to_i * 1000})]]"]
121
+ end
122
+ end
123
+
124
+ describe 'date is after' do
125
+ it 'with helpers serializes well' do
126
+ form = @api.form('everything').query(
127
+ Predicates.date_after('my.blog-post.publication-date', Date.parse('2016-03-02') )
128
+ )
129
+ form.data['q'].should == ["[[:d = date.after(my.blog-post.publication-date, #{Date.parse('2016-03-02').to_time.to_i * 1000})]]"]
130
+ end
131
+ end
132
+
133
+ describe 'date is between' do
134
+ it 'with helpers serializes well' do
135
+ form = @api.form('everything').query(
136
+ Predicates.date_between('my.blog-post.publication-date', Date.parse('2016-03-02'), Date.parse('2016-03-04') )
137
+ )
138
+ form.data['q'].should == ["[[:d = date.between(my.blog-post.publication-date, #{Date.parse('2016-03-02').to_time.to_i * 1000}, #{Date.parse('2016-03-04').to_time.to_i * 1000})]]"]
139
+ end
140
+ end
141
+
142
+ describe 'day of month' do
143
+ it 'with helpers serializes well' do
144
+ form = @api.form('everything').query(
145
+ Predicates.day_of_month('my.blog-post.publication-date', 10)
146
+ )
147
+ form.data['q'].should == ['[[:d = date.day-of-month(my.blog-post.publication-date, 10)]]']
148
+ end
149
+ end
150
+
151
+ describe 'day of month after' do
152
+ it 'with helpers serializes well' do
153
+ form = @api.form('everything').query(
154
+ Predicates.day_of_month_after('my.blog-post.publication-date', 10)
155
+ )
156
+ form.data['q'].should == ['[[:d = date.day-of-month-after(my.blog-post.publication-date, 10)]]']
157
+ end
158
+ end
159
+
160
+ describe 'day of month before' do
161
+ it 'with helpers serializes well' do
162
+ form = @api.form('everything').query(
163
+ Predicates.day_of_month_before('my.blog-post.publication-date', 10)
164
+ )
165
+ form.data['q'].should == ['[[:d = date.day-of-month-before(my.blog-post.publication-date, 10)]]']
166
+ end
167
+ end
168
+
169
+ describe 'day of week' do
170
+ it 'with helpers serializes well' do
171
+ form = @api.form('everything').query(
172
+ Predicates.day_of_week('my.blog-post.publication-date', 7)
173
+ )
174
+ form.data['q'].should == ['[[:d = date.day-of-week(my.blog-post.publication-date, 7)]]']
175
+ end
176
+ end
177
+
178
+ describe 'day of week after' do
179
+ it 'with helpers serializes well' do
180
+ form = @api.form('everything').query(
181
+ Predicates.day_of_week_after('my.blog-post.publication-date', 7)
182
+ )
183
+ form.data['q'].should == ['[[:d = date.day-of-week-after(my.blog-post.publication-date, 7)]]']
184
+ end
185
+ end
186
+
187
+ describe 'day of week before' do
188
+ it 'with helpers serializes well' do
189
+ form = @api.form('everything').query(
190
+ Predicates.day_of_week_before('my.blog-post.publication-date', 7)
191
+ )
192
+ form.data['q'].should == ['[[:d = date.day-of-week-before(my.blog-post.publication-date, 7)]]']
193
+ end
194
+ end
195
+
196
+ describe 'month' do
197
+ it 'with helpers serializes well' do
198
+ form = @api.form('everything').query(
199
+ Predicates.month('my.blog-post.publication-date', 5)
200
+ )
201
+ form.data['q'].should == ['[[:d = date.month(my.blog-post.publication-date, 5)]]']
202
+ end
203
+ it 'with helpers serializes well' do
204
+ form = @api.form('everything').query(
205
+ Predicates.month('my.blog-post.publication-date', 'May')
206
+ )
207
+ form.data['q'].should == ['[[:d = date.month(my.blog-post.publication-date, "May")]]']
208
+ end
209
+ end
210
+
211
+ describe 'month after' do
212
+ it 'with helpers serializes well' do
213
+ form = @api.form('everything').query(
214
+ Predicates.month_after('my.blog-post.publication-date', 4)
215
+ )
216
+ form.data['q'].should == ['[[:d = date.month-after(my.blog-post.publication-date, 4)]]']
217
+ end
218
+ it 'with helpers serializes well' do
219
+ form = @api.form('everything').query(
220
+ Predicates.month_after('my.blog-post.publication-date', 'April')
221
+ )
222
+ form.data['q'].should == ['[[:d = date.month-after(my.blog-post.publication-date, "April")]]']
223
+ end
224
+ end
225
+
226
+ describe 'month before' do
227
+ it 'with helpers serializes well' do
228
+ form = @api.form('everything').query(
229
+ Predicates.month_before('my.blog-post.publication-date', 12)
230
+ )
231
+ form.data['q'].should == ['[[:d = date.month-before(my.blog-post.publication-date, 12)]]']
232
+ end
233
+ it 'with helpers serializes well' do
234
+ form = @api.form('everything').query(
235
+ Predicates.month_before('my.blog-post.publication-date', 'December')
236
+ )
237
+ form.data['q'].should == ['[[:d = date.month-before(my.blog-post.publication-date, "December")]]']
238
+ end
239
+ end
240
+
241
+ describe 'year' do
242
+ it 'with helpers serializes well' do
243
+ form = @api.form('everything').query(
244
+ Predicates.year('my.blog-post.publication-date', 2013)
245
+ )
246
+ form.data['q'].should == ['[[:d = date.year(my.blog-post.publication-date, 2013)]]']
247
+ end
248
+ end
249
+
250
+ describe 'year before' do
251
+ it 'with helpers serializes well' do
252
+ form = @api.form('everything').query(
253
+ Predicates.year_before('my.blog-post.publication-date', 2013)
254
+ )
255
+ form.data['q'].should == ['[[:d = date.year-before(my.blog-post.publication-date, 2013)]]']
256
+ end
257
+ end
258
+
259
+ describe 'year after' do
260
+ it 'with helpers serializes well' do
261
+ form = @api.form('everything').query(
262
+ Predicates.year_after('my.blog-post.publication-date', 2011)
263
+ )
264
+ form.data['q'].should == ['[[:d = date.year-after(my.blog-post.publication-date, 2011)]]']
265
+ end
266
+ end
267
+
268
+ describe 'hour' do
269
+ it 'with helpers serializes well' do
270
+ form = @api.form('everything').query(
271
+ Predicates.hour('my.blog-post.publication-date', 2)
272
+ )
273
+ form.data['q'].should == ['[[:d = date.hour(my.blog-post.publication-date, 2)]]']
274
+ end
275
+ end
276
+
277
+ describe 'hour before' do
278
+ it 'with helpers serializes well' do
279
+ form = @api.form('everything').query(
280
+ Predicates.hour_before('my.blog-post.publication-date', 12)
281
+ )
282
+ form.data['q'].should == ['[[:d = date.hour-before(my.blog-post.publication-date, 12)]]']
283
+ end
284
+ end
285
+
286
+ describe 'hour after' do
287
+ it 'with helpers serializes well' do
288
+ form = @api.form('everything').query(
289
+ Predicates.hour_after('my.blog-post.publication-date', 17)
290
+ )
291
+ form.data['q'].should == ['[[:d = date.hour-after(my.blog-post.publication-date, 17)]]']
292
+ end
293
+ end
294
+
77
295
  describe 'geopoint near' do
78
296
  it 'with helpers serializes well' do
79
297
  form = @api.form('everything').query(
data/spec/prismic_spec.rb CHANGED
@@ -271,7 +271,7 @@ describe 'LinkResolver' do
271
271
  @document = Prismic::Document.new('id', nil, 'blog-post', nil, ['tag1', 'tag2'], ['my-slug', 'my-other-slug'], nil)
272
272
 
273
273
  @link_resolver = Prismic::LinkResolver.new(nil) do |doc|
274
- '/'+doc.link_type+'/'+doc.id+'/'+doc.slug
274
+ '/'+doc.type+'/'+doc.id+'/'+doc.slug
275
275
  end
276
276
  end
277
277
 
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.3.5
4
+ version: 1.4.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: 2015-11-20 00:00:00.000000000 Z
14
+ date: 2016-03-11 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler