prismic.io 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/Gemfile.lock +1 -1
- data/gulpfile.js +25 -0
- data/lib/prismic.rb +62 -8
- data/lib/prismic/api.rb +2 -2
- data/lib/prismic/fragments/embed.rb +1 -5
- data/lib/prismic/fragments/structured_text.rb +2 -2
- data/lib/prismic/predicates.rb +15 -3
- data/lib/prismic/version.rb +1 -1
- data/package.json +10 -0
- data/spec/cache_spec.rb +114 -114
- data/spec/doc_spec.rb +289 -0
- data/spec/lesbonneschoses_spec.rb +2 -2
- data/spec/micro_spec.rb +6 -6
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16a00d0902a7e578bae02a8f3ba454601d4a11eb
|
4
|
+
data.tar.gz: c4c7c7328802c53c8a4b756be7696a313926675c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01275c85a8294298cc99f43bbbaf9dd63e537d6ae73e3c446cb6d8e7fc9797a65509c329eb4f8e75d535010f8035c0dfec1ed4c39dde4f777dc08a3ab661cbe8
|
7
|
+
data.tar.gz: 79c636388540a1cd684691373f42d978fb7a8b7994219b4b05086fa9d850b99c747ef8866f4974e11c85400782959a572c4e6e8baddf9ad9b3a1f28b34772358
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/gulpfile.js
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
var gulp = require('gulp'),
|
2
|
+
gist = require('gulp-gist'),
|
3
|
+
deploy = require("gulp-gh-pages");
|
4
|
+
|
5
|
+
var pkg = require('./package.json');
|
6
|
+
|
7
|
+
gulp.task('deploy:doc', function () {
|
8
|
+
gulp.src("./doc/**/*")
|
9
|
+
.pipe(deploy());
|
10
|
+
});
|
11
|
+
|
12
|
+
gulp.task('deploy:gist', function () {
|
13
|
+
|
14
|
+
gulp.src("./spec/doc_spec.rb")
|
15
|
+
.pipe(gist());
|
16
|
+
});
|
17
|
+
|
18
|
+
gulp.task('dist', ['deploy:doc', 'deploy:gist']);
|
19
|
+
|
20
|
+
/**
|
21
|
+
* Default task
|
22
|
+
*/
|
23
|
+
|
24
|
+
gulp.task('default', ['deploy:gist']);
|
25
|
+
|
data/lib/prismic.rb
CHANGED
@@ -277,20 +277,20 @@ module Prismic
|
|
277
277
|
cache_key = form_method+'::'+form_action+'?'+data.map{|k,v|"#{k}=#{v}"}.join('&')
|
278
278
|
|
279
279
|
api.caching(cache_key) {
|
280
|
-
if form_method ==
|
280
|
+
if form_method == 'GET' && form_enctype == 'application/x-www-form-urlencoded'
|
281
281
|
data['access_token'] = api.access_token if api.access_token
|
282
282
|
data.delete_if { |k, v| v.nil? }
|
283
283
|
|
284
284
|
response = api.http_client.get(form_action, data, 'Accept' => 'application/json')
|
285
285
|
|
286
|
-
if response.code.to_s ==
|
286
|
+
if response.code.to_s == '200'
|
287
287
|
response.body
|
288
288
|
else
|
289
289
|
body = JSON.load(response.body) rescue nil
|
290
290
|
error = body.is_a?(Hash) ? body['error'] : response.body
|
291
|
-
raise AuthenticationException, error if response.code.to_s ==
|
292
|
-
raise AuthorizationException, error if response.code.to_s ==
|
293
|
-
raise RefNotFoundException, error if response.code.to_s ==
|
291
|
+
raise AuthenticationException, error if response.code.to_s == '401'
|
292
|
+
raise AuthorizationException, error if response.code.to_s == '403'
|
293
|
+
raise RefNotFoundException, error if response.code.to_s == '404'
|
294
294
|
raise FormSearchException, error
|
295
295
|
end
|
296
296
|
else
|
@@ -308,9 +308,9 @@ module Prismic
|
|
308
308
|
field = @form.fields[field_name]
|
309
309
|
if field && field.repeatable?
|
310
310
|
data[field_name] = [] unless data.include? field_name
|
311
|
-
data[field_name] << value
|
311
|
+
data[field_name] << value.to_s
|
312
312
|
else
|
313
|
-
data[field_name] = value
|
313
|
+
data[field_name] = value.to_s
|
314
314
|
end
|
315
315
|
self
|
316
316
|
end
|
@@ -459,13 +459,67 @@ module Prismic
|
|
459
459
|
def [](field)
|
460
460
|
array = field.split('.')
|
461
461
|
if array.length != 2
|
462
|
-
raise ArgumentError,
|
462
|
+
raise ArgumentError, 'Argument should contain one dot. Example: product.price'
|
463
463
|
end
|
464
464
|
return nil if array[0] != self.type
|
465
465
|
fragments[array[1]]
|
466
466
|
end
|
467
467
|
alias :get :[]
|
468
468
|
|
469
|
+
def get_text(field)
|
470
|
+
fragment = self[field]
|
471
|
+
return nil unless fragment.is_a? Prismic::Fragments::Text
|
472
|
+
fragment
|
473
|
+
end
|
474
|
+
|
475
|
+
def get_number(field)
|
476
|
+
fragment = self[field]
|
477
|
+
return nil unless fragment.is_a? Prismic::Fragments::Number
|
478
|
+
fragment
|
479
|
+
end
|
480
|
+
|
481
|
+
def get_date(field)
|
482
|
+
fragment = self[field]
|
483
|
+
return nil unless fragment.is_a? Prismic::Fragments::Date
|
484
|
+
fragment
|
485
|
+
end
|
486
|
+
|
487
|
+
def get_timestamp(field)
|
488
|
+
fragment = self[field]
|
489
|
+
return nil unless fragment.is_a? Prismic::Fragments::Timestamp
|
490
|
+
fragment
|
491
|
+
end
|
492
|
+
|
493
|
+
def get_group(field)
|
494
|
+
fragment = self[field]
|
495
|
+
return nil unless fragment.is_a? Prismic::Fragments::Group
|
496
|
+
fragment
|
497
|
+
end
|
498
|
+
|
499
|
+
def get_link(field)
|
500
|
+
fragment = self[field]
|
501
|
+
return nil unless fragment.is_a? Prismic::Fragments::Link
|
502
|
+
fragment
|
503
|
+
end
|
504
|
+
|
505
|
+
def get_embed(field)
|
506
|
+
fragment = self[field]
|
507
|
+
return nil unless fragment.is_a? Prismic::Fragments::Embed
|
508
|
+
fragment
|
509
|
+
end
|
510
|
+
|
511
|
+
def get_color(field)
|
512
|
+
fragment = self[field]
|
513
|
+
return nil unless fragment.is_a? Prismic::Fragments::Color
|
514
|
+
fragment
|
515
|
+
end
|
516
|
+
|
517
|
+
def get_geopoint(field)
|
518
|
+
fragment = self[field]
|
519
|
+
return nil unless fragment.is_a? Prismic::Fragments::GeoPoint
|
520
|
+
fragment
|
521
|
+
end
|
522
|
+
|
469
523
|
private
|
470
524
|
|
471
525
|
def parse_fragments(fragments)
|
data/lib/prismic/api.rb
CHANGED
@@ -185,9 +185,9 @@ module Prismic
|
|
185
185
|
end
|
186
186
|
|
187
187
|
def oauth_check_token(params)
|
188
|
-
|
188
|
+
unless @@warned_oauth_check_token
|
189
189
|
warn "[DEPRECATION] Method `API#oauth_check_token` is deprecated. " +
|
190
|
-
|
190
|
+
"Please use `Prismic::API.oauth_check_token` instead."
|
191
191
|
@@warned_oauth_check_token = true
|
192
192
|
end
|
193
193
|
oauth.check_token(params)
|
@@ -19,11 +19,7 @@ module Prismic
|
|
19
19
|
#
|
20
20
|
# @return [String] the HTML representation
|
21
21
|
def as_html(link_resolver=nil, html_serializer=nil)
|
22
|
-
|
23
|
-
<div data-oembed="#@url"
|
24
|
-
data-oembed-type="#{@embed_type.downcase}"
|
25
|
-
data-oembed-provider="#{@provider.downcase}">#@html</div>
|
26
|
-
HTML
|
22
|
+
%Q|<div data-oembed="#{@url}" data-oembed-type="#{@embed_type.downcase}" data-oembed-provider="#{@provider.downcase}">#@html</div>|
|
27
23
|
end
|
28
24
|
end
|
29
25
|
end
|
@@ -252,7 +252,7 @@ module Prismic
|
|
252
252
|
attr_accessor :level
|
253
253
|
|
254
254
|
def initialize(text, spans, level, label = nil)
|
255
|
-
super(text, spans)
|
255
|
+
super(text, spans, label)
|
256
256
|
@level = level
|
257
257
|
end
|
258
258
|
|
@@ -293,7 +293,7 @@ module Prismic
|
|
293
293
|
alias :ordered? :ordered
|
294
294
|
|
295
295
|
def initialize(text, spans, ordered, label = nil)
|
296
|
-
super(text, spans)
|
296
|
+
super(text, spans, label)
|
297
297
|
@ordered = ordered
|
298
298
|
end
|
299
299
|
|
data/lib/prismic/predicates.rb
CHANGED
@@ -30,15 +30,15 @@ module Prismic
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def self.date_before(fragment, before)
|
33
|
-
['date.before', fragment, before]
|
33
|
+
['date.before', fragment, as_timestamp(before)]
|
34
34
|
end
|
35
35
|
|
36
36
|
def self.date_after(fragment, after)
|
37
|
-
['date.after', fragment, after]
|
37
|
+
['date.after', fragment, as_timestamp(after)]
|
38
38
|
end
|
39
39
|
|
40
40
|
def self.date_between(fragment, before, after)
|
41
|
-
['date.between', fragment, before, after]
|
41
|
+
['date.between', fragment, as_timestamp(before), as_timestamp(after)]
|
42
42
|
end
|
43
43
|
|
44
44
|
def self.day_of_month(fragment, day)
|
@@ -97,5 +97,17 @@ module Prismic
|
|
97
97
|
['geopoint.near', fragment, latitude, longitude, radius]
|
98
98
|
end
|
99
99
|
|
100
|
+
def self.as_timestamp(date)
|
101
|
+
if date.is_a? Date or date.is_a? DateTime
|
102
|
+
date.to_time.to_i * 1000
|
103
|
+
elsif date.is_a? Time
|
104
|
+
date.to_i * 1000
|
105
|
+
else
|
106
|
+
date
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
private_class_method :as_timestamp
|
111
|
+
|
100
112
|
end
|
101
113
|
end
|
data/lib/prismic/version.rb
CHANGED
data/package.json
ADDED
data/spec/cache_spec.rb
CHANGED
@@ -3,101 +3,101 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
describe "Cache's" do
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
6
|
+
describe 'on/off switch' do
|
7
|
+
before do
|
8
|
+
@api = Prismic.api("https://lesbonneschoses.prismic.io/api", cache: Prismic::LruCache.new(3))
|
9
|
+
@cache = @api.cache
|
10
|
+
@master_ref = @api.master_ref
|
11
|
+
end
|
12
|
+
|
13
|
+
it "is properly on" do
|
14
|
+
@api.has_cache?.should == true
|
15
|
+
@cache.is_a?(Prismic::LruCache).should == true
|
16
|
+
end
|
17
|
+
|
18
|
+
it "is properly off" do
|
19
|
+
api = Prismic.api("https://lesbonneschoses.prismic.io/api", cache: false)
|
20
|
+
api.has_cache?.should == false
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'storage and retrieval' do
|
24
|
+
it 'stores properly' do
|
25
|
+
@cache.intern.size.should == 0
|
26
|
+
@api.form('products').submit(@master_ref)
|
27
|
+
@cache.intern.size.should == 1
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'does not cache /api' do
|
31
|
+
# do not call anything, so the only request made is the /api one
|
32
|
+
@cache.intern.size.should == 0
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe 'cache storage' do
|
37
|
+
before do
|
38
|
+
# max_size = 3
|
39
|
+
@cache['fake_key1'] = 1
|
40
|
+
@cache['fake_key2'] = 2
|
41
|
+
@cache['fake_key3'] = 3
|
42
|
+
end
|
43
|
+
it 'contains some keys' do
|
44
|
+
@cache.include?('fake_key1').should be_true
|
45
|
+
end
|
46
|
+
it 'contains all keys' do
|
47
|
+
@cache.intern.size.should == 3
|
48
|
+
end
|
49
|
+
it 'can return all keys' do
|
50
|
+
@cache.keys.should == %w(fake_key1 fake_key2 fake_key3)
|
51
|
+
end
|
52
|
+
it 'deletes oldest key when updating max_size' do
|
53
|
+
@cache.max_size = 1
|
54
|
+
@cache.size.should == 1
|
55
|
+
@cache.include?('fake_key1').should be_false
|
56
|
+
@cache.include?('fake_key2').should be_false
|
57
|
+
@cache.include?('fake_key3').should be_true
|
58
|
+
end
|
59
|
+
it 'deletes oldest key when adding new one (at max_size)' do
|
60
|
+
@cache['fake_key4'] = 4
|
61
|
+
@cache.max_size = 3
|
62
|
+
@cache.size.should == 3
|
63
|
+
@cache.include?('fake_key1').should be_false
|
64
|
+
end
|
65
|
+
it 'keeps readed keys alive' do
|
66
|
+
@cache['fake_key1']
|
67
|
+
@cache['fake_key4'] = 4
|
68
|
+
@cache.include?('fake_key1').should be_true
|
69
|
+
@cache.include?('fake_key2').should be_false
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe 'caching on a real repository' do
|
74
|
+
before do
|
75
|
+
@api = Prismic.api("https://lesbonneschoses.prismic.io/api", access_token: 'MC5VbDdXQmtuTTB6Z0hNWHF3.c--_vVbvv73vv73vv73vv71EA--_vS_vv73vv70T77-9Ke-_ve-_vWfvv70ebO-_ve-_ve-_vQN377-9ce-_vRfvv70')
|
76
|
+
@cache = @api.cache
|
77
|
+
@master_ref = @api.master_ref
|
78
|
+
@other_ref = @api.refs['announcement of new sf shop']
|
79
|
+
end
|
80
|
+
it 'works on different refs' do
|
81
|
+
@api.form('everything').submit(@master_ref).total_results_size.should == 40
|
82
|
+
@api.form('everything').submit(@other_ref).total_results_size.should == 43
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
86
|
end
|
87
87
|
|
88
88
|
describe "Basic Cache's" do
|
89
89
|
|
90
90
|
it 'set & get value' do
|
91
|
-
|
92
|
-
|
93
|
-
|
91
|
+
cache = Prismic::BasicCache.new
|
92
|
+
cache.set('key', 'value')
|
93
|
+
cache.get('key').should == 'value'
|
94
94
|
end
|
95
95
|
|
96
96
|
it 'set with expiration value & get value' do
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
97
|
+
cache = Prismic::BasicCache.new
|
98
|
+
cache.set('key', 'value', 1)
|
99
|
+
sleep(2)
|
100
|
+
cache.get('key').should == nil
|
101
101
|
end
|
102
102
|
|
103
103
|
it 'set with expiration and a block' do
|
@@ -109,41 +109,41 @@ describe "Basic Cache's" do
|
|
109
109
|
end
|
110
110
|
|
111
111
|
it 'set & test value' do
|
112
|
-
|
113
|
-
|
114
|
-
|
112
|
+
cache = Prismic::BasicCache.new
|
113
|
+
cache.set('key', 'value')
|
114
|
+
cache.include?('key').should == true
|
115
115
|
end
|
116
116
|
|
117
117
|
it 'get or set value' do
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
118
|
+
cache = Prismic::BasicCache.new
|
119
|
+
cache.set('key', 'value')
|
120
|
+
cache.get('key').should == 'value'
|
121
|
+
cache.get_or_set('key', 'value1')
|
122
|
+
cache.get('key').should == 'value'
|
123
|
+
cache.get_or_set('key1', 'value2')
|
124
|
+
cache.get('key1').should == 'value2'
|
125
125
|
end
|
126
126
|
|
127
127
|
it 'set, delete & get value' do
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
128
|
+
cache = Prismic::BasicCache.new
|
129
|
+
cache.set('key', 'value')
|
130
|
+
cache.get('key').should == 'value'
|
131
|
+
cache.delete('key')
|
132
|
+
cache.get('key').should == nil
|
133
133
|
end
|
134
134
|
|
135
135
|
it 'set, clear & get value' do
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
136
|
+
cache = Prismic::BasicCache.new
|
137
|
+
cache.expired?('key')
|
138
|
+
cache.set('key', 'value')
|
139
|
+
cache.set('key1', 'value1')
|
140
|
+
cache.set('key2', 'value2')
|
141
|
+
cache.get('key').should == 'value'
|
142
|
+
cache.get('key1').should == 'value1'
|
143
|
+
cache.get('key2').should == 'value2'
|
144
|
+
cache.clear()
|
145
|
+
cache.get('key').should == nil
|
146
|
+
cache.get('key1').should == nil
|
147
|
+
cache.get('key2').should == nil
|
148
148
|
end
|
149
149
|
end
|
data/spec/doc_spec.rb
ADDED
@@ -0,0 +1,289 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'Documentation' do
|
5
|
+
|
6
|
+
describe 'api' do
|
7
|
+
|
8
|
+
it 'api.get' do
|
9
|
+
# startgist:31cf4b514778d5d9d9cc:prismic-api.rb
|
10
|
+
api = Prismic.api('https://lesbonneschoses.prismic.io/api')
|
11
|
+
# endgist
|
12
|
+
api.should_not be_nil
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'apiPrivate' do
|
16
|
+
expect {
|
17
|
+
# startgist:10822fc1befeeea1191a:prismic-apiPrivate.rb
|
18
|
+
# This will fail because the token is invalid, but this is how to access a private API
|
19
|
+
api = Prismic.api('https://lesbonneschoses.prismic.io/api', 'MC5-XXXXXXX-vRfvv70')
|
20
|
+
# endgist
|
21
|
+
# err.message, "Unexpected status code [401] on URL https://lesbonneschoses.prismic.io/api?access_token=MC5-XXXXXXX-vRfvv70"); // gisthide
|
22
|
+
}.to raise_error(Prismic::API::PrismicWSAuthError, "Can't connect to Prismic's API: Invalid access token")
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'references' do
|
26
|
+
# startgist:431e191cabf5e160c701:prismic-references.rb
|
27
|
+
preview_token = 'MC5VbDdXQmtuTTB6Z0hNWHF3.c--_vVbvv73vv73vv73vv71EA--_vS_vv73vv70T77-9Ke-_ve-_vWfvv70ebO-_ve-_ve-_vQN377-9ce-_vRfvv70';
|
28
|
+
api = Prismic.api('https://lesbonneschoses.prismic.io/api', preview_token)
|
29
|
+
st_patrick_ref = api.ref('St-Patrick specials')
|
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
|
35
|
+
# The Response object contains all documents of type "product"
|
36
|
+
# including the new "Saint-Patrick's Cupcake"
|
37
|
+
# endgist
|
38
|
+
response.results.length.should == 17
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
describe 'queries' do
|
44
|
+
|
45
|
+
it 'simple query' do
|
46
|
+
# startgist:8943931ba0cf2bb2c873:prismic-simplequery.rb
|
47
|
+
api = Prismic.api('https://lesbonneschoses.prismic.io/api')
|
48
|
+
response = api
|
49
|
+
.form('everything')
|
50
|
+
.query(Prismic::Predicates::at('document.type', 'product'))
|
51
|
+
.submit(api.master_ref)
|
52
|
+
# response contains all documents of type 'product', paginated
|
53
|
+
# endgist
|
54
|
+
response.results.size.should == 16
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'orderings' do
|
58
|
+
# startgist:2866b2e2cae0221f2188:prismic-orderings.rb
|
59
|
+
api = Prismic.api('https://lesbonneschoses.prismic.io/api')
|
60
|
+
response = api.form('everything')
|
61
|
+
.ref(api.master_ref)
|
62
|
+
.query(Prismic::Predicates::at('document.type', 'product'))
|
63
|
+
.page_size(100)
|
64
|
+
.orderings('[my.product.price desc]')
|
65
|
+
.submit
|
66
|
+
# The products are now ordered by price, highest first
|
67
|
+
results = response.results
|
68
|
+
# endgist
|
69
|
+
response.results_per_page.should == 100
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'predicates' do
|
73
|
+
# startgist:e0501cce9a12fa4b83db:prismic-predicates.rb
|
74
|
+
api = Prismic.api('https://lesbonneschoses.prismic.io/api')
|
75
|
+
response = api
|
76
|
+
.form('everything')
|
77
|
+
.query(
|
78
|
+
Prismic::Predicates::at('document.type', 'product'),
|
79
|
+
Prismic::Predicates::date_after('my.blog-post.date', 1401580800000))
|
80
|
+
.submit(api.master_ref)
|
81
|
+
# endgist
|
82
|
+
response.results.size.should == 0
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'all predicates' do
|
86
|
+
# startgist:e4875d732426a7b9fd09:prismic-allPredicates.rb
|
87
|
+
# 'at' predicate: equality of a fragment to a value.
|
88
|
+
at = Predicates::at('document.type', 'article')
|
89
|
+
# 'any' predicate: equality of a fragment to a value.
|
90
|
+
any = Predicates::any('document.type', ['article', 'blog-post'])
|
91
|
+
|
92
|
+
# 'fulltext' predicate: fulltext search in a fragment.
|
93
|
+
fulltext = Predicates::fulltext('my.article.body', 'sausage')
|
94
|
+
|
95
|
+
# 'similar' predicate, with a document id as reference
|
96
|
+
similar = Predicates::similar('UXasdFwe42D', 10)
|
97
|
+
# endgist
|
98
|
+
at.should == ['at', 'document.type', 'article']
|
99
|
+
any.should == ['any', 'document.type', ['article', 'blog-post']]
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
describe 'fragments' do
|
105
|
+
|
106
|
+
it 'text' do
|
107
|
+
api = Prismic::api('https://lesbonneschoses.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]
|
113
|
+
# startgist:cd0d4559870f5f88b90f:prismic-getText.rb
|
114
|
+
author = doc.get_text('blog-post.author')
|
115
|
+
if author == nil
|
116
|
+
name = 'Anonymous'
|
117
|
+
else
|
118
|
+
name = author.value
|
119
|
+
end
|
120
|
+
# endgist
|
121
|
+
name.should == 'John M. Martelle, Fine Pastry Magazine'
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'number' do
|
125
|
+
api = Prismic::api('https://lesbonneschoses.prismic.io/api')
|
126
|
+
response = api.form('everything')
|
127
|
+
.query(Predicates::at('document.id', 'UlfoxUnM0wkXYXbO'))
|
128
|
+
.ref(api.master_ref)
|
129
|
+
.submit
|
130
|
+
doc = response[0]
|
131
|
+
# startgist:c6783e9789d3ff446876:prismic-getNumber.rb
|
132
|
+
# Number predicates
|
133
|
+
gt = Predicates::gt('my.product.price', 10)
|
134
|
+
lt = Predicates::lt('my.product.price', 20)
|
135
|
+
in_range = Predicates::in_range('my.product.price', 10, 20)
|
136
|
+
|
137
|
+
# Accessing number fields
|
138
|
+
price = doc.get_number('product.price').value
|
139
|
+
# endgist
|
140
|
+
price.should == 2.5
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'date and timestamp' do
|
144
|
+
api = Prismic::api('https://lesbonneschoses.prismic.io/api')
|
145
|
+
response = api.form('everything')
|
146
|
+
.query(Predicates::at('document.id', 'UlfoxUnM0wkXYXbl'))
|
147
|
+
.ref(api.master_ref)
|
148
|
+
.submit
|
149
|
+
doc = response[0]
|
150
|
+
# startgist:aa956ac3d7fb9c221011:prismic-dateTimestamp.rb
|
151
|
+
# Date and Timestamp predicates
|
152
|
+
dateBefore = Predicates::date_before('my.product.releaseDate', Time.new(2014, 6, 1))
|
153
|
+
dateAfter = Predicates::date_after('my.product.releaseDate', Time.new(2014, 1, 1))
|
154
|
+
dateBetween = Predicates::date_between('my.product.releaseDate', Time.new(2014, 1, 1), Time.new(2014, 6, 1))
|
155
|
+
dayOfMonth = Predicates::day_of_month('my.product.releaseDate', 14)
|
156
|
+
dayOfMonthAfter = Predicates::day_of_month_after('my.product.releaseDate', 14)
|
157
|
+
dayOfMonthBefore = Predicates::day_of_month_before('my.product.releaseDate', 14)
|
158
|
+
dayOfWeek = Predicates::day_of_week('my.product.releaseDate', 'Tuesday')
|
159
|
+
dayOfWeekAfter = Predicates::day_of_week_after('my.product.releaseDate', 'Wednesday')
|
160
|
+
dayOfWeekBefore = Predicates::day_of_week_before('my.product.releaseDate', 'Wednesday')
|
161
|
+
month = Predicates::month('my.product.releaseDate', 'June')
|
162
|
+
monthBefore = Predicates::month_before('my.product.releaseDate', 'June')
|
163
|
+
monthAfter = Predicates::month_after('my.product.releaseDate', 'June')
|
164
|
+
year = Predicates::year('my.product.releaseDate', 2014)
|
165
|
+
hour = Predicates::hour('my.product.releaseDate', 12)
|
166
|
+
hourBefore = Predicates::hour_before('my.product.releaseDate', 12)
|
167
|
+
hourAfter = Predicates::hour_after('my.product.releaseDate', 12)
|
168
|
+
|
169
|
+
# Accessing Date and Timestamp fields
|
170
|
+
date = doc.get_date('blog-post.date').value
|
171
|
+
date_year = date ? date.year : nil
|
172
|
+
update_time = doc.get_timestamp('blog-post.update')
|
173
|
+
update_hour = update_time ? update_time.value.hour : nil
|
174
|
+
# endgist
|
175
|
+
date_year.should == 2013
|
176
|
+
end
|
177
|
+
|
178
|
+
it 'group' do
|
179
|
+
json = '{"id":"abcd","type":"article","href":"","slugs":[],"tags":[],"data":{"article":{"documents":{"type":"Group","value":[{"linktodoc":{"type":"Link.document","value":{"document":{"id":"UrDejAEAAFwMyrW9","type":"doc","tags":[],"slug":"installing-meta-micro"},"isBroken":false}},"desc":{"type":"StructuredText","value":[{"type":"paragraph","text":"A detailed step by step point of view on how installing happens.","spans":[]}]}},{"linktodoc":{"type":"Link.document","value":{"document":{"id":"UrDmKgEAALwMyrXA","type":"doc","tags":[],"slug":"using-meta-micro"},"isBroken":false}}}]}}}}'
|
180
|
+
document = Prismic::JsonParser.document_parser(JSON.load(json))
|
181
|
+
resolver = Prismic.link_resolver('master') { |doc_link| "http://localhost/#{doc_link.id}" }
|
182
|
+
# startgist:825cff092f082058520d:prismic-group.rb
|
183
|
+
group = document.get_group('article.documents')
|
184
|
+
docs = group ? group : []
|
185
|
+
docs.each do |doc|
|
186
|
+
# Desc and Link are Fragments, their type depending on what's declared in the Document Mask
|
187
|
+
desc = doc['desc']
|
188
|
+
link = doc['linktodoc']
|
189
|
+
end
|
190
|
+
# endgist
|
191
|
+
docs[0]['desc'].as_html(resolver).should == '<p>A detailed step by step point of view on how installing happens.</p>'
|
192
|
+
end
|
193
|
+
|
194
|
+
it 'link' do
|
195
|
+
json = '{"id":"abcd","type":"article","href":"","slugs":[],"tags":[],"data":{"article":{"source":{"type":"Link.document","value":{"document":{"id":"UlfoxUnM0wkXYXbE","type":"product","tags":["Macaron"],"slug":"dark-chocolate-macaron"},"isBroken":false}}}}}'
|
196
|
+
document = Prismic::JsonParser.document_parser(JSON.load(json))
|
197
|
+
# startgist:6c7ae8d7ab6dc057a8b0:prismic-link.rb
|
198
|
+
resolver = Prismic.link_resolver('master') { |doc_link| "http://localhost/#{doc_link.id}/#{doc_link.slug}" }
|
199
|
+
source = document.get_link('article.source')
|
200
|
+
url = source ? source.url(resolver) : nil
|
201
|
+
# endgist
|
202
|
+
url.should == 'http://localhost/UlfoxUnM0wkXYXbE/dark-chocolate-macaron'
|
203
|
+
end
|
204
|
+
|
205
|
+
it 'embed' do
|
206
|
+
json = '{"id":"abcd","type":"article","href":"","slugs":[],"tags":[],"data":{"article":{"video":{"type":"Embed","value":{"oembed":{"provider_url":"http://www.youtube.com/","type":"video","thumbnail_height":360,"height":270,"thumbnail_url":"http://i1.ytimg.com/vi/baGfM6dBzs8/hqdefault.jpg","width":480,"provider_name":"YouTube","html":"<iframe width=\\"480\\" height=\\"270\\" src=\\"http://www.youtube.com/embed/baGfM6dBzs8?feature=oembed\\" frameborder=\\"0\\" allowfullscreen></iframe>","author_name":"Siobhan Wilson","version":"1.0","author_url":"http://www.youtube.com/user/siobhanwilsonsongs","thumbnail_width":480,"title":"Siobhan Wilson - All Dressed Up","embed_url":"https://www.youtube.com/watch?v=baGfM6dBzs8"}}}}}}'
|
207
|
+
document = Prismic::JsonParser.document_parser(JSON.load(json))
|
208
|
+
# startgist:d5a6c0715c9a8df984e4:prismic-embed.rb
|
209
|
+
video = document.get_embed('article.video')
|
210
|
+
# Html is the code to include to embed the object, and depends on the embedded service
|
211
|
+
html = video ? video.as_html : ''
|
212
|
+
# endgist
|
213
|
+
html.should == '<div data-oembed="http://www.youtube.com/" data-oembed-type="video" data-oembed-provider="youtube"><iframe width="480" height="270" src="http://www.youtube.com/embed/baGfM6dBzs8?feature=oembed" frameborder="0" allowfullscreen></iframe></div>'
|
214
|
+
end
|
215
|
+
|
216
|
+
it 'color' do
|
217
|
+
json = '{"id":"abcd","type":"article","href":"","slugs":[],"tags":[],"data":{"article":{"background":{"type":"Color","value":"#000000"}}}}'
|
218
|
+
document = Prismic::JsonParser.document_parser(JSON.load(json))
|
219
|
+
# startgist:ccafcdcbcd6ef6f2fce8:prismic-color.rb
|
220
|
+
bgcolor = document.get_color('article.background')
|
221
|
+
hex = '#' + (bgcolor ? bgcolor.value : 'FFFFFF')
|
222
|
+
# endgist
|
223
|
+
hex.should == '#000000'
|
224
|
+
end
|
225
|
+
|
226
|
+
it 'GeoPoint' do
|
227
|
+
json = '{"id":"abcd","type":"article","href":"","slugs":[],"tags":[],"data":{"article":{"location":{"type":"GeoPoint","value":{"latitude":48.877108,"longitude":2.333879}}}}}'
|
228
|
+
document = Prismic::JsonParser.document_parser(JSON.load(json))
|
229
|
+
# startgist:c70626752d00669ee18f:prismic-geopoint.rb
|
230
|
+
# "near" predicate for GeoPoint fragments
|
231
|
+
near = Predicates::near('my.store.location', 48.8768767, 2.3338802, 10)
|
232
|
+
|
233
|
+
# Accessing GeoPoint fragments
|
234
|
+
place = document.get_geopoint('article.location')
|
235
|
+
coordinates = place ? (place.latitude.to_s + ',' + place.longitude.to_s) : ''
|
236
|
+
# endgist
|
237
|
+
coordinates.should == '48.877108,2.333879'
|
238
|
+
end
|
239
|
+
|
240
|
+
it 'asHtml' do
|
241
|
+
api = Prismic.api('https://lesbonneschoses.prismic.io/api')
|
242
|
+
response = api
|
243
|
+
.form('everything')
|
244
|
+
.query(Prismic::Predicates::at('document.id', 'UlfoxUnM0wkXYXbX'))
|
245
|
+
.submit(api.master_ref)
|
246
|
+
# startgist:7bc04d4690b74e4d4a39:prismic-asHtml.rb
|
247
|
+
resolver = Prismic.link_resolver('master'){ |doc_link| "http:#localhost/#{doc_link.id}" }
|
248
|
+
doc = response.results[0]
|
249
|
+
html = doc['blog-post.body'].as_html(resolver)
|
250
|
+
# endgist
|
251
|
+
html.should_not be_nil
|
252
|
+
end
|
253
|
+
|
254
|
+
it 'HtmlSerializer' do
|
255
|
+
api = Prismic.api('https://lesbonneschoses.prismic.io/api')
|
256
|
+
response = api
|
257
|
+
.form('everything')
|
258
|
+
.query(Prismic::Predicates::at('document.id', 'UlfoxUnM0wkXYXbX'))
|
259
|
+
.submit(api.master_ref)
|
260
|
+
# startgist:db34a3847be03315da55:prismic-htmlSerializer.rb
|
261
|
+
resolver = Prismic.link_resolver('master'){ |doc_link| "http:#localhost/#{doc_link.id}" }
|
262
|
+
serializer = Prismic.html_serializer do |element, html|
|
263
|
+
if element.is_a?(Prismic::Fragments::StructuredText::Block::Image)
|
264
|
+
# Don't wrap images in a <p> tag
|
265
|
+
%(<img src="#{element.url}" alt="#{element.alt}" width="#{element.width}" height="#{element.height}" />)
|
266
|
+
else
|
267
|
+
nil
|
268
|
+
end
|
269
|
+
end
|
270
|
+
doc = response.results[0]
|
271
|
+
html = doc['blog-post.body'].as_html(resolver, serializer)
|
272
|
+
# endgist
|
273
|
+
html.should_not be_nil
|
274
|
+
end
|
275
|
+
|
276
|
+
it 'cache' do
|
277
|
+
# startgist:a6b898cc3af15d7def0a:prismic-cache.rb
|
278
|
+
# You can pass any object implementing the same methods as the BasicCache
|
279
|
+
# https://github.com/prismicio/ruby-kit/blob/master/lib/prismic/cache/basic.rb
|
280
|
+
cache = Prismic::BasicCache.new
|
281
|
+
api = Prismic::api('https://lesbonneschoses.prismic.io/api', { :cache => cache })
|
282
|
+
# The Api will use the custom cache object
|
283
|
+
# endgist
|
284
|
+
api.should_not be_nil
|
285
|
+
end
|
286
|
+
|
287
|
+
end
|
288
|
+
|
289
|
+
end
|
@@ -149,8 +149,8 @@ describe 'LesBonnesChoses' do
|
|
149
149
|
"<p>As you may know, we like to give our workshop artists the ability to master their art to the top; that is why our Preparation Experts always start off as being Ganache Specialists for Les Bonnes Choses. That way, they're given an opportunity to focus on one exercise before moving on. "\
|
150
150
|
"Once they master their ganache, and are able to provide the most optimal delight to our customers, we consider they'll thrive as they work on other kinds of preparations.</p>\n\n"\
|
151
151
|
"<h2>About the chocolate in our ganache</h2>\n\n"\
|
152
|
-
"<p>Now, we've also had a lot of questions about how our chocolate gets made. It's true, as you might know, that we make it ourselves, from Columbian cocoa and French cow milk, with a process that much resembles the one in the following Discovery Channel documentary.</p>\n\n
|
153
|
-
"<div data-oembed=\"http://www.youtube.com/\"
|
152
|
+
"<p>Now, we've also had a lot of questions about how our chocolate gets made. It's true, as you might know, that we make it ourselves, from Columbian cocoa and French cow milk, with a process that much resembles the one in the following Discovery Channel documentary.</p>\n\n"\
|
153
|
+
"<div data-oembed=\"http://www.youtube.com/\" data-oembed-type=\"video\" data-oembed-provider=\"youtube\"><iframe width=\"459\" height=\"344\" src=\"http://www.youtube.com/embed/Ye78F3-CuXY?feature=oembed\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
154
154
|
end
|
155
155
|
it "returns a correct as_html on a StructuredText with custom HTML serializer" do
|
156
156
|
@api.form("everything")
|
data/spec/micro_spec.rb
CHANGED
@@ -3,25 +3,25 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
describe 'micro' do
|
5
5
|
before do
|
6
|
-
@api = Prismic.api(
|
6
|
+
@api = Prismic.api('https://micro.prismic.io/api', nil)
|
7
7
|
@master_ref = @api.master_ref
|
8
|
-
@link_resolver = Prismic.link_resolver(
|
8
|
+
@link_resolver = Prismic.link_resolver('master'){|doc_link| "http://localhost/#{doc_link.id}" }
|
9
9
|
end
|
10
10
|
|
11
11
|
describe 'embed block in structured text fragments' do
|
12
12
|
it 'is of the right Embed object, and serializes well' do
|
13
|
-
fragment = @api.form(
|
13
|
+
fragment = @api.form('everything').query(%w(at document.id UrjI1gEAALOCeO5i)).submit(@master_ref)[0]['article.body']
|
14
14
|
fragment.blocks[4].is_a?(Prismic::Fragments::Embed).should == true
|
15
|
-
fragment.as_html(@link_resolver).gsub(/[\n\r]+/, '').gsub(/ +/, ' ').gsub(/'/, "'").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
|
15
|
+
fragment.as_html(@link_resolver).gsub(/[\n\r]+/, '').gsub(/ +/, ' ').gsub(/'/, "'").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
|
18
18
|
|
19
19
|
describe 'linked documents' do
|
20
20
|
it 'should have linked documents' do
|
21
|
-
response = @api.form(
|
21
|
+
response = @api.form('everything').query('[[:d = any(document.type, ["doc","docchapter"])]]').submit(@master_ref)
|
22
22
|
linked_documents = response.results[0].linked_documents
|
23
23
|
linked_documents.count.should == 1
|
24
|
-
linked_documents[0].id.should ==
|
24
|
+
linked_documents[0].id.should == 'U0w8OwEAACoAQEvB'
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
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.0.
|
4
|
+
version: 1.0.3
|
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: 2014-10-
|
14
|
+
date: 2014-10-24 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|
@@ -84,6 +84,7 @@ files:
|
|
84
84
|
- README.md
|
85
85
|
- Rakefile
|
86
86
|
- deploy-doc.sh
|
87
|
+
- gulpfile.js
|
87
88
|
- lib/prismic.rb
|
88
89
|
- lib/prismic/api.rb
|
89
90
|
- lib/prismic/cache/basic.rb
|
@@ -107,8 +108,10 @@ files:
|
|
107
108
|
- lib/prismic/json_parsers.rb
|
108
109
|
- lib/prismic/predicates.rb
|
109
110
|
- lib/prismic/version.rb
|
111
|
+
- package.json
|
110
112
|
- prismic.gemspec
|
111
113
|
- spec/cache_spec.rb
|
114
|
+
- spec/doc_spec.rb
|
112
115
|
- spec/fragments_spec.rb
|
113
116
|
- spec/json_parsers_spec.rb
|
114
117
|
- spec/lesbonneschoses_spec.rb
|
@@ -152,6 +155,7 @@ specification_version: 4
|
|
152
155
|
summary: Prismic.io development kit
|
153
156
|
test_files:
|
154
157
|
- spec/cache_spec.rb
|
158
|
+
- spec/doc_spec.rb
|
155
159
|
- spec/fragments_spec.rb
|
156
160
|
- spec/json_parsers_spec.rb
|
157
161
|
- spec/lesbonneschoses_spec.rb
|