prismic.io 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/prismic.rb +1 -1
- data/lib/prismic/api.rb +1 -1
- data/lib/prismic/version.rb +1 -1
- data/lib/prismic/with_fragments.rb +7 -0
- data/package.json +1 -1
- data/spec/doc_spec.rb +20 -20
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 262cbc2bac7da40a5f91810b4b1e3d3325676f0b
|
4
|
+
data.tar.gz: fb939276c43de3b25a2f949119650035536afcd2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e87f7f3f8eb76161cf56b94dbf919215b85963d3dce8f67ff0383987abbcb67f18ab807b14834a2a810f4c5c87fc00ec7f29873b59558c2ddcde1dfddef7340b
|
7
|
+
data.tar.gz: 14f537c21d1ecee4c18204174e64236911a268f71b49412c4ca4190d984a3f08fab97a36556585329f42e2aa37f42e3a5aa80587a2938389fc1cc40cc5ce2028
|
data/Gemfile.lock
CHANGED
data/lib/prismic.rb
CHANGED
@@ -157,7 +157,7 @@ module Prismic
|
|
157
157
|
|
158
158
|
def q(*query)
|
159
159
|
def serialize(field)
|
160
|
-
if field.kind_of?(String) and not (field.start_with?('my.') or field.start_with?('document
|
160
|
+
if field.kind_of?(String) and not (field.start_with?('my.') or field.start_with?('document'))
|
161
161
|
%("#{field}")
|
162
162
|
elsif field.kind_of?(Array)
|
163
163
|
%([#{field.map{ |arg| serialize(arg) }.join(', ')}])
|
data/lib/prismic/api.rb
CHANGED
data/lib/prismic/version.rb
CHANGED
@@ -66,6 +66,13 @@ module Prismic
|
|
66
66
|
end
|
67
67
|
alias :size :length
|
68
68
|
|
69
|
+
# @return [Fragments::StructuredText]
|
70
|
+
def get_structured_text(field)
|
71
|
+
fragment = self[field]
|
72
|
+
return nil unless fragment.is_a? Prismic::Fragments::StructuredText
|
73
|
+
fragment
|
74
|
+
end
|
75
|
+
|
69
76
|
# @return [Fragments::Text]
|
70
77
|
def get_text(field)
|
71
78
|
fragment = self[field]
|
data/package.json
CHANGED
data/spec/doc_spec.rb
CHANGED
@@ -6,7 +6,7 @@ describe 'Documentation' do
|
|
6
6
|
describe 'api' do
|
7
7
|
|
8
8
|
it 'api.get' do
|
9
|
-
# startgist:
|
9
|
+
# startgist:983989438334c8bf7967:prismic-api.rb
|
10
10
|
api = Prismic.api('https://lesbonneschoses.cdn.wroom.io/api')
|
11
11
|
# endgist
|
12
12
|
api.should_not be_nil
|
@@ -14,7 +14,7 @@ describe 'Documentation' do
|
|
14
14
|
|
15
15
|
it 'apiPrivate' do
|
16
16
|
expect {
|
17
|
-
# startgist:
|
17
|
+
# startgist:efecc8f60b1f69bada81:prismic-apiPrivate.rb
|
18
18
|
# This will fail because the token is invalid, but this is how to access a private API
|
19
19
|
api = Prismic.api('https://lesbonneschoses.cdn.prismic.io/api', 'MC5-XXXXXXX-vRfvv70')
|
20
20
|
# endgist
|
@@ -23,7 +23,7 @@ describe 'Documentation' do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'references' do
|
26
|
-
# startgist:
|
26
|
+
# startgist:55a7ef6bc691bf3c4929:prismic-references.rb
|
27
27
|
preview_token = 'MC5VbDdXQmtuTTB6Z0hNWHF3.c--_vVbvv73vv73vv73vv71EA--_vS_vv73vv70T77-9Ke-_ve-_vWfvv70ebO-_ve-_ve-_vQN377-9ce-_vRfvv70';
|
28
28
|
api = Prismic.api('https://lesbonneschoses.cdn.prismic.io/api', preview_token)
|
29
29
|
st_patrick_ref = api.ref('St-Patrick specials')
|
@@ -43,7 +43,7 @@ describe 'Documentation' do
|
|
43
43
|
describe 'queries' do
|
44
44
|
|
45
45
|
it 'simple query' do
|
46
|
-
# startgist:
|
46
|
+
# startgist:f1007f1c4c4bc94f9fc6:prismic-simplequery.rb
|
47
47
|
api = Prismic.api('https://lesbonneschoses.cdn.prismic.io/api')
|
48
48
|
response = api
|
49
49
|
.form('everything')
|
@@ -55,7 +55,7 @@ describe 'Documentation' do
|
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'orderings' do
|
58
|
-
# startgist:
|
58
|
+
# startgist:f987025745dbbf26e817:prismic-orderings.rb
|
59
59
|
api = Prismic.api('https://lesbonneschoses.cdn.prismic.io/api')
|
60
60
|
response = api.form('everything')
|
61
61
|
.ref(api.master_ref)
|
@@ -70,7 +70,7 @@ describe 'Documentation' do
|
|
70
70
|
end
|
71
71
|
|
72
72
|
it 'predicates' do
|
73
|
-
# startgist:
|
73
|
+
# startgist:7b93db67fa25ac386603:prismic-predicates.rb
|
74
74
|
api = Prismic.api('https://lesbonneschoses.cdn.prismic.io/api')
|
75
75
|
response = api
|
76
76
|
.form('everything')
|
@@ -83,7 +83,7 @@ describe 'Documentation' do
|
|
83
83
|
end
|
84
84
|
|
85
85
|
it 'all predicates' do
|
86
|
-
# startgist:
|
86
|
+
# startgist:1efb7363a5f573627308:prismic-allPredicates.rb
|
87
87
|
# 'at' predicate: equality of a fragment to a value.
|
88
88
|
at = Predicates::at('document.type', 'article')
|
89
89
|
# 'any' predicate: equality of a fragment to a value.
|
@@ -110,7 +110,7 @@ describe 'Documentation' do
|
|
110
110
|
.ref(api.master_ref)
|
111
111
|
.submit
|
112
112
|
doc = response[0]
|
113
|
-
# startgist:
|
113
|
+
# startgist:4cbc1abffe7cc1209f95:prismic-getText.rb
|
114
114
|
author = doc.get_text('blog-post.author')
|
115
115
|
if author == nil
|
116
116
|
name = 'Anonymous'
|
@@ -128,7 +128,7 @@ describe 'Documentation' do
|
|
128
128
|
.ref(api.master_ref)
|
129
129
|
.submit
|
130
130
|
doc = response[0]
|
131
|
-
# startgist:
|
131
|
+
# startgist:4e263ac039e0b0cea0be:prismic-getNumber.rb
|
132
132
|
# Number predicates
|
133
133
|
gt = Predicates::gt('my.product.price', 10)
|
134
134
|
lt = Predicates::lt('my.product.price', 20)
|
@@ -147,7 +147,7 @@ describe 'Documentation' do
|
|
147
147
|
.ref(api.master_ref)
|
148
148
|
.submit
|
149
149
|
doc = response[0]
|
150
|
-
# startgist:
|
150
|
+
# startgist:154ba379a5000f14b3ea:prismic-images.rb
|
151
151
|
# Accessing image fields
|
152
152
|
image = doc.get_image('product.image')
|
153
153
|
# Most of the time you will be using the "main" view
|
@@ -163,7 +163,7 @@ describe 'Documentation' do
|
|
163
163
|
.ref(api.master_ref)
|
164
164
|
.submit
|
165
165
|
doc = response[0]
|
166
|
-
# startgist:
|
166
|
+
# startgist:4ac2db89bde0ca0c2b33:prismic-dateTimestamp.rb
|
167
167
|
# Date and Timestamp predicates
|
168
168
|
dateBefore = Predicates::date_before('my.product.releaseDate', Time.new(2014, 6, 1))
|
169
169
|
dateAfter = Predicates::date_after('my.product.releaseDate', Time.new(2014, 1, 1))
|
@@ -195,7 +195,7 @@ describe 'Documentation' do
|
|
195
195
|
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}}}]}}}}'
|
196
196
|
document = Prismic::JsonParser.document_parser(JSON.load(json))
|
197
197
|
resolver = Prismic.link_resolver('master') { |doc_link| "http://localhost/#{doc_link.id}" }
|
198
|
-
# startgist:
|
198
|
+
# startgist:4c87bd640086b9094151:prismic-group.rb
|
199
199
|
group = document.get_group('article.documents')
|
200
200
|
docs = group ? group : []
|
201
201
|
docs.each do |doc|
|
@@ -210,7 +210,7 @@ describe 'Documentation' do
|
|
210
210
|
it 'link' do
|
211
211
|
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}}}}}'
|
212
212
|
document = Prismic::JsonParser.document_parser(JSON.load(json))
|
213
|
-
# startgist:
|
213
|
+
# startgist:762dfce77d215e6c70b0:prismic-link.rb
|
214
214
|
resolver = Prismic.link_resolver('master') { |doc_link| "http://localhost/#{doc_link.id}/#{doc_link.slug}" }
|
215
215
|
source = document.get_link('article.source')
|
216
216
|
url = source ? source.url(resolver) : nil
|
@@ -221,7 +221,7 @@ describe 'Documentation' do
|
|
221
221
|
it 'embed' do
|
222
222
|
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"}}}}}}'
|
223
223
|
document = Prismic::JsonParser.document_parser(JSON.load(json))
|
224
|
-
# startgist:
|
224
|
+
# startgist:86d937da7ba242ea981f:prismic-embed.rb
|
225
225
|
video = document.get_embed('article.video')
|
226
226
|
# Html is the code to include to embed the object, and depends on the embedded service
|
227
227
|
html = video ? video.as_html : ''
|
@@ -232,7 +232,7 @@ describe 'Documentation' do
|
|
232
232
|
it 'color' do
|
233
233
|
json = '{"id":"abcd","type":"article","href":"","slugs":[],"tags":[],"data":{"article":{"background":{"type":"Color","value":"#000000"}}}}'
|
234
234
|
document = Prismic::JsonParser.document_parser(JSON.load(json))
|
235
|
-
# startgist:
|
235
|
+
# startgist:2b41f3a75f129a0d6903:prismic-color.rb
|
236
236
|
bgcolor = document.get_color('article.background')
|
237
237
|
hex = '#' + (bgcolor ? bgcolor.value : 'FFFFFF')
|
238
238
|
# endgist
|
@@ -242,7 +242,7 @@ describe 'Documentation' do
|
|
242
242
|
it 'GeoPoint' do
|
243
243
|
json = '{"id":"abcd","type":"article","href":"","slugs":[],"tags":[],"data":{"article":{"location":{"type":"GeoPoint","value":{"latitude":48.877108,"longitude":2.333879}}}}}'
|
244
244
|
document = Prismic::JsonParser.document_parser(JSON.load(json))
|
245
|
-
# startgist:
|
245
|
+
# startgist:f221a2396c079a7d291f:prismic-geopoint.rb
|
246
246
|
# "near" predicate for GeoPoint fragments
|
247
247
|
near = Predicates::near('my.store.location', 48.8768767, 2.3338802, 10)
|
248
248
|
|
@@ -259,7 +259,7 @@ describe 'Documentation' do
|
|
259
259
|
.form('everything')
|
260
260
|
.query(Prismic::Predicates::at('document.id', 'UlfoxUnM0wkXYXbX'))
|
261
261
|
.submit(api.master_ref)
|
262
|
-
# startgist:
|
262
|
+
# startgist:7b93db67fa25ac386603:prismic-asHtml.rb
|
263
263
|
resolver = Prismic.link_resolver('master'){ |doc_link| "http:#localhost/#{doc_link.id}" }
|
264
264
|
doc = response.results[0]
|
265
265
|
html = doc['blog-post.body'].as_html(resolver)
|
@@ -273,7 +273,7 @@ describe 'Documentation' do
|
|
273
273
|
.form('everything')
|
274
274
|
.query(Prismic::Predicates::at('document.id', 'UlfoxUnM0wkXYXbX'))
|
275
275
|
.submit(api.master_ref)
|
276
|
-
# startgist:
|
276
|
+
# startgist:e7944fe6ecdd8956b72:prismic-htmlSerializer.rb
|
277
277
|
resolver = Prismic.link_resolver('master'){ |doc_link| "http:#localhost/#{doc_link.id}" }
|
278
278
|
serializer = Prismic.html_serializer do |element, html|
|
279
279
|
if element.is_a?(Prismic::Fragments::StructuredText::Block::Image)
|
@@ -284,13 +284,13 @@ describe 'Documentation' do
|
|
284
284
|
end
|
285
285
|
end
|
286
286
|
doc = response.results[0]
|
287
|
-
html = doc
|
287
|
+
html = doc.get_structured_text('blog-post.body').as_html(resolver, serializer)
|
288
288
|
# endgist
|
289
289
|
html.should_not be_nil
|
290
290
|
end
|
291
291
|
|
292
292
|
it 'cache' do
|
293
|
-
# startgist:
|
293
|
+
# startgist:388900d4e9e7a444e0a2:prismic-cache.rb
|
294
294
|
# You can pass any object implementing the same methods as the BasicCache
|
295
295
|
# https://github.com/prismicio/ruby-kit/blob/master/lib/prismic/cache/basic.rb
|
296
296
|
cache = Prismic::BasicCache.new
|
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.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Étienne Vallette d'Osia
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2015-04-09 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|