This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resolver = Prismic.link_resolver('master') { |doc_link| "http://localhost/#{doc_link.id}/#{doc_link.slug}" } | |
source = document.get_link('article.source') | |
url = source ? source.url(resolver) : nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
group = document.get_group('article.documents') | |
docs = group ? group : [] | |
docs.each do |doc| | |
# Desc and Link are Fragments, their type depending on what's declared in the Document Mask | |
desc = doc['desc'] | |
link = doc['linktodoc'] | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
video = document.get_embed('article.video') | |
# Html is the code to include to embed the object, and depends on the embedded service | |
html = video ? video.as_html : '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Date and Timestamp predicates | |
dateBefore = Predicates::date_before('my.product.releaseDate', Time.new(2014, 6, 1)) | |
dateAfter = Predicates::date_after('my.product.releaseDate', Time.new(2014, 1, 1)) | |
dateBetween = Predicates::date_between('my.product.releaseDate', Time.new(2014, 1, 1), Time.new(2014, 6, 1)) | |
dayOfMonth = Predicates::day_of_month('my.product.releaseDate', 14) | |
dayOfMonthAfter = Predicates::day_of_month_after('my.product.releaseDate', 14) | |
dayOfMonthBefore = Predicates::day_of_month_before('my.product.releaseDate', 14) | |
dayOfWeek = Predicates::day_of_week('my.product.releaseDate', 'Tuesday') | |
dayOfWeekAfter = Predicates::day_of_week_after('my.product.releaseDate', 'Wednesday') | |
dayOfWeekBefore = Predicates::day_of_week_before('my.product.releaseDate', 'Wednesday') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Number predicates | |
gt = Predicates::gt('my.product.price', 10) | |
lt = Predicates::lt('my.product.price', 20) | |
in_range = Predicates::in_range('my.product.price', 10, 20) | |
# Accessing number fields | |
price = doc.get_number('product.price').value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 'at' predicate: equality of a fragment to a value. | |
at = Predicates::at('document.type', 'article') | |
# 'any' predicate: equality of a fragment to a value. | |
any = Predicates::any('document.type', ['article', 'blog-post']) | |
# 'fulltext' predicate: fulltext search in a fragment. | |
fulltext = Predicates::fulltext('my.article.body', 'sausage') | |
# 'similar' predicate, with a document id as reference | |
similar = Predicates::similar('UXasdFwe42D', 10) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
author = doc.get_text('blog-post.author') | |
if author == nil | |
name = 'Anonymous' | |
else | |
name = author.value | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
api = Prismic.api('https://lesbonneschoses.cdn.prismic.io/api') | |
response = api | |
.form('everything') | |
.query( | |
Prismic::Predicates::at('document.type', 'product'), | |
Prismic::Predicates::date_after('my.blog-post.date', 1401580800000)) | |
.submit(api.master_ref) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
api = Prismic.api('https://lesbonneschoses.cdn.prismic.io/api') | |
response = api.form('everything') | |
.ref(api.master_ref) | |
.query(Prismic::Predicates::at('document.type', 'product')) | |
.page_size(100) | |
.orderings('[my.product.price desc]') | |
.submit | |
# The products are now ordered by price, highest first | |
results = response.results |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This will fail because the token is invalid, but this is how to access a private API | |
api = Prismic.api('https://lesbonneschoses.cdn.prismic.io/api', 'MC5-XXXXXXX-vRfvv70') |