Skip to content

Instantly share code, notes, and snippets.

View prismicdeveloper's full-sized avatar

prismicdeveloper

View GitHub Profile
class StarterKitLinkResolver extends LinkResolver
{
// [...]
public function resolve($link)
{
// [...]
if ($link->getType() == 'author') {
return '/author/'.$link->getId().'/'.$link->getSlug();
}
if ($link->getType() == 'category') {
// This goes to the app/app.php file, before the "page" route to take priority
// Let's add a route for our event type
$app->get('/event/:uid', function ($uid) use($app, $prismic) {
$doc = $prismic->by_uid('event', $uid);
if (!$doc) {
not_found($app);
return;
}
<!DOCTYPE html>
<html lang="en">
<head>
<title><?= single_post_title() ?> <?= site_title() ?></title>
<link rel="stylesheet" href="/assets/reset.css">
<link rel="stylesheet" href="/assets/common.css">
<link rel="stylesheet" href="/assets/main.css">
<link rel="stylesheet" href="/assets/blog.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
{
"Happening" : {
"title" : {
"fieldset" : "Event title",
"type" : "StructuredText",
"config" : {
"single" : "heading1,em,strong",
"placeholder" : "What is your event called?"
}
},
resolver = Prismic.link_resolver('master'){ |doc_link| "http:#localhost/#{doc_link.id}" }
doc = response.results[0]
html = doc['blog-post.body'].as_html(resolver)
resolver = Prismic.link_resolver('master'){ |doc_link| "http:#localhost/#{doc_link.id}" }
serializer = Prismic.html_serializer do |element, html|
if element.is_a?(Prismic::Fragments::StructuredText::Block::Image)
# Don't wrap images in a <p> tag
%(<img src="#{element.url}" alt="#{element.alt}" width="#{element.width}" height="#{element.height}" />)
else
nil
end
end
doc = response.results[0]
# You can pass any object implementing the same methods as the BasicCache
# https://github.com/prismicio/ruby-kit/blob/master/lib/prismic/cache/basic.rb
cache = Prismic::BasicCache.new
api = Prismic::api('https://lesbonneschoses.cdn.prismic.io/api', { :cache => cache })
# The Api will use the custom cache object
# Accessing image fields
image = doc.get_image('product.image')
# Most of the time you will be using the "main" view
url = image.main.url
# "near" predicate for GeoPoint fragments
near = Predicates::near('my.store.location', 48.8768767, 2.3338802, 10)
# Accessing GeoPoint fragments
place = document.get_geopoint('article.location')
coordinates = place ? (place.latitude.to_s + ',' + place.longitude.to_s) : ''
bgcolor = document.get_color('article.background')
hex = '#' + (bgcolor ? bgcolor.value : 'FFFFFF')