Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

prismic.io

Package Overview
Dependencies
Maintainers
3
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prismic.io - npm Package Compare versions

Comparing version 1.0.20 to 1.0.21

.jshintrc

6

dist/prismic.io.min.js

@@ -1,5 +0,1 @@

/*!
* prismic.io 1.0.20
* See release notes: https://github.com/prismicio/javascript-kit/releases
*/
!function(a,b){"use strict";function c(a,b,c,d,e,f){this.name=a,this.fields=b,this.form_method=c,this.rel=d,this.enctype=e,this.action=f}function e(a,b,c){this.api=a,this.form=b,this.data=c||{};for(var d in b.fields)b.fields[d]["default"]&&(this.data[d]=[b.fields[d]["default"]])}function f(a){return this.fragments&&this.fragments[a]?Array.isArray(this.fragments[a])?this.fragments[a]:[this.fragments[a]]:[]}function g(a,b,c,d,e,f,g,h){this.page=a,this.results_per_page=b,this.results_size=c,this.total_results_size=d,this.total_pages=e,this.next_page=f,this.prev_page=g,this.results=h}function h(a,b,c,d){this.id=a,this.slug=b,this.type=c,this.tags=d}function i(a,b,c,d,e,f,g){this.id=a,this.type=b,this.href=c,this.tags=d,this.slug=e?e[0]:"-",this.slugs=e,this.linkedDocuments=f,this.fragments=g}function j(a,b,c,d,e){this.ref=a,this.label=b,this.isMaster=c,this.scheduledAt=d,this.id=e}function k(){this.cache={},this.states={}}var l=function(a,b,c,d,e){var f=new l.fn.init(a,c,d,e);return b&&f.get(b),f},m=function(){return"undefined"!=typeof XMLHttpRequest&&"withCredentials"in new XMLHttpRequest?function(a,b){var c=new XMLHttpRequest,d=function(){b(null,JSON.parse(c.responseText),c)},e=function(){var d=c.status;b(new Error("Unexpected status code ["+d+"] on URL "+a),null,c)};c.onreadystatechange=function(){4===c.readyState&&(c.status&&200==c.status?d():e())},c.open("GET",a,!0),c.setRequestHeader("Accept","application/json"),c.send()}:void 0},n=function(){return"undefined"!=typeof XDomainRequest?function(a,b){var c=new XDomainRequest,d=function(){b(null,JSON.parse(c.responseText),c)},e=function(a){b(new Error(a),null,c)};c.onload=function(){d(c)},c.onerror=function(){e("Unexpected status code on URL "+a)},c.open("GET",a,!0),c.ontimeout=function(){e("Request timeout")},c.onprogress=function(){},c.send()}:void 0},o=function(){if("function"==typeof require&&require("http")){var a={},c=require("http"),d=require("https"),e=require("url"),f=(require("querystring"),require("../package.json"));return function(g,h){if(a[g])h(null,a[g]);else{var i=e.parse(g),j="https:"==i.protocol?d:c,k={hostname:i.hostname,path:i.path,query:i.query,headers:{Accept:"application/json","User-Agent":"Prismic-javascript-kit/"+f.version+" NodeJS/"+process.version}};j.get(k,function(c){if(c.statusCode&&200==c.statusCode){var d="";c.setEncoding("utf8"),c.on("data",function(a){d+=a}),c.on("end",function(){var e=c.headers["cache-control"],f=e&&/max-age=(\d+)/.test(e)?parseInt(/max-age=(\d+)/.exec(e)[1]):b,i=JSON.parse(d);f&&(a[g]=i),h(null,i,c)})}else h(new Error("Unexpected status code ["+c.statusCode+"] on URL "+g),null,c)})}}}};l.fn=l.prototype={AT:"at",ANY:"any",SIMILAR:"similar",FULLTEXT:"fulltext",NUMBER:{GT:"number.gt",LT:"number.lt"},DATE:{AFTER:"date.after",BEFORE:"date.before",BETWEEN:"date.between"},DOCUMENT:{ID:"document.id",TYPE:"document.type",TAGS:"document.tags"},constructor:l,data:null,get:function(a){var b=this,c=this.url+(this.accessToken?"#"+this.accessToken:"");this.apiCache.getOrSet(c,5,function(a){b.requestHandler(b.url,function(c,d,e){c?a&&a(c,null,e):a&&a(null,b.parse(d),e)})},function(c,d,e){c?a&&a(c,null,e):(b.data=d,b.bookmarks=d.bookmarks,a&&a(null,b,e))})},parse:function(a){var b,d,e,f,g,h,i,k={};for(i in a.forms)a.forms.hasOwnProperty(i)&&(h=a.forms[i],this.accessToken&&(h.fields.access_token={},h.fields.access_token.type="string",h.fields.access_token["default"]=this.accessToken),e=new c(h.name,h.fields,h.form_method,h.rel,h.enctype,h.action),k[i]=e);if(b=a.refs.map(function(a){return new j(a.ref,a.label,a.isMasterRef,a.scheduledAt,a.id)})||[],d=b.filter(function(a){return a.isMaster===!0}),f=a.types,g=a.tags,0===d.length)throw"No master ref.";return{bookmarks:a.bookmarks||{},refs:b,forms:k,master:d[0],types:f,tags:g,oauthInitiate:a.oauth_initiate,oauthToken:a.oauth_token}},init:function(a,b,c,d){return this.url=a+(b?(a.indexOf("?")>-1?"&":"?")+"access_token="+b:""),this.accessToken=b,this.requestHandler=c||m()||n()||o()||function(){throw new Error("No request handler available (tried XMLHttpRequest & NodeJS)")}(),this.apiCache=d||new k,this},forms:function(a){return this.form(a)},form:function(a){var b=this.data.forms[a];return b?new e(this,b,{}):void 0},master:function(){return this.data.master.ref},ref:function(a){for(var b=0;b<this.data.refs.length;b++)if(this.data.refs[b].label==a)return this.data.refs[b].ref}},l.fn.init.prototype=l.fn,c.prototype={},e.prototype={set:function(a,c){var d=this.form.fields[a];if(!d)throw new Error("Unknown field "+a);var e=this.data[a]||[];return(""===c||c===b)&&(c=null),d.multiple?null!=c&&e.push(c):e=null!=c&&[c],this.data[a]=e,this},ref:function(a){return this.set("ref",a)},query:function(a){if("string"==typeof a)return this.set("q",a);var b=[].slice.apply(arguments),c=[];return b.forEach(function(a){var b=0==a[1].indexOf("my.")||0==a[1].indexOf("document.")?a[1]:'"'+a[1]+'"';c.push("[:d = "+a[0]+"("+b+", "+function(){return a.slice(2).map(function(a){return"string"==typeof a?'"'+a+'"':Array.isArray(a)?"["+a.map(function(a){return'"'+a+'"'}).join(",")+"]":a instanceof Date?d.getTime():a}).join(",")}()+")]")}),this.query("["+c.join("")+"]")},pageSize:function(a){return this.set("pageSize",a)},page:function(a){return this.set("page",a)},orderings:function(a){return this.set("orderings",a)},submit:function(a){var b=this.form.action;if(this.data){var c=b.indexOf("?")>-1?"&":"?";for(var d in this.data){var e=this.data[d];if(e)for(var f=0;f<e.length;f++)b+=c+d+"="+encodeURIComponent(e[f]),c="&"}}this.api.requestHandler(b,function(b,c,d){if(b)return void a(b,null,d);var e=c.results.map(function(a){var b=[];a.linked_documents&&(b=a.linked_documents.map(function(a){return new h(a.id,a.slug,a.type,a.tags)}));var c={};for(var d in a.data[a.type])c[a.type+"."+d]=a.data[a.type][d];return new i(a.id,a.type,a.href,a.tags,a.slugs,b,c)});a(null,new g(c.page,c.results_per_page,c.results_size,c.total_results_size,c.total_pages,c.next_page,c.prev_page,e||[]),d)})}},i.prototype={get:function(b){var c=f.call(this,b);return c.length?a.Prismic.Fragments.initField(c[0]):null},getAll:function(b){return f.call(this,b).map(function(b){return a.Prismic.Fragments.initField(b)},this)},getImage:function(b){var c=this.get(b);return c instanceof a.Prismic.Fragments.Image?c:c instanceof a.Prismic.Fragments.StructuredText?c:null},getAllImages:function(b){var c=this.getAll(b);return c.map(function(b){if(b instanceof a.Prismic.Fragments.Image)return b;if(b instanceof a.Prismic.Fragments.StructuredText)throw new Error("Not done.");return null})},getImageView:function(b,c){var d=this.get(b);if(d instanceof a.Prismic.Fragments.Image)return d.getView(c);if(d instanceof a.Prismic.Fragments.StructuredText)for(var e=0;e<d.blocks.length;e++)if("image"==d.blocks[e].type)return d.blocks[e];return null},getAllImageViews:function(a,b){return this.getAllImages(a).map(function(a){return a.getView(b)})},getDate:function(b){var c=this.get(b);return c instanceof a.Prismic.Fragments.Date?c.value:void 0},getBoolean:function(a){var b=this.get(a);return b.value&&("yes"==b.value.toLowerCase()||"on"==b.value.toLowerCase()||"true"==b.value.toLowerCase())},getText:function(b,c){var d=this.get(b);return d instanceof a.Prismic.Fragments.StructuredText?d.blocks.map(function(a){return a.text?a.text+(c?c:""):void 0}).join("\n"):d instanceof a.Prismic.Fragments.Text&&d.value?d.value+(c?c:""):d instanceof a.Prismic.Fragments.Number&&d.value?d.value+(c?c:""):d instanceof a.Prismic.Fragments.Select&&d.value?d.value+(c?c:""):d instanceof a.Prismic.Fragments.Color&&d.value?d.value+(c?c:""):void 0},getStructuredText:function(b){var c=this.get(b);return c instanceof a.Prismic.Fragments.StructuredText?c:void 0},getNumber:function(b){var c=this.get(b);return c instanceof a.Prismic.Fragments.Number?c.value:void 0},getColor:function(b){var c=this.get(b);return c instanceof a.Prismic.Fragments.Color?c.value:void 0},getGeoPoint:function(b){var c=this.get(b);return c instanceof a.Prismic.Fragments.GeoPoint?c:void 0},getGroup:function(b){var c=this.get(b);return c instanceof a.Prismic.Fragments.Group?c:void 0},getHtml:function(a,b){var c=this.get(a);return c&&c.asHtml?c.asHtml(b):void 0},asHtml:function(a){var b=[];for(var c in this.fragments){var d=this.get(c);b.push(d&&d.asHtml?'<section data-field="'+c+'">'+d.asHtml(a)+"</section>":"")}return b.join("")},asText:function(a){var b=[];for(var c in this.fragments){var d=this.get(c);b.push(d&&d.asText?d.asText(a):"")}return b.join("")}},j.prototype={},k.prototype={get:function(a){var b=this.cache[a];return b&&(!this.isExpired(a)||this.isExpired(a)&&this.isInProgress(a))?b.data:null},set:function(a,b,c){this.cache[a]={data:b,expiredIn:c?Date.now()+1e3*c:0}},getOrSet:function(a,b,c,d){var e=this.get(a),f=this;if(e)d&&d(null,e);else{this.states[a]="progress";{c(function(c,e,g){f.set(a,e,b),delete f.states[a],d&&d(c,e,g)})}}},isExpired:function(a){var b=this.cache[a];return b?0!=b.expiredIn&&b.expiredIn<Date.now():!1},isInProgress:function(a){return"progress"==this.states[a]},exists:function(a){return!!this.cache[a]},remove:function(a){return delete this.cache[a]},clear:function(){this.cache={}}},a.Prismic={Api:l}}("object"==typeof exports&&exports?exports:"object"==typeof module&&module&&"object"==typeof module.exports?module.exports:window),function(a){"use strict";function b(a){this.value=a}function c(a){this.value=a,this.document=a.document,this.isBroken=a.isBroken}function d(a){this.value=a}function e(a){this.value=a}function f(a){this.value=a}function g(a){this.value=a}function h(a){this.value=a}function i(a,b){this.latitude=a,this.longitude=b}function j(a){this.value=a}function k(a){this.value=new Date(a)}function l(a){var b=24==a.length?a.substring(0,22)+":"+a.substring(22,24):a;this.value=new Date(b)}function m(a){this.value=a}function n(a,b){this.main=a,this.views=b||{}}function o(a,b,c,d){this.url=a,this.width=b,this.height=c,this.alt=d}function p(a){this.value=a}function q(a){this.blocks=a}function r(a){return a&&a.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function s(a,b,c,d){if(!b||!b.length)return r(a);var e={},f={};b.forEach(function(a){e[a.start]||(e[a.start]=[]),f[a.end]||(f[a.end]=[]),e[a.start].push(a),f[a.end].unshift(a)});for(var g,h="",i=[],j=0,k=a.length+1;k>j;j++)f[j]&&f[j].forEach(function(){var a=i.pop(),b=v(a.span,a.text,d);0==i.length?h+=b:i[i.length-1].text+=b}),e[j]&&(e[j].sort(function(a,b){return b.end-b.start-(a.end-a.start)}),e[j].forEach(function(a){var b=null;if("hyperlink"==a.type){var d=t(a.data);if(!d)return console&&console.error&&console.error("Impossible to convert span.data as a Fragment",a),"";b=d.url(c),a.url=b}var e={span:a,text:""};i.push(e)})),j<a.length&&(g=a[j],0==i.length?h+=r(g):i[i.length-1].text+=r(g));return h}function t(a){var r,s;switch(a.type){case"Color":r=new h(a.value);break;case"Number":r=new j(a.value);break;case"Date":r=new k(a.value);break;case"Timestamp":r=new l(a.value);break;case"Text":r=new b(a.value);break;case"Embed":r=new m(a.value);break;case"GeoPoint":r=new i(a.value.latitude,a.value.longitude);break;case"Select":r=new g(a.value);break;case"Image":s=a.value.main,r=new n(new o(s.url,s.dimensions.width,s.dimensions.height,s.alt),{});for(var u in a.value.views)s=a.value.views[u],r.views[u]=new o(s.url,s.dimensions.width,s.dimensions.height,s.alt);break;case"StructuredText":r=new q(a.value);break;case"Link.document":r=new c(a.value);break;case"Link.web":r=new d(a.value);break;case"Link.file":r=new e(a.value);break;case"Link.image":r=new f(a.value);break;case"Group":for(var v=[],w=0;w<a.value.length;w++){var x={};for(var y in a.value[w])x[y]=t(a.value[w][y]);v.push(x)}r=new p(v);break;default:console&&console.log&&console.log("Fragment type not supported: ",a.type)}return r}function u(a){var b={};return a&&"[object Function]"===b.toString.call(a)}function v(a,b,c){if(c){var d=c(a,b);if(d)return d}var e={heading1:"h1",heading2:"h2",heading3:"h3",heading4:"h4",heading5:"h5",heading6:"h6",paragraph:"p",preformatted:"pre","list-item":"li","o-list-item":"li","group-list-item":"ul","group-o-list-item":"ol",strong:"strong",em:"em"};if(e[a.type]){var f=e[a.type],g=a.label?' class="'+a.label+'"':"";return"<"+f+g+">"+b+"</"+f+">"}if("image"==a.type){var h=a.label?" "+a.label:"",i='<img src="'+a.url+'" alt="'+a.alt+'">';return'<p class="block-img'+h+'">'+(a.linkUrl?'<a href="'+a.linkUrl+'">'+i+"</a>":i)+"</p>"}return"embed"==a.type?'<div data-oembed="'+a.embed_url+'" data-oembed-type="'+a.type+'" data-oembed-provider="'+a.provider_name+(a.label?'" class="'+h:"")+'">'+a.oembed.html+"</div>":"hyperlink"===a.type?'<a href="'+a.url+'">'+b+"</a>":"label"===a.type?'<span class="'+a.data.label+'">'+b+"</span>":"<!-- Warning: "+a.type+" not implemented. Upgrade the Developer Kit. -->"+b}b.prototype={asHtml:function(){return"<span>"+this.value+"</span>"},asText:function(){return this.value}},c.prototype={asHtml:function(a){return'<a href="'+this.url(a)+'">'+this.url(a)+"</a>"},url:function(a){return a(this.document,this.isBroken)},asText:function(a){return this.url(a)}},d.prototype={asHtml:function(){return'<a href="'+this.url()+'">'+this.url()+"</a>"},url:function(){return this.value.url},asText:function(){return this.url()}},e.prototype={asHtml:function(){return'<a href="'+this.url()+'">'+this.value.file.name+"</a>"},url:function(){return this.value.file.url},asText:function(){return this.url()}},f.prototype={asHtml:function(){return'<a href="'+this.url()+'"><img src="'+this.url()+'" alt="'+this.alt+'"></a>'},url:function(){return this.value.image.url},asText:function(){return this.url()}},g.prototype={asHtml:function(){return"<span>"+this.value+"</span>"},asText:function(){return this.value}},h.prototype={asHtml:function(){return"<span>"+this.value+"</span>"},asText:function(){return this.value}},i.prototype={asHtml:function(){return'<div class="geopoint"><span class="latitude">'+this.latitude+'</span><span class="longitude">'+this.longitude+"</span></div>"},asText:function(){return"("+this.latitude+","+this.longitude+")"}},j.prototype={asHtml:function(){return"<span>"+this.value+"</span>"},asText:function(){return this.value.toString()}},k.prototype={asHtml:function(){return"<time>"+this.value+"</time>"},asText:function(){return this.value.toString()}},l.prototype={asHtml:function(){return"<time>"+this.value+"</time>"},asText:function(){return this.value.toString()}},m.prototype={asHtml:function(){return this.value.oembed.html},asText:function(){return""}},n.prototype={getView:function(a){return"main"===a?this.main:this.views[a]},asHtml:function(){return this.main.asHtml()},asText:function(){return""}},o.prototype={ratio:function(){return this.width/this.height},asHtml:function(){return"<img src="+this.url+" width="+this.width+" height="+this.height+' alt="'+this.alt+'">'},asText:function(){return""}},p.prototype={asHtml:function(a){for(var b="",c=0;c<this.value.length;c++)for(var d in this.value[c])b+='<section data-field="'+d+'">',b+=this.value[c][d].asHtml(a),b+="</section>";return b},toArray:function(){return this.value},asText:function(a){for(var b="",c=0;c<this.value.length;c++)for(var d in this.value[c])b+=this.value[c][d].asText(a);return b}},q.prototype={getTitle:function(){for(var a=0;a<this.blocks.length;a++){var b=this.blocks[a];if(0==b.type.indexOf("heading"))return b}},getFirstParagraph:function(){for(var a=0;a<this.blocks.length;a++){var b=this.blocks[a];if("paragraph"==b.type)return b}},getParagraphs:function(){for(var a=[],b=0;b<this.blocks.length;b++){var c=this.blocks[b];"paragraph"==c.type&&a.push(c)}return a},getParagraph:function(a){return this.getParagraphs()[a]},getFirstImage:function(){for(var a=0;a<this.blocks.length;a++){var b=this.blocks[a];if("image"==b.type)return new o(b.url,b.dimensions.width,b.dimensions.height,b.alt)}},asHtml:function(a,b){var c,d,e=[],f=[];if(!u(a)){var g=a;a=function(a,b){return g.linkResolver(g,a,b)}}if(Array.isArray(this.blocks)){for(var h=0;h<this.blocks.length;h++){if(d=this.blocks[h],"image"==d.type&&d.linkTo){var i=t(d.linkTo);d.linkUrl=i.url(a)}"list-item"!==d.type&&"o-list-item"!==d.type?(e.push(d),c=null):c&&c.type=="group-"+d.type?c.blocks.push(d):(c={type:"group-"+d.type,blocks:[d]},e.push(c))}var j=function(c){var d="";return c.blocks?c.blocks.forEach(function(a){d+=v(a,j(a),b)}):d=s(c.text,c.spans,a,b),d};e.forEach(function(a){f.push(v(a,j(a),b))})}return f.join("")},asText:function(){for(var a=[],b=0;b<this.blocks.length;b++){var c=this.blocks[b];c.text&&a.push(c.text)}return a.join(" ")}},a.Prismic.Fragments={Image:n,ImageView:o,Text:b,Number:j,Date:k,Timestamp:l,Select:g,Color:h,StructuredText:q,WebLink:d,DocumentLink:c,ImageLink:f,FileLink:e,Group:p,GeoPoint:i,initField:t,insertSpans:s}}("object"==typeof exports&&exports?exports:"object"==typeof module&&module&&"object"==typeof module.exports?module.exports:window),function(a){"use strict";var b={at:function(a,b){return["at",a,b]},any:function(a,b){return["any",a,b]},fulltext:function(a,b){return["fulltext",a,b]},similar:function(a,b){return["similar",a,b]},gt:function(a,b){return["number.gt",a,b]},lt:function(a,b){return["number.lt",a,b]},inRange:function(a,b,c){return["number.inRange",a,b,c]},dateBefore:function(a,b){return["date.before",a,b]},dateAfter:function(a,b){return["date.after",a,b]},dateBetween:function(a,b,c){return["date.between",a,b,c]},dayOfMonth:function(a,b){return["date.day-of-month",a,b]},dayOfMonthAfter:function(a,b){return["date.day-of-month-after",a,b]},dayOfMonthBefore:function(a,b){return["date.day-of-month-before",a,b]},dayOfWeek:function(a,b){return["date.day-of-week",a,b]},dayOfWeekAfter:function(a,b){return["date.day-of-week-after",a,b]},dayOfWeekBefore:function(a,b){return["date.day-of-week-before",a,b]},month:function(a,b){return["date.month",a,b]},monthBefore:function(a,b){return["date.month-before",a,b]},monthAfter:function(a,b){return["date.month-after",a,b]},year:function(a,b){return["date.year",a,b]},hour:function(a,b){return["date.hour",a,b]},hourBefore:function(a,b){return["date.hour-before",a,b]},hourAfter:function(a,b){return["date.hour-after",a,b]},near:function(a,b,c){return["near",a,b,c]}};a.Prismic.Predicates=b}("object"==typeof exports&&exports?exports:"object"==typeof module&&module&&"object"==typeof module.exports?module.exports:window);
!function(){Object.create||(Object.create=function(){function t(){}return function(e){if(1!=arguments.length)throw new Error("Object.create implementation only accepts one parameter.");return t.prototype=e,new t}}())}(),function(t,e){"use strict";function n(t,e,n,r,i,o){this.name=t,this.fields=e,this.form_method=n,this.rel=r,this.enctype=i,this.action=o}function r(t,e,n){this.api=t,this.form=e,this.data=n||{};for(var r in e.fields)e.fields[r]["default"]&&(this.data[r]=[e.fields[r]["default"]])}function i(t,e,n,r,i,o,s,a){this.page=t,this.results_per_page=e,this.results_size=n,this.total_results_size=r,this.total_pages=i,this.next_page=o,this.prev_page=s,this.results=a}function o(t,e,n,r){this.id=t,this.slug=e,this.type=n,this.tags=r}function s(t,e,n,r,i){this.ref=t,this.label=e,this.isMaster=n,this.scheduledAt=r,this.id=i}function a(){this.cache={},this.states={}}var u=function(t,e,n,r,i){var o=new u.fn.init(t,n,r,i);return e&&o.get(e),o},c=function(){return"undefined"!=typeof XMLHttpRequest&&"withCredentials"in new XMLHttpRequest?function(t,e){var n=new XMLHttpRequest,r=function(){e(null,JSON.parse(n.responseText),n)},i=function(){var r=n.status;e(new Error("Unexpected status code ["+r+"] on URL "+t),null,n)};n.onreadystatechange=function(){4===n.readyState&&(n.status&&200==n.status?r():i())},n.open("GET",t,!0),n.setRequestHeader("Accept","application/json"),n.send()}:void 0},l=function(){return"undefined"!=typeof XDomainRequest?function(t,e){var n=new XDomainRequest,r=function(){e(null,JSON.parse(n.responseText),n)},i=function(t){e(new Error(t),null,n)};n.onload=function(){r(n)},n.onerror=function(){i("Unexpected status code on URL "+t)},n.open("GET",t,!0),n.ontimeout=function(){i("Request timeout")},n.onprogress=function(){},n.send()}:void 0},f=function(){if("function"==typeof require&&require("http")){var t={},n=require("http"),r=require("https"),i=require("url"),o=(require("querystring"),require("../package.json"));return function(s,a){if(t[s])a(null,t[s]);else{var u=i.parse(s),c="https:"==u.protocol?r:n,l={hostname:u.hostname,path:u.path,query:u.query,headers:{Accept:"application/json","User-Agent":"Prismic-javascript-kit/"+o.version+" NodeJS/"+process.version}};c.get(l,function(n){if(n.statusCode&&200==n.statusCode){var r="";n.setEncoding("utf8"),n.on("data",function(t){r+=t}),n.on("end",function(){var i=n.headers["cache-control"],o=i&&/max-age=(\d+)/.test(i)?parseInt(/max-age=(\d+)/.exec(i)[1]):e,u=JSON.parse(r);o&&(t[s]=u),a(null,u,n)})}else a(new Error("Unexpected status code ["+n.statusCode+"] on URL "+s),null,n)})}}}};u.fn=u.prototype={AT:"at",ANY:"any",SIMILAR:"similar",FULLTEXT:"fulltext",NUMBER:{GT:"number.gt",LT:"number.lt"},DATE:{AFTER:"date.after",BEFORE:"date.before",BETWEEN:"date.between"},DOCUMENT:{ID:"document.id",TYPE:"document.type",TAGS:"document.tags"},constructor:u,data:null,get:function(e){var n=this,r=this.url+(this.accessToken?"#"+this.accessToken:"");this.apiCache.getOrSet(r,5,function(t){n.requestHandler(n.url,function(e,r,i){e?t&&t(e,null,i):t&&t(null,n.parse(r),i)})},function(r,i,o){r?e&&e(r,null,o):(n.data=i,n.bookmarks=i.bookmarks,n.experiments=new t.Prismic.Experiments(i.experiments),e&&e(null,n,o))})},parse:function(t){var e,r,i,o,a,u,c,l={};for(c in t.forms)t.forms.hasOwnProperty(c)&&(u=t.forms[c],this.accessToken&&(u.fields.access_token={},u.fields.access_token.type="string",u.fields.access_token["default"]=this.accessToken),i=new n(u.name,u.fields,u.form_method,u.rel,u.enctype,u.action),l[c]=i);if(e=t.refs.map(function(t){return new s(t.ref,t.label,t.isMasterRef,t.scheduledAt,t.id)})||[],r=e.filter(function(t){return t.isMaster===!0}),o=t.types,a=t.tags,0===r.length)throw"No master ref.";return{bookmarks:t.bookmarks||{},refs:e,forms:l,master:r[0],types:o,tags:a,oauthInitiate:t.oauth_initiate,oauthToken:t.oauth_token}},init:function(t,e,n,r){return this.url=t+(e?(t.indexOf("?")>-1?"&":"?")+"access_token="+e:""),this.accessToken=e,this.requestHandler=n||c()||l()||f()||function(){throw new Error("No request handler available (tried XMLHttpRequest & NodeJS)")}(),this.apiCache=r||new a,this},forms:function(t){return this.form(t)},form:function(t){var e=this.data.forms[t];return e?new r(this,e,{}):void 0},master:function(){return this.data.master.ref},ref:function(t){for(var e=0;e<this.data.refs.length;e++)if(this.data.refs[e].label==t)return this.data.refs[e].ref},currentExperiment:function(){return this.experiments.current()},parseDoc:function(e){var n=[];e.linked_documents&&(n=e.linked_documents.map(function(t){return new o(t.id,t.slug,t.type,t.tags)}));var r={};for(var i in e.data[e.type])r[e.type+"."+i]=e.data[e.type][i];return new t.Prismic.Document(e.id,e.type,e.href,e.tags,e.slugs,n,r)}},u.fn.init.prototype=u.fn,n.prototype={},r.prototype={set:function(t,n){var r=this.form.fields[t];if(!r)throw new Error("Unknown field "+t);var i=this.data[t]||[];return(""===n||n===e)&&(n=null),r.multiple?n&&i.push(n):i=n&&[n],this.data[t]=i,this},ref:function(t){return this.set("ref",t)},query:function(t){if("string"==typeof t)return this.set("q",t);var e=[].slice.apply(arguments),n=[];return e.forEach(function(t){var e=0===t[1].indexOf("my.")||0===t[1].indexOf("document.")?t[1]:'"'+t[1]+'"';n.push("[:d = "+t[0]+"("+e+", "+function(){return t.slice(2).map(function(t){return"string"==typeof t?'"'+t+'"':Array.isArray(t)?"["+t.map(function(t){return'"'+t+'"'}).join(",")+"]":t instanceof Date?t.getTime():t}).join(",")}()+")]")}),this.query("["+n.join("")+"]")},pageSize:function(t){return this.set("pageSize",t)},page:function(t){return this.set("page",t)},orderings:function(t){return this.set("orderings",t)},submit:function(t){var e=this.form.action;if(this.data){var n=e.indexOf("?")>-1?"&":"?";for(var r in this.data){var o=this.data[r];if(o)for(var s=0;s<o.length;s++)e+=n+r+"="+encodeURIComponent(o[s]),n="&"}}this.api.requestHandler(e,function(e,n,r){if(e)return void t(e,null,r);var o=n.results.map(u.fn.parseDoc);t(null,new i(n.page,n.results_per_page,n.results_size,n.total_results_size,n.total_pages,n.next_page,n.prev_page,o||[]),r)})}},s.prototype={},a.prototype={get:function(t){var e=this.cache[t];return e&&(!this.isExpired(t)||this.isExpired(t)&&this.isInProgress(t))?e.data:null},set:function(t,e,n){this.cache[t]={data:e,expiredIn:n?Date.now()+1e3*n:0}},getOrSet:function(t,e,n,r){var i=this.get(t),o=this;if(i)r&&r(null,i);else{this.states[t]="progress";{n(function(n,i,s){o.set(t,i,e),delete o.states[t],r&&r(n,i,s)})}}},isExpired:function(t){var e=this.cache[t];return e?0!==e.expiredIn&&e.expiredIn<Date.now():!1},isInProgress:function(t){return"progress"===this.states[t]},exists:function(t){return!!this.cache[t]},remove:function(t){return delete this.cache[t]},clear:function(){this.cache={}}},t.Prismic={Api:u}}("object"==typeof exports&&exports?exports:"object"==typeof module&&module&&"object"==typeof module.exports?module.exports:window),function(t){"use strict";function e(){}function n(t,e,n,r,i,o,s){this.id=t,this.type=e,this.href=n,this.tags=r,this.slug=i?i[0]:"-",this.slugs=i,this.linkedDocuments=o,this.fragments=s}function r(t){this.fragments=t}function i(t){var e={};return t&&"[object Function]"===e.toString.call(t)}e.prototype={get:function(e){var n=this._getFragments(e);return n.length?t.Prismic.Fragments.initField(n[0]):null},getAll:function(e){return this._getFragments(e).map(function(e){return t.Prismic.Fragments.initField(e)},this)},getImage:function(e){var n=this.get(e);return n instanceof t.Prismic.Fragments.Image?n:n instanceof t.Prismic.Fragments.StructuredText?n:null},getAllImages:function(e){var n=this.getAll(e);return n.map(function(e){if(e instanceof t.Prismic.Fragments.Image)return e;if(e instanceof t.Prismic.Fragments.StructuredText)throw new Error("Not done.");return null})},getImageView:function(e,n){var r=this.get(e);if(r instanceof t.Prismic.Fragments.Image)return r.getView(n);if(r instanceof t.Prismic.Fragments.StructuredText)for(var i=0;i<r.blocks.length;i++)if("image"==r.blocks[i].type)return r.blocks[i];return null},getAllImageViews:function(t,e){return this.getAllImages(t).map(function(t){return t.getView(e)})},getTimestamp:function(e){var n=this.get(e);return n instanceof t.Prismic.Fragments.Timestamp?n.value:void 0},getDate:function(e){var n=this.get(e);return n instanceof t.Prismic.Fragments.Date?n.value:void 0},getBoolean:function(t){var e=this.get(t);return e.value&&("yes"==e.value.toLowerCase()||"on"==e.value.toLowerCase()||"true"==e.value.toLowerCase())},getText:function(e,n){var r=this.get(e);return r instanceof t.Prismic.Fragments.StructuredText?r.blocks.map(function(t){return t.text?t.text+(n?n:""):void 0}).join("\n"):r instanceof t.Prismic.Fragments.Text&&r.value?r.value+(n?n:""):r instanceof t.Prismic.Fragments.Number&&r.value?r.value+(n?n:""):r instanceof t.Prismic.Fragments.Select&&r.value?r.value+(n?n:""):r instanceof t.Prismic.Fragments.Color&&r.value?r.value+(n?n:""):void 0},getStructuredText:function(e){var n=this.get(e);return n instanceof t.Prismic.Fragments.StructuredText?n:null},getLink:function(e){var n=this.get(e);return n instanceof t.Prismic.Fragments.WebLink||n instanceof t.Prismic.Fragments.DocumentLink||n instanceof t.Prismic.Fragments.ImageLink?n:null},getNumber:function(e){var n=this.get(e);return n instanceof t.Prismic.Fragments.Number?n.value:null},getColor:function(e){var n=this.get(e);return n instanceof t.Prismic.Fragments.Color?n.value:null},getGeoPoint:function(e){var n=this.get(e);return n instanceof t.Prismic.Fragments.GeoPoint?n:null},getGroup:function(e){var n=this.get(e);return n instanceof t.Prismic.Fragments.Group?n:null},getHtml:function(t,e){if(!i(e)){var n=e;e=function(t,e){return n.linkResolver(n,t,e)}}var r=this.get(t);return r&&r.asHtml?r.asHtml(e):null},asHtml:function(t){if(!i(t)){var e=t;t=function(t,n){return e.linkResolver(e,t,n)}}var n=[];for(var r in this.fragments){var o=this.get(r);n.push(o&&o.asHtml?'<section data-field="'+r+'">'+o.asHtml(t)+"</section>":"")}return n.join("")},asText:function(t){if(!i(t)){var e=t;t=function(t,n){return e.linkResolver(e,t,n)}}var n=[];for(var r in this.fragments){var o=this.get(r);n.push(o&&o.asText?o.asText(t):"")}return n.join("")},_getFragments:function(t){return this.fragments&&this.fragments[t]?Array.isArray(this.fragments[t])?this.fragments[t]:[this.fragments[t]]:[]}},n.prototype=Object.create(e.prototype,{}),r.prototype=Object.create(e.prototype,{}),t.Prismic.Document=n,t.Prismic.GroupDoc=r}("object"==typeof exports&&exports?exports:"object"==typeof module&&module&&"object"==typeof module.exports?module.exports:window),function(t){"use strict";function e(t){this.value=t}function n(t){this.value=t,this.document=t.document,this.isBroken=t.isBroken}function r(t){this.value=t}function i(t){this.value=t}function o(t){this.value=t}function s(t){this.value=t}function a(t){this.value=t}function u(t,e){this.latitude=t,this.longitude=e}function c(t){this.value=t}function l(t){this.value=new Date(t)}function f(t){var e=24==t.length?t.substring(0,22)+":"+t.substring(22,24):t;this.value=new Date(e)}function h(t){this.value=t}function p(t,e){this.main=t,this.views=e||{}}function m(t,e,n,r){this.url=t,this.width=e,this.height=n,this.alt=r}function d(e){this.value=[];for(var n=0;n<e.length;n++)this.value.push(new t.Prismic.GroupDoc(e[n]))}function g(t){this.blocks=t}function v(t){return t&&t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function y(t,e,n,r){if(!e||!e.length)return v(t);var i={},o={};e.forEach(function(t){i[t.start]||(i[t.start]=[]),o[t.end]||(o[t.end]=[]),i[t.start].push(t),o[t.end].unshift(t)});for(var s,a="",u=[],c=0,l=t.length+1;l>c;c++)o[c]&&o[c].forEach(function(){var t=u.pop(),e=k(t.span,t.text,r);0===u.length?a+=e:u[u.length-1].text+=e}),i[c]&&(i[c].sort(function(t,e){return e.end-e.start-(t.end-t.start)}),i[c].forEach(function(t){var e=null;if("hyperlink"==t.type){var r=b(t.data);if(!r)return console&&console.error&&console.error("Impossible to convert span.data as a Fragment",t),"";e=r.url(n),t.url=e}var i={span:t,text:""};u.push(i)})),c<t.length&&(s=t[c],0===u.length?a+=v(s):u[u.length-1].text+=v(s));return a}function b(t){var v,y;switch(t.type){case"Color":v=new a(t.value);break;case"Number":v=new c(t.value);break;case"Date":v=new l(t.value);break;case"Timestamp":v=new f(t.value);break;case"Text":v=new e(t.value);break;case"Embed":v=new h(t.value);break;case"GeoPoint":v=new u(t.value.latitude,t.value.longitude);break;case"Select":v=new s(t.value);break;case"Image":y=t.value.main,v=new p(new m(y.url,y.dimensions.width,y.dimensions.height,y.alt),{});for(var b in t.value.views)y=t.value.views[b],v.views[b]=new m(y.url,y.dimensions.width,y.dimensions.height,y.alt);break;case"StructuredText":v=new g(t.value);break;case"Link.document":v=new n(t.value);break;case"Link.web":v=new r(t.value);break;case"Link.file":v=new i(t.value);break;case"Link.image":v=new o(t.value);break;case"Group":v=new d(t.value);break;default:console&&console.log&&console.log("Fragment type not supported: ",t.type)}return v}function x(t){var e={};return t&&"[object Function]"===e.toString.call(t)}function k(t,e,n){if(n){var r=n(t,e);if(r)return r}var i={heading1:"h1",heading2:"h2",heading3:"h3",heading4:"h4",heading5:"h5",heading6:"h6",paragraph:"p",preformatted:"pre","list-item":"li","o-list-item":"li","group-list-item":"ul","group-o-list-item":"ol",strong:"strong",em:"em"};if(i[t.type]){var o=i[t.type],s=t.label?' class="'+t.label+'"':"";return"<"+o+s+">"+e+"</"+o+">"}if("image"==t.type){var a=t.label?" "+t.label:"",u='<img src="'+t.url+'" alt="'+t.alt+'">';return'<p class="block-img'+a+'">'+(t.linkUrl?'<a href="'+t.linkUrl+'">'+u+"</a>":u)+"</p>"}return"embed"==t.type?'<div data-oembed="'+t.embed_url+'" data-oembed-type="'+t.type+'" data-oembed-provider="'+t.provider_name+(t.label?'" class="'+t.label:"")+'">'+t.oembed.html+"</div>":"hyperlink"===t.type?'<a href="'+t.url+'">'+e+"</a>":"label"===t.type?'<span class="'+t.data.label+'">'+e+"</span>":"<!-- Warning: "+t.type+" not implemented. Upgrade the Developer Kit. -->"+e}e.prototype={asHtml:function(){return"<span>"+this.value+"</span>"},asText:function(){return this.value}},n.prototype={asHtml:function(t){return'<a href="'+this.url(t)+'">'+this.url(t)+"</a>"},url:function(t){return t(this.document,this.isBroken)},asText:function(t){return this.url(t)}},r.prototype={asHtml:function(){return'<a href="'+this.url()+'">'+this.url()+"</a>"},url:function(){return this.value.url},asText:function(){return this.url()}},i.prototype={asHtml:function(){return'<a href="'+this.url()+'">'+this.value.file.name+"</a>"},url:function(){return this.value.file.url},asText:function(){return this.url()}},o.prototype={asHtml:function(){return'<a href="'+this.url()+'"><img src="'+this.url()+'" alt="'+this.alt+'"></a>'},url:function(){return this.value.image.url},asText:function(){return this.url()}},s.prototype={asHtml:function(){return"<span>"+this.value+"</span>"},asText:function(){return this.value}},a.prototype={asHtml:function(){return"<span>"+this.value+"</span>"},asText:function(){return this.value}},u.prototype={asHtml:function(){return'<div class="geopoint"><span class="latitude">'+this.latitude+'</span><span class="longitude">'+this.longitude+"</span></div>"},asText:function(){return"("+this.latitude+","+this.longitude+")"}},c.prototype={asHtml:function(){return"<span>"+this.value+"</span>"},asText:function(){return this.value.toString()}},l.prototype={asHtml:function(){return"<time>"+this.value+"</time>"},asText:function(){return this.value.toString()}},f.prototype={asHtml:function(){return"<time>"+this.value+"</time>"},asText:function(){return this.value.toString()}},h.prototype={asHtml:function(){return this.value.oembed.html},asText:function(){return""}},p.prototype={getView:function(t){return"main"===t?this.main:this.views[t]},asHtml:function(){return this.main.asHtml()},asText:function(){return""}},m.prototype={ratio:function(){return this.width/this.height},asHtml:function(){return"<img src="+this.url+" width="+this.width+" height="+this.height+' alt="'+this.alt+'">'},asText:function(){return""}},d.prototype={asHtml:function(t){for(var e="",n=0;n<this.value.length;n++)e+=this.value[n].asHtml(t);return e},toArray:function(){return this.value},asText:function(t){for(var e="",n=0;n<this.value.length;n++)for(var r in this.value[n])e+=this.value[n][r].asText(t);return e}},g.prototype={getTitle:function(){for(var t=0;t<this.blocks.length;t++){var e=this.blocks[t];if(0===e.type.indexOf("heading"))return e}},getFirstParagraph:function(){for(var t=0;t<this.blocks.length;t++){var e=this.blocks[t];if("paragraph"==e.type)return e}},getParagraphs:function(){for(var t=[],e=0;e<this.blocks.length;e++){var n=this.blocks[e];"paragraph"==n.type&&t.push(n)}return t},getParagraph:function(t){return this.getParagraphs()[t]},getFirstImage:function(){for(var t=0;t<this.blocks.length;t++){var e=this.blocks[t];if("image"==e.type)return new m(e.url,e.dimensions.width,e.dimensions.height,e.alt)}},asHtml:function(t,e){var n,r,i=[],o=[];if(!x(t)){var s=t;t=function(t,e){return s.linkResolver(s,t,e)}}if(Array.isArray(this.blocks)){for(var a=0;a<this.blocks.length;a++){if(r=this.blocks[a],"image"==r.type&&r.linkTo){var u=b(r.linkTo);r.linkUrl=u.url(t)}"list-item"!==r.type&&"o-list-item"!==r.type?(i.push(r),n=null):n&&n.type=="group-"+r.type?n.blocks.push(r):(n={type:"group-"+r.type,blocks:[r]},i.push(n))}var c=function(n){var r="";return n.blocks?n.blocks.forEach(function(t){r+=k(t,c(t),e)}):r=y(n.text,n.spans,t,e),r};i.forEach(function(t){o.push(k(t,c(t),e))})}return o.join("")},asText:function(){for(var t=[],e=0;e<this.blocks.length;e++){var n=this.blocks[e];n.text&&t.push(n.text)}return t.join(" ")}},t.Prismic.Fragments={Image:p,ImageView:m,Text:e,Number:c,Date:l,Timestamp:f,Select:s,Color:a,StructuredText:g,WebLink:r,DocumentLink:n,ImageLink:o,FileLink:i,Group:d,GeoPoint:u,initField:b,insertSpans:y}}("object"==typeof exports&&exports?exports:"object"==typeof module&&module&&"object"==typeof module.exports?module.exports:window),function(t){"use strict";var e={at:function(t,e){return["at",t,e]},any:function(t,e){return["any",t,e]},fulltext:function(t,e){return["fulltext",t,e]},similar:function(t,e){return["similar",t,e]},gt:function(t,e){return["number.gt",t,e]},lt:function(t,e){return["number.lt",t,e]},inRange:function(t,e,n){return["number.inRange",t,e,n]},dateBefore:function(t,e){return["date.before",t,e]},dateAfter:function(t,e){return["date.after",t,e]},dateBetween:function(t,e,n){return["date.between",t,e,n]},dayOfMonth:function(t,e){return["date.day-of-month",t,e]},dayOfMonthAfter:function(t,e){return["date.day-of-month-after",t,e]},dayOfMonthBefore:function(t,e){return["date.day-of-month-before",t,e]},dayOfWeek:function(t,e){return["date.day-of-week",t,e]},dayOfWeekAfter:function(t,e){return["date.day-of-week-after",t,e]},dayOfWeekBefore:function(t,e){return["date.day-of-week-before",t,e]},month:function(t,e){return["date.month",t,e]},monthBefore:function(t,e){return["date.month-before",t,e]},monthAfter:function(t,e){return["date.month-after",t,e]},year:function(t,e){return["date.year",t,e]},hour:function(t,e){return["date.hour",t,e]},hourBefore:function(t,e){return["date.hour-before",t,e]},hourAfter:function(t,e){return["date.hour-after",t,e]},near:function(t,e,n,r){return["geopoint.near",t,e,n,r]}};t.Prismic.Predicates=e}("object"==typeof exports&&exports?exports:"object"==typeof module&&module&&"object"==typeof module.exports?module.exports:window),function(t){"use strict";function e(t){var e=[],r=[];t&&(t.drafts&&t.drafts.forEach(function(t){e.push(new n(t))}),t.running&&t.running.forEach(function(t){r.push(new n(t))})),this.drafts=e,this.running=r,this.cookieName=i}function n(t){this.data=t;var e=[];t.variations&&t.variations.forEach(function(t){e.push(new r(t))}),this.variations=e}function r(t){this.data=t}var i="io.prismic.experiment";e.prototype.current=function(){return this.running.length>0?this.running[0]:null},e.prototype.refFromCookie=function(t){if(!t||""===t.trim())return null;var e=t.trim().split("%20");if(e.length<2)return null;var n=e[0],r=parseInt(e[1],10);return this.running.forEach(function(t){return t.googleId()==n?t.variations.length>r?t.variations[r]:null:void 0}),null},n.prototype.id=function(){return this.data.id},n.prototype.googleId=function(){return this.data.googleId},n.prototype.name=function(){return this.data.name},r.prototype.id=function(){return this.data.id},r.prototype.ref=function(){return this.data.ref},r.prototype.label=function(){return this.data.label},t.Prismic.Experiments=e,t.Prismic.Experiment=n,t.Prismic.Variation=r}("object"==typeof exports&&exports?exports:"object"==typeof module&&module&&"object"==typeof module.exports?module.exports:window),function(t){t.Prismic.version="1.0.21"}("object"==typeof exports&&exports?exports:"object"==typeof module&&module&&"object"==typeof module.exports?module.exports:window);

@@ -12,14 +12,13 @@ {

],
"version": "1.0.20",
"version": "1.0.21",
"devDependencies": {
"grunt": "~0.4.1",
"grunt-bump": "~0.0.13",
"grunt-contrib-clean": "~0.5.0",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-connect": "0.8.0",
"grunt-contrib-copy": "~0.5.0",
"grunt-contrib-qunit": "0.2.2",
"grunt-contrib-uglify": "~0.2.2",
"grunt-gh-pages": "^0.9.1",
"grunt-jsdoc": "~0.5.4"
"gulp": "~3.8.8",
"gulp-uglify": "~1.0.1",
"gulp-util": "~3.0.1",
"gulp-concat": "~2.4.1",
"gulp-qunit": "~0.3.3",
"gulp-jsdoc": "~0.1.4",
"gulp-jshint": "~1.8.5",
"gulp-gist": "~1.0.3",
"gulp-gh-pages": "~0.3.4"
},

@@ -32,4 +31,4 @@ "repository": {

"scripts:": {
"test": "grunt test"
"test": "gulp test"
}
}

@@ -5,8 +5,7 @@ ## JavaScript development kit for prismic.io

### Getting started
* The [source code](https://github.com/prismicio/javascript-kit) is on Github.
* The [Changelog](https://github.com/prismicio/javascript-kit/releases) is on Github's releases tab.
#### Install the kit
### Installation
You can find downloadable versions of the kit on our release page: [https://github.com/prismicio/javascript-kit/releases](https://github.com/prismicio/javascript-kit/releases).
You can install a stable version using __npm__:

@@ -24,37 +23,21 @@

Finally, you can find downloadable versions of the kit on our release page: [https://github.com/prismicio/javascript-kit/releases](https://github.com/prismicio/javascript-kit/releases).
#### Get started with prismic.io
### Usage
You can find out [how to get started with prismic.io](https://developers.prismic.io/documentation/UjBaQsuvzdIHvE4D/getting-started) on our [prismic.io developer's portal](https://developers.prismic.io/).
If you don't have a Prismic.io repository yet, find out [how to get one](https://developers.prismic.io/documentation/UjBaQsuvzdIHvE4D/getting-started).
#### Get started using the kit
Once your repository is ready, you can use the Javascript kit server-side with Node.js, or client-side without needing and specific technology server-side. We provide various starter kits depending on your choice:
Also on our [prismic.io developer's portal](https://developers.prismic.io/), on top of our full documentation, you will:
* get a thorough introduction of [how to use prismic.io kits](https://developers.prismic.io/documentation/UjBe8bGIJ3EKtgBZ/api-documentation#kits-and-helpers), including this one.
* see [what else is available for Javascript](https://developers.prismic.io/technologies/UjBh28uvzeMJvE4i/javascript): starter projects, examples, ...
* [jQuery starter kit](https://github.com/prismicio/javascript-jquery-starter)
* [Node.js starter kit](https://github.com/prismicio/javascript-nodejs-starter)
* [Single page starter kit](https://github.com/prismicio/javascript-singlepage)
* [Static pages generation with baked.js](https://github.com/prismicio/baked.js)
### Using the kit
We're working hard to keep all the starter kit up-to-date, but it's always a good idea to check on this page if you're on the
latest version of the kit. We're constantly adding new features to Prismic.io, and it is necessary to have the latest version
to use all of them.
#### Kit's detailed documentation
You can then read the documentation from the [Developer's Portal](https://developers.prismic.io/) for more details on how to use
To get a detailed documentation of the JavaScript kit's variables and methods, please check out the [prismic.io JS kit's documentation](http://prismicio.github.io/javascript-kit/).
#### Specific JS kit syntax
The ["Kits and helpers" section of our API documentation](https://developers.prismic.io/documentation/UjBe8bGIJ3EKtgBZ/api-documentation#kits-and-helpers) is largely based on the JS kit, so there are not many differences:
* The `submit()` function takes a callback, which expects two parameters: a potential error, and the object of class `Documents` you can use.
* For security reasons, non-type-dependent fragments actually get written `document.getId()`, `document.getSlug()`, ... rather than `document.id`, `document.slug`, ...
* This is not a difference but a confirmation: `asHtml()` expects a `ctx` object that has a `linkResolver` closure and `maybeRef` string as its attributes.
Knowing all that, here is typical code written with the JavaScript kit:
* A typical API object instantiation looks like this: `Prismic.Api(url, callback)`
* A typical querying looks like this: `api.form('everything').query('[[:d = at(document.type, "product")]]').ref(ref).submit(callback)`
* A typical fragment manipulation looks like this: `doc.getImageView('article.image', 'icon').getUrl()`
* A typical fragment serialization to HTML looks like this: `doc.getStructuredText('article.body').asHtml(ctx)`
### Changelog
Need to see what changed, or to upgrade your kit? We keep our changelog on [this repository's "Releases" tab](https://github.com/prismicio/javascript-kit/releases).
### Contribute to the kit

@@ -66,7 +49,7 @@

You can simply execute this JavaScript kit with a web browser, but before committing, we kindly ask you to run the ```grunt``` command (it will make sure all tests still pass, and concatenate/minify your changes).
You can simply execute this JavaScript kit with a web browser, but before committing, we kindly ask you to run the ```gulp``` command (it will make sure all tests still pass, and concatenate/minify your changes).
To install grunt and other required packages: [install Node.js and npm](http://www.joyent.com/blog/installing-node-and-npm/), and then run this from your kit's repository, as an administrator:
To install gulp and other required packages: [install Node.js and npm](http://www.joyent.com/blog/installing-node-and-npm/), and then run this from your kit's repository, as an administrator:
```
npm install -g grunt
npm install -g gulp
npm install

@@ -79,9 +62,9 @@ ```

Execute the tests either by opening [test/test.html](test/test.html) or [test/unit.html](test/unit.html) in a browser, or by using Grunt:
Execute the tests either by opening [test/test.html](test/test.html) or [test/unit.html](test/unit.html) in a browser, or by using Gulp:
* ```grunt test``` will run all the tests and display the result on your shell
* ```grunt test:int``` will run all integration tests (the ones from [test/test.html](test/test.html))
* ```grunt test:unit``` will run all unit tests (the ones from [test/unit.html](test/unit.html))
* ```grunt test:browser``` will start a local server at [http://localhost:8888](http://localhost:8888) so that you can run the tests on your browser
* ```grunt test:local``` will test the local files without starting any server
* ```gulp jshint``` will run jshint to check for syntax errors or bad practice in the code
* ```gulp test``` will run jshint, all the tests and display the result on your shell
* ```gulp test:int``` will run all integration tests (the ones from [test/test.html](test/test.html))
* ```gulp test:unit``` will run all unit tests (the ones from [test/unit.html](test/unit.html))
* ```gulp test:doc``` will run all tests related to the code snippets from the documentation (the ones from [test/doc.html](test/doc.html))

@@ -102,3 +85,3 @@ If you find existing code that is not optimally tested and wish to make it better, we really appreciate it; but you should document it on its own branch and its own pull request.

Copyright 2013 Zengularity (http://www.zengularity.com).
Copyright 2013-2014 Zengularity (http://www.zengularity.com).

@@ -105,0 +88,0 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this project except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

@@ -19,3 +19,5 @@ (function (Global, undefined) {

var api = new prismic.fn.init(url, accessToken, maybeRequestHandler, maybeApiCache);
callback && api.get(callback);
if (callback) {
api.get(callback);
}
return api;

@@ -58,2 +60,5 @@ };

// Kit version (can't override the user-agent client side)
// xhr.setRequestHeader("X-Prismic-User-Agent", "Prismic-javascript-kit/%VERSION%".replace("%VERSION%", Global.Prismic.version));
// Json request

@@ -214,5 +219,5 @@ xhr.setRequestHeader('Accept', 'application/json');

if (error) {
cb && cb(error, null, xhr);
if (cb) cb(error, null, xhr);
} else {
cb && cb(null, self.parse(data), xhr);
if (cb) cb(null, self.parse(data), xhr);
}

@@ -222,8 +227,9 @@ });

function done (error, api, xhr) {
if(error) {
callback && callback(error, null, xhr);
if (error) {
if (callback) callback(error, null, xhr);
} else {
self.data = api;
self.bookmarks = api.bookmarks;
callback && callback(null, self, xhr);
self.experiments = new Global.Prismic.Experiments(api.experiments);
if (callback) callback(null, self, xhr);
}

@@ -373,4 +379,40 @@ }

}
},
/**
* The current experiment, or null
* @returns {Experiment}
*/
currentExperiment: function() {
return this.experiments.current();
},
/**
* Parse json as a document
*
* @returns {Document}
*/
parseDoc: function(json) {
var linkedDocuments = [];
if(json.linked_documents) {
linkedDocuments = json.linked_documents.map(function(linkedDoc) {
return new LinkedDocument(linkedDoc['id'], linkedDoc['slug'], linkedDoc['type'], linkedDoc['tags']);
});
}
var fragments = {};
for(var field in json.data[json.type]) {
fragments[json.type + '.' + field] = json.data[json.type][field];
}
return new Global.Prismic.Document(
json.id,
json.type,
json.href,
json.tags,
json.slugs,
linkedDocuments,
fragments
);
}
};

@@ -435,5 +477,5 @@

if(fieldDesc.multiple) {
value != null && values.push(value);
if (value) values.push(value);
} else {
values = value != null && [value];
values = value && [value];
}

@@ -471,4 +513,3 @@ this.data[field] = values;

predicates.forEach(function (predicate) {
var firstArg = (predicate[1].indexOf("my.") == 0 || predicate[1].indexOf("document.") == 0)
? predicate[1]
var firstArg = (predicate[1].indexOf("my.") === 0 || predicate[1].indexOf("document.") === 0) ? predicate[1]
: '"' + predicate[1] + '"';

@@ -484,3 +525,3 @@ stringQueries.push("[:d = " + predicate[0] + "(" + firstArg + ", " + (function() {

} else if (p instanceof Date) {
return d.getTime();
return p.getTime();
} else {

@@ -555,27 +596,4 @@ return p;

var results = documents.results.map(function (doc) {
var results = documents.results.map(prismic.fn.parseDoc);
var linkedDocuments = [];
if(doc.linked_documents) {
linkedDocuments = doc.linked_documents.map(function(linkedDoc) {
return new LinkedDocument(linkedDoc['id'], linkedDoc['slug'], linkedDoc['type'], linkedDoc['tags']);
});
}
var fragments = {};
for(var field in doc.data[doc.type]) {
fragments[doc.type + '.' + field] = doc.data[doc.type][field];
}
return new Doc(
doc.id,
doc.type,
doc.href,
doc.tags,
doc.slugs,
linkedDocuments,
fragments
);
});
callback(null, new Response(

@@ -597,20 +615,3 @@ documents.page,

/**
* An array of the fragments with the given fragment name.
* The array is often a single-element array, expect when the fragment is a multiple fragment.
* @private
*/
function getFragments(name) {
if (!this.fragments || !this.fragments[name]) {
return [];
}
if (Array.isArray(this.fragments[name])) {
return this.fragments[name];
} else {
return [this.fragments[name]];
}
}
/**

@@ -692,343 +693,2 @@ * Embodies the response of a SearchForm query as returned by the API.

/**
* Embodies a document as returned by the API.
* Most useful fields: id, type, tags, slug, slugs
* @constructor
* @global
* @alias Doc
*/
function Doc(id, type, href, tags, slugs, linkedDocuments, fragments) {
/**
* The ID of the document
* @type {string}
*/
this.id = id;
/**
* The type of the document, corresponds to a document mask defined in the repository
* @type {string}
*/
this.type = type;
/**
* The URL of the document in the API
* @type {string}
*/
this.href = href;
/**
* The tags of the document
* @type {array}
*/
this.tags = tags;
/**
* The current slug of the document, "-" if none was provided
* @type {string}
*/
this.slug = slugs ? slugs[0] : "-";
/**
* All the slugs that were ever used by this document (including the current one, at the head)
* @type {array}
*/
this.slugs = slugs;
/**
* Linked documents, as an array of {@link LinkedDocument}
* @type {array}
*/
this.linkedDocuments = linkedDocuments;
this.fragments = fragments;
}
Doc.prototype = {
/**
* Gets the fragment in the current Document object. Since you most likely know the type
* of this fragment, it is advised that you use a dedicated method, like get StructuredText() or getDate(),
* for instance.
*
* @param {string} name - The name of the fragment to get, with its type; for instance, "blog-post.author"
* @returns {object} - The JavaScript Fragment object to manipulate
*/
get: function(name) {
var frags = getFragments.call(this, name);
return frags.length ? Global.Prismic.Fragments.initField(frags[0]) : null;
},
/**
* Builds an array of all the fragments in case they are multiple.
*
* @param {string} name - The name of the multiple fragment to get, with its type; for instance, "blog-post.author"
* @returns {array} - An array of each JavaScript fragment object to manipulate.
*/
getAll: function(name) {
return getFragments.call(this, name).map(function (fragment) {
return Global.Prismic.Fragments.initField(fragment);
}, this);
},
/**
* Gets the image fragment in the current Document object, for further manipulation.
*
* @example document.getImage('blog-post.photo').asHtml(ctx)
*
* @param {string} fragment - The name of the fragment to get, with its type; for instance, "blog-post.photo"
* @returns {ImageEl} - The Image object to manipulate
*/
getImage: function(fragment) {
var img = this.get(fragment);
if (img instanceof Global.Prismic.Fragments.Image) {
return img;
}
if (img instanceof Global.Prismic.Fragments.StructuredText) {
// find first image in st.
return img;
}
return null;
},
// Useful for obsolete multiples
getAllImages: function(fragment) {
var images = this.getAll(fragment);
return images.map(function (image) {
if (image instanceof Global.Prismic.Fragments.Image) {
return image;
}
if (image instanceof Global.Prismic.Fragments.StructuredText) {
throw new Error("Not done.");
}
return null;
});
},
/**
* Gets the view within the image fragment in the current Document object, for further manipulation.
*
* @example document.getImageView('blog-post.photo', 'large').asHtml(ctx)
*
* @param {string} fragment - The name of the fragment to get, with its type; for instance, "blog-post.photo"
* @returns {ImageView} - The View object to manipulate
*/
getImageView: function(name, view) {
var fragment = this.get(name);
if (fragment instanceof Global.Prismic.Fragments.Image) {
return fragment.getView(view);
}
if (fragment instanceof Global.Prismic.Fragments.StructuredText) {
for(var i=0; i<fragment.blocks.length; i++) {
if(fragment.blocks[i].type == 'image') {
return fragment.blocks[i];
}
}
}
return null;
},
// Useful for obsolete multiples
getAllImageViews: function(name, view) {
return this.getAllImages(name).map(function (image) {
return image.getView(view);
});
},
/**
* Gets the date fragment in the current Document object, for further manipulation.
*
* @example document.getDate('blog-post.publicationdate').asHtml(ctx)
*
* @param {string} fragment - The name of the fragment to get, with its type; for instance, "blog-post.publicationdate"
* @returns {Date} - The Date object to manipulate
*/
getDate: function(name) {
var fragment = this.get(name);
if(fragment instanceof Global.Prismic.Fragments.Date) {
return fragment.value;
}
},
/**
* Gets a boolean value of the fragment in the current Document object, for further manipulation.
* This works great with a Select fragment. The Select values that are considered true are (lowercased before matching): 'yes', 'on', and 'true'.
*
* @example if(document.getBoolean('blog-post.enableComments')) { ... }
*
* @param {string} fragment - The name of the fragment to get, with its type; for instance, "blog-post.enableComments"
* @returns {boolean} - The boolean value of the fragment
*/
getBoolean: function(name) {
var fragment = this.get(name);
return fragment.value && (fragment.value.toLowerCase() == 'yes' || fragment.value.toLowerCase() == 'on' || fragment.value.toLowerCase() == 'true');
},
/**
* Gets the text fragment in the current Document object, for further manipulation.
* The method works with StructuredText fragments, Text fragments, Number fragments, Select fragments and Color fragments.
*
* @example document.getText('blog-post.label').asHtml(ctx).
*
* @param {string} name - The name of the fragment to get, with its type; for instance, "blog-post.label"
* @param {string} after - a suffix that will be appended to the value
* @returns {object} - either StructuredText, or Text, or Number, or Select, or Color.
*/
getText: function(name, after) {
var fragment = this.get(name);
if (fragment instanceof Global.Prismic.Fragments.StructuredText) {
return fragment.blocks.map(function(block) {
if(block.text) {
return block.text + (after ? after : '');
}
}).join('\n');
}
if (fragment instanceof Global.Prismic.Fragments.Text) {
if(fragment.value) {
return fragment.value + (after ? after : '');
}
}
if (fragment instanceof Global.Prismic.Fragments.Number) {
if(fragment.value) {
return fragment.value + (after ? after : '');
}
}
if (fragment instanceof Global.Prismic.Fragments.Select) {
if(fragment.value) {
return fragment.value + (after ? after : '');
}
}
if (fragment instanceof Global.Prismic.Fragments.Color) {
if(fragment.value) {
return fragment.value + (after ? after : '');
}
}
},
/**
* Gets the StructuredText fragment in the current Document object, for further manipulation.
* @example document.getStructuredText('blog-post.body').asHtml(ctx).
*
* @param {string} fragment - The name of the fragment to get, with its type; for instance, "blog-post.body"
* @returns {StructuredText} - The StructuredText fragment to manipulate.
*/
getStructuredText: function(name) {
var fragment = this.get(name);
if (fragment instanceof Global.Prismic.Fragments.StructuredText) {
return fragment;
}
},
/**
* Gets the Number fragment in the current Document object, for further manipulation.
* @example document.getNumber('product.price')
*
* @param {string} name - The name of the fragment to get, with its type; for instance, "product.price"
* @returns {number} - The number value of the fragment.
*/
getNumber: function(name) {
var fragment = this.get(name);
if (fragment instanceof Global.Prismic.Fragments.Number) {
return fragment.value;
}
},
/**
* Gets the Color fragment in the current Document object, for further manipulation.
* @example document.getColor('product.color')
*
* @param {string} fragment - The name of the fragment to get, with its type; for instance, "product.color"
* @returns {string} - The string value of the Color fragment.
*/
getColor: function(name) {
var fragment = this.get(name);
if (fragment instanceof Global.Prismic.Fragments.Color) {
return fragment.value;
}
},
/** Gets the GeoPoint fragment in the current Document object, for further manipulation.
*
* @example document.getGeoPoint('blog-post.location').asHtml(ctx)
*
* @param {string} name - The name of the fragment to get, with its type; for instance, "blog-post.location"
* @returns {GeoPoint} - The GeoPoint object to manipulate
*/
getGeoPoint: function(name) {
var fragment = this.get(name);
if(fragment instanceof Global.Prismic.Fragments.GeoPoint) {
return fragment;
}
},
/**
* Gets the Group fragment in the current Document object, for further manipulation.
*
* @example document.getGroup('product.gallery').asHtml(ctx).
*
* @param {string} name - The name of the fragment to get, with its type; for instance, "product.gallery"
* @returns {Group} - The Group fragment to manipulate.
*/
getGroup: function(name) {
var fragment = this.get(name);
if (fragment instanceof Global.Prismic.Fragments.Group) {
return fragment;
}
},
/**
* Shortcut to get the HTML output of the fragment in the current document.
* This is the same as writing document.get(fragment).asHtml(ctx);
*
* @param {string} name - The name of the fragment to get, with its type; for instance, "blog-post.body"
* @param {function} ctx - The ctx object that contains the context: ctx.api, ctx.ref, ctx.maybeRef, ctx.oauth(), and ctx.linkResolver()
* @returns {string} - The HTML output
*/
getHtml: function(name, ctx) {
var fragment = this.get(name);
if(fragment && fragment.asHtml) {
return fragment.asHtml(ctx);
}
},
/**
* Transforms the whole document as an HTML output. Each fragment is separated by a &lt;section&gt; tag,
* with the attribute data-field="nameoffragment"
* Note that most of the time you will not use this method, but read fragment independently and generate
* HTML output for {@link StructuredText} fragment with that class' asHtml method.
*
* @param {object} ctx - The ctx object that contains the context: ctx.api, ctx.ref, ctx.maybeRef, ctx.oauth(), and ctx.linkResolver()
* @returns {string} - The HTML output
*/
asHtml: function(ctx) {
var htmls = [];
for(var field in this.fragments) {
var fragment = this.get(field);
htmls.push(fragment && fragment.asHtml ? '<section data-field="' + field + '">' + fragment.asHtml(ctx) + '</section>' : '');
}
return htmls.join('');
},
/**
* Turns the document into a useable text version of it.
*
* @returns {string} - basic text version of the fragment
*/
asText: function(ctx) {
var texts = [];
for(var field in this.fragments) {
var fragment = this.get(field);
texts.push(fragment && fragment.asText ? fragment.asText(ctx) : '');
}
return texts.join('');
}
};
/**
* Embodies a prismic.io ref (a past or future point in time you can query)

@@ -1099,6 +759,6 @@ * @constructor

delete self.states[key];
done && done(error, value, xhr);
if (done) done(error, value, xhr);
});
} else {
done && done(null, found);
if (done) done(null, found);
}

@@ -1110,3 +770,3 @@ },

if(entry) {
return entry.expiredIn != 0 && entry.expiredIn < Date.now();
return entry.expiredIn !== 0 && entry.expiredIn < Date.now();
} else {

@@ -1118,3 +778,3 @@ return false;

isInProgress: function(key) {
return this.states[key] == 'progress';
return this.states[key] === 'progress';
},

@@ -1121,0 +781,0 @@

@@ -500,3 +500,3 @@ (function (Global, undefined) {

asHtml: function () {
return this.main.asHtml()
return this.main.asHtml();
},

@@ -573,31 +573,30 @@

function Group(data) {
this.value = data;
this.value = [];
for (var i = 0; i < data.length; i++) {
this.value.push(new Global.Prismic.GroupDoc(data[i]));
}
}
Group.prototype = {
/**
* Turns the fragment into a useable HTML version of it.
* If the native HTML code doesn't suit your design, this function is meant to be overriden.
* @params {function} linkResolver - linkResolver function (please read prismic.io online documentation about this)
* @returns {string} - basic HTML code for the fragment
*/
asHtml: function(linkResolver) {
var output = "";
for (var i=0; i<this.value.length; i++) {
for (var fragmentName in this.value[i]) {
output += '<section data-field="'+fragmentName+'">';
output += this.value[i][fragmentName].asHtml(linkResolver);
output += '</section>';
}
}
return output;
},
/**
* Turns the Group fragment into an array in order to access its items (groups of fragments),
* or to loop through them.
* @params {object} ctx - mandatory ctx object, with a useable linkResolver function (please read prismic.io online documentation about this)
* @returns {array} - the array of groups, each group being a JSON object with subfragment name as keys, and subfragment as values
*/
toArray: function(){
return this.value;
},
/**
* Turns the fragment into a useable HTML version of it.
* If the native HTML code doesn't suit your design, this function is meant to be overriden.
* @params {function} linkResolver - linkResolver function (please read prismic.io online documentation about this)
* @returns {string} - basic HTML code for the fragment
*/
asHtml: function(linkResolver) {
var output = "";
for (var i = 0; i < this.value.length; i++) {
output += this.value[i].asHtml(linkResolver);
}
return output;
},
/**
* Turns the Group fragment into an array in order to access its items (groups of fragments),
* or to loop through them.
* @params {object} ctx - mandatory ctx object, with a useable linkResolver function (please read prismic.io online documentation about this)
* @returns {array} - the array of groups, each group being a JSON object with subfragment name as keys, and subfragment as values
*/
toArray: function(){
return this.value;
},

@@ -609,11 +608,11 @@ /**

*/
asText: function(linkResolver) {
asText: function(linkResolver) {
var output = "";
for (var i=0; i<this.value.length; i++) {
for (var fragmentName in this.value[i]) {
output += this.value[i][fragmentName].asText(linkResolver);
}
for (var fragmentName in this.value[i]) {
output += this.value[i][fragmentName].asText(linkResolver);
}
}
return output;
}
}
};

@@ -642,3 +641,3 @@

var block = this.blocks[i];
if(block.type.indexOf('heading') == 0) {
if(block.type.indexOf('heading') === 0) {
return block;

@@ -716,3 +715,3 @@ }

return ctx.linkResolver(ctx, doc, isBroken);
}
};
}

@@ -825,3 +824,3 @@ if (Array.isArray(this.blocks)) {

var innerHtml = serialize(tag.span, tag.text, htmlSerializer);
if (stack.length == 0) {
if (stack.length === 0) {
// The tag was top level

@@ -848,3 +847,3 @@ html += innerHtml;

} else {
console && console.error && console.error('Impossible to convert span.data as a Fragment', span);
if (console && console.error) console.error('Impossible to convert span.data as a Fragment', span);
return '';

@@ -863,3 +862,3 @@ }

c = text[pos];
if (stack.length == 0) {
if (stack.length === 0) {
// Top-level text

@@ -965,17 +964,7 @@ html += htmlEscape(c);

case "Group":
var groups_array = [];
// for each array of groups
for (var i = 0; i < field.value.length; i++) {
var group = {}; // recreate groups with...
for (var fragmentName in field.value[i]) {
// ... the same fragment name as keys, but reinitalized fragments as values
group[fragmentName] = initField(field.value[i][fragmentName]);
}
groups_array.push(group);
}
output = new Group(groups_array);
output = new Group(field.value);
break;
default:
console && console.log && console.log("Fragment type not supported: ", field.type);
if (console && console.log) console.log("Fragment type not supported: ", field.type);
break;

@@ -1029,13 +1018,13 @@ }

var imgTag = '<img src="' + element.url + '" alt="' + element.alt + '">';
return '<p class="block-img' + label + '">'
+ (element.linkUrl ? ('<a href="' + element.linkUrl + '">' + imgTag + '</a>') : imgTag)
+ '</p>';
return '<p class="block-img' + label + '">' +
(element.linkUrl ? ('<a href="' + element.linkUrl + '">' + imgTag + '</a>') : imgTag) +
'</p>';
}
if (element.type == "embed") {
return '<div data-oembed="'+ element.embed_url
+ '" data-oembed-type="'+ element.type
+ '" data-oembed-provider="'+ element.provider_name
+ (element.label ? ('" class="' + label) : '')
+ '">' + element.oembed.html+"</div>";
return '<div data-oembed="'+ element.embed_url +
'" data-oembed-type="'+ element.type +
'" data-oembed-provider="'+ element.provider_name +
(element.label ? ('" class="' + element.label) : '') +
'">' + element.oembed.html+"</div>";
}

@@ -1072,4 +1061,4 @@

insertSpans: insertSpans
}
};
}(typeof exports === 'object' && exports ? exports : (typeof module === "object" && module && typeof module.exports === "object" ? module.exports : window)));

@@ -5,58 +5,244 @@ (function (Global, undefined) {

/**
* @global
* @namespace
* @alias Predicates
*/
var predicates = {
/**
* Build an "at" predicate: equality of a fragment to a value.
*
* @example Predicates.at("document.type", "article")
* @param fragment {String}
* @param value {String}
* @returns {Array} an array corresponding to the predicate
*/
at: function(fragment, value) { return ["at", fragment, value]; },
/**
* Build an "any" predicate: equality of a fragment to a value.
*
* @example Predicates.any("document.type", ["article", "blog-post"])
* @param fragment {String}
* @param values {Array}
* @returns {Array} an array corresponding to the predicate
*/
any: function(fragment, values) { return ["any", fragment, values]; },
fulltext: function(fragment, values) { return ["fulltext", fragment, values]; },
/**
* Build a "fulltext" predicate: fulltext search in a fragment.
*
* @example Predicates.fulltext("my.article.body", "sausage"])
* @param fragment {String}
* @param value {String} the term to search
* @returns {Array} an array corresponding to the predicate
*/
fulltext: function(fragment, value) { return ["fulltext", fragment, value]; },
similar: function(fragment, value) { return ["similar", fragment, value]; },
/**
* Build a "similar" predicate.
*
* @example Predicates.similar("UXasdFwe42D", 10)
* @param documentId {String} the document id to retrieve similar documents to.
* @param maxResults {Number} the maximum number of results to return
* @returns {Array} an array corresponding to the predicate
*/
similar: function(documentId, maxResults) { return ["similar", documentId, maxResults]; },
/**
* Build a "number.gt" predicate: documents where the fragment field is greater than the given value.
*
* @example Predicates.gt("my.product.price", 10)
* @param fragment {String} the name of the field - must be a number.
* @param value {Number} the lower bound of the predicate
* @returns {Array} an array corresponding to the predicate
*/
gt: function(fragment, value) { return ["number.gt", fragment, value]; },
/**
* Build a "number.lt" predicate: documents where the fragment field is lower than the given value.
*
* @example Predicates.lt("my.product.price", 20)
* @param fragment {String} the name of the field - must be a number.
* @param value {Number} the upper bound of the predicate
* @returns {Array} an array corresponding to the predicate
*/
lt: function(fragment, value) { return ["number.lt", fragment, value]; },
/**
* Build a "number.inRange" predicate: combination of lt and gt.
*
* @example Predicates.inRange("my.product.price", 10, 20)
* @param fragment {String} the name of the field - must be a number.
* @param before {Number}
* @param after {Number}
* @returns {Array} an array corresponding to the predicate
*/
inRange: function(fragment, before, after) { return ["number.inRange", fragment, before, after]; },
/**
* Build a "date.before" predicate: documents where the fragment field is before the given date.
*
* @example Predicates.dateBefore("my.product.releaseDate", new Date(2014, 6, 1))
* @param fragment {String} the name of the field - must be a date or timestamp field.
* @param before {Date}
* @returns {Array} an array corresponding to the predicate
*/
dateBefore: function(fragment, before) { return ["date.before", fragment, before]; },
/**
* Build a "date.after" predicate: documents where the fragment field is after the given date.
*
* @example Predicates.dateAfter("my.product.releaseDate", new Date(2014, 1, 1))
* @param fragment {String} the name of the field - must be a date or timestamp field.
* @param after {Date}
* @returns {Array} an array corresponding to the predicate
*/
dateAfter: function(fragment, after) { return ["date.after", fragment, after]; },
/**
* Build a "date.between" predicate: combination of dateBefore and dateAfter
*
* @example Predicates.dateBetween("my.product.releaseDate", new Date(2014, 1, 1), new Date(2014, 6, 1))
* @param fragment {String} the name of the field - must be a date or timestamp field.
* @param before {Date}
* @param after {Date}
* @returns {Array} an array corresponding to the predicate
*/
dateBetween: function(fragment, before, after) { return ["date.between", fragment, before, after]; },
/**
*
* @example Predicates.dayOfMonth("my.product.releaseDate", 14)
* @param fragment
* @param day {Number} between 1 and 31
* @returns {Array}
*/
dayOfMonth: function(fragment, day) { return ["date.day-of-month", fragment, day]; },
/**
*
* @example Predicates.dayOfMonthAfter("my.product.releaseDate", 14)
* @param fragment
* @param day {Number} between 1 and 31
* @returns {Array}
*/
dayOfMonthAfter: function(fragment, day) { return ["date.day-of-month-after", fragment, day]; },
/**
*
* @example Predicates.dayOfMonthBefore("my.product.releaseDate", 14)
* @param fragment
* @param day {Number} between 1 and 31
* @returns {Array}
*/
dayOfMonthBefore: function(fragment, day) { return ["date.day-of-month-before", fragment, day]; },
/**
*
* @example Predicates.dayOfWeek("my.product.releaseDate", 14)
* @param fragment
* @param day {Number|String} Number between 1 and 7 or string between "Monday" and "Sunday"
* @returns {Array}
*/
dayOfWeek: function(fragment, day) { return ["date.day-of-week", fragment, day]; },
/**
*
* @example Predicates.dayOfWeekAfter("my.product.releaseDate", "Wednesday")
* @param fragment
* @param day {Number|String} Number between 1 and 7 or string between "Monday" and "Sunday"
* @returns {Array}
*/
dayOfWeekAfter: function(fragment, day) { return ["date.day-of-week-after", fragment, day]; },
/**
*
* @example Predicates.dayOfWeekBefore("my.product.releaseDate", "Wednesday")
* @param fragment
* @param day {Number|String} Number between 1 and 7 or string between "Monday" and "Sunday"
* @returns {Array}
*/
dayOfWeekBefore: function(fragment, day) { return ["date.day-of-week-before", fragment, day]; },
/**
*
* @example Predicates.month("my.product.releaseDate", "June")
* @param fragment
* @param month {Number|String} Number between 1 and 12 or string between "January" and "December"
* @returns {Array}
*/
month: function(fragment, month) { return ["date.month", fragment, month]; },
/**
*
* @example Predicates.monthBefore("my.product.releaseDate", "June")
* @param fragment
* @param month {Number|String} Number between 1 and 12 or string between "January" and "December"
* @returns {Array}
*/
monthBefore: function(fragment, month) { return ["date.month-before", fragment, month]; },
/**
*
* @example Predicates.monthAfter("my.product.releaseDate", "June")
* @param fragment
* @param month {Number|String} Number between 1 and 12 or string between "January" and "December"
* @returns {Array}
* @returns {Array}
*/
monthAfter: function(fragment, month) { return ["date.month-after", fragment, month]; },
/**
*
* @example Predicates.year("my.product.releaseDate", 2014)
* @param fragment
* @param year {Number}
* @returns {Array}
*/
year: function(fragment, year) { return ["date.year", fragment, year]; },
/**
*
* @example Predicates.hour("my.product.releaseDate", 12)
* @param fragment
* @param hour {Number}
* @returns {Array}
*/
hour: function(fragment, hour) { return ["date.hour", fragment, hour]; },
/**
*
* @example Predicates.hourBefore("my.product.releaseDate", 12)
* @param fragment
* @param hour {Number}
* @returns {Array}
*/
hourBefore: function(fragment, hour) { return ["date.hour-before", fragment, hour]; },
/**
*
* @example Predicates.hourAfter("my.product.releaseDate", 12)
* @param fragment
* @param hour {Number}
* @returns {Array}
*/
hourAfter: function(fragment, hour) { return ["date.hour-after", fragment, hour]; },
near: function(fragment, latitude, longitude, radius) { return ["near", fragment, latitude, longitude]; }
/**
*
* @example Predicates.near("my.store.location", 48.8768767, 2.3338802, 10)
* @param fragment
* @param latitude {Number}
* @param longitude {Number}
* @param radius {Number} in kilometers
* @returns {Array}
*/
near: function(fragment, latitude, longitude, radius) { return ["geopoint.near", fragment, latitude, longitude, radius]; }
};
// -- Export Globally
Global.Prismic.Predicates = predicates;
}(typeof exports === 'object' && exports ? exports : (typeof module === "object" && module && typeof module.exports === "object" ? module.exports : window)));

@@ -13,9 +13,2 @@ (function(Prismic) {

function getLinkResolver(ref) {
return function(doc, isBroken) {
if (isBroken) return '#broken';
return "/testing_url/" + doc.id + "/" + doc.slug + (ref ? ('?ref=' + ref) : '');
}
}
module('Prismic.io', {

@@ -31,3 +24,3 @@ setup: function() {}

Prismic.Api(testRepository, function(err, Api) {
if (err) { console.log(err); return; }
if (err) { console.log(err); start(); }
equal(Api.data.refs.length, 1);

@@ -52,3 +45,3 @@ equal(Api.url, testRepository);

Prismic.Api(testRepository, function(err, Api) {
if (err) { console.log(err); return; }
if (err) { console.log(err); start(); }
equal(Object.keys(Api.data.types).length, 6);

@@ -62,3 +55,3 @@ equal(Api.data.tags.length, 4);

Prismic.Api(testRepository, function(err, Api) {
if (err) { console.log(err); return; }
if (err) { console.log(err); start(); }
equal(Api.data.refs.length, 3);

@@ -75,3 +68,3 @@ start();

Prismic.Api(testRepository, function(err, Api) {
if (err) { console.log(err); return; }
if (err) { console.log(err); start(); }
Api.form('everything').ref(Api.master()).submit(function(err, documents) {

@@ -94,3 +87,3 @@ if (err) { console.log(err); return; }

Prismic.Api(microRepository, function(err, Api) {
if (err) { console.log(err); return; }
if (err) { console.log(err); start(); }
Api.form('everything').query('[[:d = any(document.type, ["doc","docchapter"])]]').ref(Api.master()).submit(function(err, response) {

@@ -108,3 +101,3 @@ if (err) { console.log(err); return; }

Prismic.Api(microRepository, function(err, Api) {
if (err) { console.log(err); return; }
if (err) { console.log(err); start(); }
Api.form('everything')

@@ -125,3 +118,3 @@ .query(Predicates.any("document.type", ["doc", "docchapter"]))

Prismic.Api(testRepository, function(err, Api) {
if (err) { console.log(err); return; }
if (err) { console.log(err); start(); }
Api.form('everything').ref(Api.master()).orderings('[my.product.price desc]').submit(function(err, documents) {

@@ -138,3 +131,3 @@ if (err) { console.log(err); return; }

Prismic.Api(testRepository, function(err, Api) {
if (err) { console.log(err); return; }
if (err) { console.log(err); start(); }
Api.form('everything').page(2).ref(Api.master()).submit(function(err, documents) {

@@ -157,3 +150,3 @@ if (err) { console.log(err); return; }

Prismic.Api(testRepository, function(err, Api) {
if (err) { console.log(err); return; }
if (err) { console.log(err); start(); }
Api.form('everything').pageSize(10).ref(Api.master()).submit(function(err, documents) {

@@ -176,3 +169,3 @@ if (err) { console.log(err); return; }

Prismic.Api(testRepository, function(err, Api) {
if (err) { console.log(err); return; }
if (err) { console.log(err); start(); }
Api.form('everything').pageSize(10).page(2).ref(Api.master()).submit(function(err, documents) {

@@ -195,3 +188,3 @@ if (err) { console.log(err); return; }

Prismic.Api(testRepository, function(err, Api) {
if (err) { console.log(err); return; }
if (err) { console.log(err); start(); }
Api.form('everything').ref(Api.master()).query("wrongpredicate").submit(function(err, _) {

@@ -207,3 +200,3 @@ ok(err);

Prismic.Api(testRepository, function(err, Api) {
if (err) { console.log(err); return; }
if (err) { console.log(err); start(); }
Api.form('everything').ref(Api.master()).query(["at", "document.type", "product"]).submit(function(err, documents) {

@@ -219,3 +212,3 @@ if (err) { console.log(err); return; }

Prismic.Api(testRepository, function(err, Api) {
if (err) { console.log(err); return; }
if (err) { console.log(err); start(); }
Api.form('everything').ref(Api.master()).query('[[:d = at(document.type, "youhou")]]').submit(function(err, documents) {

@@ -231,3 +224,3 @@ if (err) { console.log(err); return; }

Prismic.Api(microRepository, function(err, Api) {
if (err) { console.log(err); return; }
if (err) { console.log(err); start(); }
Api.form('everything').ref(Api.master()).query(["at", "document.id", "UrOaNwEAAM2OpbPy"]).submit(function(err, documents) {

@@ -244,3 +237,3 @@ if (err) { console.log(err); return; }

Prismic.Api(testRepository, function(err, Api) {
if (err) { console.log(err); return; }
if (err) { console.log(err); start(); }
Api.form('everything').ref(Api.master()).query(["similar", "U9pjvjQAADAAehbf", 10]).submit(function(err, documents) {

@@ -256,3 +249,3 @@ if (err) { console.log(err); return; }

Prismic.Api(microRepository, function(err, Api) {
if (err) { console.log(err); return; }
if (err) { console.log(err); start(); }
Api.form('everything').ref(Api.master()).query(

@@ -271,3 +264,3 @@ Predicates.at("document.type", "article"),

Prismic.Api(testRepository, function(err, Api) {
if (err) { console.log(err); return; }
if (err) { console.log(err); start(); }
Api.form('products').ref(Api.master()).submit(function(err, documents) {

@@ -283,3 +276,3 @@ if (err) { console.log(err); return; }

Prismic.Api(testRepository, function(err, Api) {
if (err) { console.log(err); return; }
if (err) { console.log(err); start(); }
Api.form('products').ref(Api.master()).query('[[:d = at(my.product.flavour, "Chocolate")]]').submit(function(err, documents) {

@@ -295,3 +288,3 @@ if (err) { console.log(err); return; }

Prismic.Api(testRepository, function(err, Api) {
if (err) { console.log(err); return; }
if (err) { console.log(err); start(); }
Api.form('products').ref(Api.master()).query('').submit(function(err, documents) {

@@ -307,3 +300,3 @@ if (err) { console.log(err); return; }

Prismic.Api(testRepository, function(err, Api) {
if (err) { console.log(err); return; }
if (err) { console.log(err); start(); }
Api.form('products').ref(Api.ref('Announcement of new SF shop')).submit(function(err, documents) {

@@ -317,352 +310,2 @@ if (err) { console.log(err); return; }

/*************************/
/* Document manipulation */
/*************************/
asyncTest('Stores and retrieves all document slugs well', 1, function() {
Prismic.Api(testRepository, function(err, Api) {
if (err) { console.log(err); return; }
Api.form('everything').query('[[:d = at(document.id, "UlfoxUnM0wkXYXbg")]]').ref(Api.master()).submit(function(err, documents) {
if (err) { console.log(err); return; }
var doc = documents.results[0];
equal(doc.slugs.length, 2);
start();
});
});
});
asyncTest('Render a document to Html', 1, function() {
Prismic.Api(testRepository, function(err, Api) {
if (err) { console.log(err); return; }
Api.form('everything').ref(Api.master()).submit(function(err, documents) {
if (err) { console.log(err); return; }
var first = documents.results[0];
notEqual(null, first);
first.asHtml(getLinkResolver());
start();
});
});
});
asyncTest('Render a document to Text', 1, function() {
Prismic.Api(testRepository, function(err, Api) {
if (err) { console.log(err); return; }
Api.form('everything').query('[[:d = at(document.id, "UlfoxUnM0wkXYXbX")]]').ref(Api.master()).submit(function(err, documents) {
if (err) { console.log(err); return; }
function fix(s) {
// remove dates and timezone
return s.replace(/[A-Z][a-z]{2,4} [A-Z][a-z]{2,4} \d{2} \d{4} \d{2}:\d{2}:\d{2} GMT[+-]\d{4} \([^)]+\)/g, '<DATE>');
}
equal(fix(documents.results[0].asText(getLinkResolver('XXXXX'))), fix("Get the right approach to ganache A lot of people touch base with us to know about one of our key ingredients, and the essential role it plays in our creations: ganache. Indeed, ganache is the macaron's softener, or else, macarons would be but tough biscuits; it is the cupcake's wrapper, or else, cupcakes would be but plain old cake. We even sometimes use ganache within our cupcakes, to soften the cake itself, or as a support to our pies' content. How to approach ganache Apart from the taste balance, which is always a challenge when it comes to pastry, the tough part about ganache is about thickness. It is even harder to predict through all the phases the ganache gets to meet (how long will it get melted? how long will it remain in the fridge?). Things get a hell of a lot easier to get once you consider that there are two main ways to get the perfect ganache: working from the top down: start with a thick, almost hard material, and soften it by manipulating it, or by mixing it with a more liquid ingredient (like milk) working from the bottom up: start from a liquid-ish state, and harden it by miwing it with thicker ingredients, or by leaving it in the fridge longer. We do hope this advice will empower you in your ganache-making skills. Let us know how you did with it! Ganache at Les Bonnes Choses We have a saying at Les Bonnes Choses: \"Once you can make ganache, you can make anything.\" 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. 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. About the chocolate in our ganache 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.Ganache is a tricky topic, but here's some guidance.Tue Jul 23 2013 17:00:00 GMT-0700 (PDT)Steve Adams, Ganache SpecialistDo it yourselfYes/testing_url/UlfoxUnM0wkXYXbj/triple-chocolate-cupcake?ref=XXXXX/testing_url/UlfoxUnM0wkXYXbm/tips-to-dress-a-pastry?ref=XXXXX"));
start();
});
});
});
asyncTest('StructuredTexts asHtml handles embeds and lists', 1, function() {
Prismic.Api(testRepository, function(err, Api) {
if (err) { console.log(err); return; }
Api.form('everything').query('[[:d = at(document.id, "UlfoxUnM0wkXYXbX")]]').ref(Api.master()).submit(function(err, documents) {
if (err) { console.log(err); return; }
equal(documents.results[0].getStructuredText('blog-post.body').asHtml(), '<h1>Get the right approach to ganache</h1><p>A lot of people touch base with us to know about one of our key ingredients, and the essential role it plays in our creations: ganache.</p><p>Indeed, ganache is the macaron\'s softener, or else, macarons would be but tough biscuits; it is the cupcake\'s wrapper, or else, cupcakes would be but plain old cake. We even sometimes use ganache within our cupcakes, to soften the cake itself, or as a support to our pies\' content.</p><h2>How to approach ganache</h2><p class=\"block-img\"><img src=\"https://prismic-io.s3.amazonaws.com/lesbonneschoses/ee7b984b98db4516aba2eabd54ab498293913c6c.jpg\" alt=\"\"></p><p>Apart from the taste balance, which is always a challenge when it comes to pastry, the tough part about ganache is about thickness. It is even harder to predict through all the phases the ganache gets to meet (how long will it get melted? how long will it remain in the fridge?). Things get a hell of a lot easier to get once you consider that there are two main ways to get the perfect ganache:</p><ul><li><strong>working from the top down</strong>: start with a thick, almost hard material, and soften it by manipulating it, or by mixing it with a more liquid ingredient (like milk)</li><li><strong>working from the bottom up</strong>: start from a liquid-ish state, and harden it by miwing it with thicker ingredients, or by leaving it in the fridge longer.</li></ul><p>We do hope this advice will empower you in your ganache-making skills. Let us know how you did with it!</p><h2>Ganache at <em>Les Bonnes Choses</em></h2><p>We have a saying at Les Bonnes Choses: \"Once you can make ganache, you can make anything.\"</p><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. 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><h2>About the chocolate in our ganache</h2><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><div data-oembed=\"undefined\" data-oembed-type=\"embed\" data-oembed-provider=\"undefined\"><iframe width=\"459\" height=\"344\" src=\"http://www.youtube.com/embed/Ye78F3-CuXY?feature=oembed\" frameborder=\"0\" allowfullscreen></iframe></div>');
start();
});
}, previewToken);
});
asyncTest('StructuredTexts asText works', 1, function() {
Prismic.Api(testRepository, function(err, Api) {
if (err) { console.log(err); return; }
Api.form('everything').query('[[:d = at(document.id, "UlfoxUnM0wkXYXbX")]]').ref(Api.master()).submit(function(err, documents) {
if (err) { console.log(err); return; }
equal(documents.results[0].getStructuredText('blog-post.body').asText(), "Get the right approach to ganache A lot of people touch base with us to know about one of our key ingredients, and the essential role it plays in our creations: ganache. Indeed, ganache is the macaron's softener, or else, macarons would be but tough biscuits; it is the cupcake's wrapper, or else, cupcakes would be but plain old cake. We even sometimes use ganache within our cupcakes, to soften the cake itself, or as a support to our pies' content. How to approach ganache Apart from the taste balance, which is always a challenge when it comes to pastry, the tough part about ganache is about thickness. It is even harder to predict through all the phases the ganache gets to meet (how long will it get melted? how long will it remain in the fridge?). Things get a hell of a lot easier to get once you consider that there are two main ways to get the perfect ganache: working from the top down: start with a thick, almost hard material, and soften it by manipulating it, or by mixing it with a more liquid ingredient (like milk) working from the bottom up: start from a liquid-ish state, and harden it by miwing it with thicker ingredients, or by leaving it in the fridge longer. We do hope this advice will empower you in your ganache-making skills. Let us know how you did with it! Ganache at Les Bonnes Choses We have a saying at Les Bonnes Choses: \"Once you can make ganache, you can make anything.\" 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. 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. About the chocolate in our ganache 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.");
start();
});
}, previewToken);
});
asyncTest('StructuredTexts asHtml handles preformatted', 1, function() {
Prismic.Api(microRepository, function(err, Api) {
if (err) { console.log(err); return; }
Api.form('everything').query('[[:d = at(document.id, "UrDejAEAAFwMyrW9")]]').ref(Api.master()).submit(function(err, documents) {
if (err) { console.log(err); return; }
equal(
documents.results[0].getStructuredText('doc.content').asHtml(getLinkResolver()),
'<p>Meta-micro gets installed pretty much like any javascript library:</p><ol><li><a href=\"/testing_url/U0w8OwEAACoAQEvB/download-meta-micro\">download</a> the .js file: get the minified one, unless the framework you\'re using minifies your .js files automatically.</li><li>add a link towards the file in your webpage\'s head.</li></ol><p>The link might look like this, anywhere inside your head tag:</p><pre>&lt;script type=\"text/javascript\" src=\"meta-micro.min.js\"&gt;&lt;/script&gt;</pre><p>You\'re all set!</p>');
start();
});
});
});
asyncTest('Test backward-compatibility with passing a ctx instead of just a linkResolver', 1, function() {
Prismic.Api(microRepository, function(err, Api) {
if (err) { console.log(err); return; }
Api.form('everything').query('[[:d = at(document.id, "UrDejAEAAFwMyrW9")]]').ref(Api.master()).submit(function(err, documents) {
if (err) { console.log(err); return; }
equal(
documents.results[0].getStructuredText('doc.content').asHtml({
api: undefined,
ref: { ref: 'XXXXX', label: 'Future release', isMaster: false },
maybeRef: 'XXXXX',
oauth: function() { },
linkResolver: function(ctx, doc, isBroken) {
if (isBroken) return '#broken';
return "/testing_url/"+doc.id+"/"+doc.slug+( ctx.maybeRef ? '?ref=' + ctx.maybeRef : '' );
}
}),
'<p>Meta-micro gets installed pretty much like any javascript library:</p><ol><li><a href=\"/testing_url/U0w8OwEAACoAQEvB/download-meta-micro?ref=XXXXX\">download</a> the .js file: get the minified one, unless the framework you\'re using minifies your .js files automatically.</li><li>add a link towards the file in your webpage\'s head.</li></ol><p>The link might look like this, anywhere inside your head tag:</p><pre>&lt;script type=\"text/javascript\" src=\"meta-micro.min.js\"&gt;&lt;/script&gt;</pre><p>You\'re all set!</p>');
start();
});
});
});
asyncTest('StructuredTexts asHtml handles spans', 1, function() {
Prismic.Api(testRepository, function(err, Api) {
if (err) { console.log(err); return; }
Api.form('everything').query('[[:d = at(document.id, "UlfoxUnM0wkXYXbt")]]').ref(Api.master()).submit(function(err, documents) {
if (err) { console.log(err); return; }
equal(documents.results[0].getStructuredText('blog-post.body').asHtml(), '<h1>The end of a chapter the beginning of a new one</h1><p class="block-img"><img src="https://prismic-io.s3.amazonaws.com/lesbonneschoses/8181933ff2f5032daff7d732e33a3beb6f57e09f.jpg" alt=\"\"></p><p>Jean-Michel Pastranova, the founder of <em>Les Bonnes Choses</em>, and creator of the whole concept of modern fine pastry, has decided to step down as the CEO and the Director of Workshops of <em>Les Bonnes Choses</em>, to focus on other projects, among which his now best-selling pastry cook books, but also to take on a primary role in a culinary television show to be announced later this year.</p><p>"I believe I\'ve taken the <em>Les Bonnes Choses</em> concept as far as it can go. <em>Les Bonnes Choses</em> is already an entity that is driven by its people, thanks to a strong internal culture, so I don\'t feel like they need me as much as they used to. I\'m sure they are greater ways to come, to innovate in pastry, and I\'m sure <em>Les Bonnes Choses</em>\'s coming innovation will be even more mind-blowing than if I had stayed longer."</p><p>He will remain as a senior advisor to the board, and to the workshop artists, as his daughter Selena, who has been working with him for several years, will fulfill the CEO role from now on.</p><p>"My father was able not only to create a revolutionary concept, but also a company culture that puts everyone in charge of driving the company\'s innovation and quality. That gives us years, maybe decades of revolutionary ideas to come, and there\'s still a long, wonderful path to walk in the fine pastry world."</p>');
start();
});
}, previewToken);
});
asyncTest('StructuredTexts asHtml handles span Link.web', 1, function() {
Prismic.Api(testRepository, function(err, Api) {
if (err) { console.log(err); return; }
Api.form('everything').query('[[:d = at(document.id, "UlfoxUnM0wkXYXbW")]]').ref(Api.master()).submit(function(err, documents) {
if (err) { console.log(err); return; }
equal(documents.results[0].getStructuredText('job-offer.profile').asHtml(), '<p>As a company whose marketing is very content-centric, we expect our Content Director to have a tremendous experience, both in content strategy, and in content writing. We expect our applicants to show off some of the content strategies they set up themselves, explaining their choices, and to provide amazing contents they personally wrote.</p><p>Our contents get flexibly powerfully shared on various supports: our site, our in-store printed magazine, our mobile apps, our mailings ... Our Content Director must have experience with all of those, and with using modern adaptive content managers such as <a href=\"http://prismic.io\">prismic.io</a>.</p>');
start();
});
}, previewToken);
});
asyncTest('StructuredTexts asHtml handles span Link.document', 1, function() {
Prismic.Api(testRepository, function(err, Api) {
if (err) { console.log(err); return; }
Api.form('everything').query('[[:d = at(document.id, "UlfoxUnM0wkXYXbl")]]').ref(Api.master()).submit(function(err, documents) {
if (err) { console.log(err); return; }
equal(documents.results[0].getStructuredText('blog-post.body').asHtml(getLinkResolver('XXXXX')), '<h1>Our world-famous Pastry Art Brainstorm event</h1><p class=\"block-img\"><img src=\"https://prismic-io.s3.amazonaws.com/lesbonneschoses/c38f9e5a1a6c43aa7aae516c154013a2cee2bc75.jpg\" alt=\"\"></p><p>Each year, <em>Les Bonnes Choses</em> organizes a world-famous two-day event called the \"Pastry Art Brainstorm\", and which is the perfect excuse for every fine pastry artist in the world to exercise their art, and build their skills up. The event is a multiple win-win operation, at many levels: see what the event is, as seen by many point of views.</p><h2>As seen by the top pastry artists worldwide</h2><p>The event always starts with half a day of conference talks, given by the most insightful pastry artists in the world, selected for having made tremendous achievements in pastry that year. The list of invited guest speakers is decided jointly by the <em>Les Bonnes Choses</em> staff and the Fine Pastry Magazine editors.</p><p>This is great for the speakers, who get an occasion to share their work, and have people build up on it with them.</p><h2>As seen by the pastry professionals</h2><p>After half a day of thoughtful conference, the professionals will get to put what they learned to good use, and mingle with the best artists worldwide to make the most daring pastries together. There are no set rules about who does what during this giant innovation workshop, and many crazy ideas get created out of thin air. As a virtually infinite amount of ingredients is provided by the <em>Les Bonnes Choses</em> staff, many unexpected pastries happen on that day, and professionals taste each other\'s creations, and provide relevant feedback to each other. Most pieces get showcased to the amateur audience as well, who get invited to taste some of the pieces.</p><p>At noon on the second day, teams are expected to subscribe to our Pastry Art Challenge, during which they will make the best possible pastry, judged on many aspects (originality, taste, looks, ...) by a jury of amateurs and professionals. The team members of the three winning pieces share a substantial prize, and their pastries may even join the Les Bonnes Choses catalogue, and be offered in all the <em>Les Bonnes Choses</em> shops worldwide!</p><h2>As seen by the pastry amateurs</h2><p>The conference is limited with a reasonable fee; but the showcase is open to everyone, although visitors are often expected to pay the pastry chefs for the pastries they taste. The educated amateurs spend their day tasting the most daring pieces, giving some appreciated feedback to their chefs, and challenging their own tastebuds. The novice amateurs usually get a once-in-a-lifetime experience, and often mention being blown away by how rich the fine pastry art can be. All in all, every one goes home with a smile on their faces!</p><h2>As seen by the Les Bonnes Choses interns</h2><p>Every year, we recruit a very limited amount of interns, who get aboard a <a href=\"/testing_url/UlfoxUnM0wkXYXbu/les-bonnes-chosess-internship-a-testimony?ref=XXXXX\">life-defining adventure around fine pastries</a>, discovering <em>Les Bonnes Choses</em> during half a year, with part of this time spent in one of our shops abroad. We always manage to get them on board at a time when we know they will be able to attend a Fine Pastry Brainstorm, because we consider it is a very defining element in the experience of being part of <em>Les Bonnes Choses</em>.</p><p>Not only do we invite them to the event (whatever the country they are stationed in when the event happens), but we give them a front-row seat! They are part of the jury for the Fine Pastry Challenge, they are introduced to every speaker as the next generation of pastry (thus having the occasion to learn even more, directly from them).</p><h2>As seen by fine pastry as a field</h2><p>There wasn\'t really an international occasion for pastry artists to join and share, before <em>Les Bonnes Choses</em> came up with the first Fine Pastry Brainstorm, in 2006. Fine Pastry Magazine\'s first edition was out in 2004, and initiated the idea that pastry art needed to be shared better between professionals. But a proper event to meet up in person was missing, and <em>Les Bonnes Choses</em> is proud to be the one to have come up with it first.</p><p>Since then, more local initiatives have been started (notably in Argentina, and Canada), but none comes close to the size of <em>Les Bonnes Choses</em>\'s international Fine Pastry Brainstorm.</p><h2>As seen by <em>Les Bonnes Choses</em></h2><p>As the almost only sponsor of every edition of the event, <em>Les Bonnes Choses</em> makes sure enough ingredients are available for everyone, rents the premises, makes sure the speakers are as comfortable as possible, and takes care of the whole organization! But through the operation, <em>Les Bonnes Choses</em> gains much more than any sponsoring can buy: not only does it get to secure <em>Les Bonnes Choses</em> as the world reference in pastry arts, but it also allows them to claim rightfully that they do offer in their shops the best pastries, created by the world top artists indeed.</p>');
start();
});
}, previewToken);
});
test('HTML content (2 spans on the same text - one bigger 1)', 1, function() {
var text = 'abcdefghijklmnopqrstuvwxyz';
var spans = [{
"type": "em",
"start": 2,
"end": 6
}, {
"type": "strong",
"start": 2,
"end": 4
}];
var html = Prismic.Fragments.insertSpans(text, spans, {});
equal(html, 'ab<em><strong>cd</strong>ef</em>ghijklmnopqrstuvwxyz');
});
test('HTML content (2 spans on the same text - one bigger 2)', 1, function() {
var text = 'abcdefghijklmnopqrstuvwxyz';
var spans = [{
"type": "em",
"start": 2,
"end": 4
}, {
"type": "strong",
"start": 2,
"end": 6
}];
var html = Prismic.Fragments.insertSpans(text, spans, {});
equal(html, 'ab<strong><em>cd</em>ef</strong>ghijklmnopqrstuvwxyz');
});
test("HTML content with span labels", 1, function() {
var text = 'abcdefghijklmnopqrstuvwxyz';
var spans = [{
"type": "label",
"start": 2,
"end": 6,
"data": {
"label": "tip"
}
}];
var html = Prismic.Fragments.insertSpans(text, spans, {});
equal(html, 'ab<span class="tip">cdef</span>ghijklmnopqrstuvwxyz');
});
asyncTest('StructuredTexts asHtml with custom serializer', 1, function() {
Prismic.Api(testRepository, function(err, Api) {
if (err) { console.log(err); return; }
Api.form('everything').query('[[:d = at(document.id, "UlfoxUnM0wkXYXbl")]]').ref(Api.master()).submit(function(err, documents) {
if (err) { console.log(err); return; }
var htmlSerializer = function (element, content) {
if (element.type == "image") {
return '<img src="' + element.url + '" alt="' + element.alt + '">';
}
if (element.type == "hyperlink") {
return '<a class="some-link" href="' + element.url + '">' + content + '</a>';
}
return null;
};
equal(documents.results[0].getStructuredText('blog-post.body').asHtml(getLinkResolver(), htmlSerializer),
'<h1>Our world-famous Pastry Art Brainstorm event</h1>' +
'<img src=\"https://prismic-io.s3.amazonaws.com/lesbonneschoses/c38f9e5a1a6c43aa7aae516c154013a2cee2bc75.jpg\" alt=\"\">' +
'<p>Each year, <em>Les Bonnes Choses</em> organizes a world-famous two-day event called the \"Pastry Art Brainstorm\", and which is the perfect excuse for every fine pastry artist in the world to exercise their art, and build their skills up. The event is a multiple win-win operation, at many levels: see what the event is, as seen by many point of views.</p>' +
'<h2>As seen by the top pastry artists worldwide</h2>' +
'<p>The event always starts with half a day of conference talks, given by the most insightful pastry artists in the world, selected for having made tremendous achievements in pastry that year. The list of invited guest speakers is decided jointly by the <em>Les Bonnes Choses</em> staff and the Fine Pastry Magazine editors.</p>' +
'<p>This is great for the speakers, who get an occasion to share their work, and have people build up on it with them.</p>' +
'<h2>As seen by the pastry professionals</h2>' +
'<p>After half a day of thoughtful conference, the professionals will get to put what they learned to good use, and mingle with the best artists worldwide to make the most daring pastries together. There are no set rules about who does what during this giant innovation workshop, and many crazy ideas get created out of thin air. As a virtually infinite amount of ingredients is provided by the <em>Les Bonnes Choses</em> staff, many unexpected pastries happen on that day, and professionals taste each other\'s creations, and provide relevant feedback to each other. Most pieces get showcased to the amateur audience as well, who get invited to taste some of the pieces.</p>' +
'<p>At noon on the second day, teams are expected to subscribe to our Pastry Art Challenge, during which they will make the best possible pastry, judged on many aspects (originality, taste, looks, ...) by a jury of amateurs and professionals. The team members of the three winning pieces share a substantial prize, and their pastries may even join the Les Bonnes Choses catalogue, and be offered in all the <em>Les Bonnes Choses</em> shops worldwide!</p>' +
'<h2>As seen by the pastry amateurs</h2>' +
'<p>The conference is limited with a reasonable fee; but the showcase is open to everyone, although visitors are often expected to pay the pastry chefs for the pastries they taste. The educated amateurs spend their day tasting the most daring pieces, giving some appreciated feedback to their chefs, and challenging their own tastebuds. The novice amateurs usually get a once-in-a-lifetime experience, and often mention being blown away by how rich the fine pastry art can be. All in all, every one goes home with a smile on their faces!</p>' +
'<h2>As seen by the Les Bonnes Choses interns</h2>' +
'<p>Every year, we recruit a very limited amount of interns, who get aboard a <a class="some-link" href=\"/testing_url/UlfoxUnM0wkXYXbu/les-bonnes-chosess-internship-a-testimony\">life-defining adventure around fine pastries</a>, discovering <em>Les Bonnes Choses</em> during half a year, with part of this time spent in one of our shops abroad. We always manage to get them on board at a time when we know they will be able to attend a Fine Pastry Brainstorm, because we consider it is a very defining element in the experience of being part of <em>Les Bonnes Choses</em>.</p>' +
'<p>Not only do we invite them to the event (whatever the country they are stationed in when the event happens), but we give them a front-row seat! They are part of the jury for the Fine Pastry Challenge, they are introduced to every speaker as the next generation of pastry (thus having the occasion to learn even more, directly from them).</p>' +
'<h2>As seen by fine pastry as a field</h2>' +
'<p>There wasn\'t really an international occasion for pastry artists to join and share, before <em>Les Bonnes Choses</em> came up with the first Fine Pastry Brainstorm, in 2006. Fine Pastry Magazine\'s first edition was out in 2004, and initiated the idea that pastry art needed to be shared better between professionals. But a proper event to meet up in person was missing, and <em>Les Bonnes Choses</em> is proud to be the one to have come up with it first.</p>' +
'<p>Since then, more local initiatives have been started (notably in Argentina, and Canada), but none comes close to the size of <em>Les Bonnes Choses</em>\'s international Fine Pastry Brainstorm.</p>' +
'<h2>As seen by <em>Les Bonnes Choses</em></h2>' +
'<p>As the almost only sponsor of every edition of the event, <em>Les Bonnes Choses</em> makes sure enough ingredients are available for everyone, rents the premises, makes sure the speakers are as comfortable as possible, and takes care of the whole organization! But through the operation, <em>Les Bonnes Choses</em> gains much more than any sponsoring can buy: not only does it get to secure <em>Les Bonnes Choses</em> as the world reference in pastry arts, but it also allows them to claim rightfully that they do offer in their shops the best pastries, created by the world top artists indeed.</p>');
start();
});
}, previewToken);
});
asyncTest('StructuredTexts getFirstImage works', 5, function() {
Prismic.Api(testRepository, function(err, Api) {
if (err) { console.log(err); return; }
Api.form('everything').query('[[:d = at(document.id, "UlfoxUnM0wkXYXbl")]]').ref(Api.master()).submit(function(err, documents) {
if (err) { console.log(err); return; }
equal(documents.results[0].getStructuredText('blog-post.body').getFirstImage().url, "https://prismic-io.s3.amazonaws.com/lesbonneschoses/c38f9e5a1a6c43aa7aae516c154013a2cee2bc75.jpg");
equal(documents.results[0].getStructuredText('blog-post.body').getFirstImage().alt, "");
equal(documents.results[0].getStructuredText('blog-post.body').getFirstImage().height, 427);
equal(documents.results[0].getStructuredText('blog-post.body').getFirstImage().width, 640);
equal(documents.results[0].getStructuredText('blog-post.body').getFirstImage().asHtml(), '<img src=https://prismic-io.s3.amazonaws.com/lesbonneschoses/c38f9e5a1a6c43aa7aae516c154013a2cee2bc75.jpg width=640 height=427 alt="">');
start();
});
}, previewToken);
});
asyncTest('StructuredTexts asHtml handles span Link.file', 1, function() {
var jsonString = '{"type":"StructuredText","value":[{"type":"paragraph","text":"2012 Annual Report","spans":[{"start":0,"end":18,"type":"hyperlink","data":{"type":"Link.file","value":{"file":{"name":"2012_annual.report.pdf","kind":"document","url":"https://prismic-io.s3.amazonaws.com/annual.report.pdf","size":"1282484"}}}}]},{"type":"paragraph","text":"2012 Annual Budget","spans":[{"start":0,"end":18,"type":"hyperlink","data":{"type":"Link.file","value":{"file":{"name":"2012_smec.annual.budget.pdf","kind":"document","url":"https://prismic-io.s3.amazonaws.com/annual.budget.pdf","size":"59229"}}}}]},{"type":"paragraph","text":"2015 Vision & Strategic Plan","spans":[{"start":0,"end":28,"type":"hyperlink","data":{"type":"Link.file","value":{"file":{"name":"2015_vision.strategic.plan_.sm_.pdf","kind":"document","url":"https://prismic-io.s3.amazonaws.com/vision.strategic.plan_.sm_.pdf","size":"1969956"}}}}]}]}';
var jsonObject = JSON.parse(jsonString);
equal(Prismic.Fragments.initField(jsonObject).asHtml(), '<p><a href=\"https://prismic-io.s3.amazonaws.com/annual.report.pdf\">2012 Annual Report</a></p><p><a href=\"https://prismic-io.s3.amazonaws.com/annual.budget.pdf\">2012 Annual Budget</a></p><p><a href=\"https://prismic-io.s3.amazonaws.com/vision.strategic.plan_.sm_.pdf\">2015 Vision &amp; Strategic Plan</a></p>');
start();
});
asyncTest('Proper escaping in asHtml', 1, function() {
var jsonString = "{ \"type\": \"StructuredText\", \"value\": [ { \"type\": \"paragraph\", \"text\": \"<not a real tag>\", \"spans\": [] } ]}";
var jsonObject = JSON.parse(jsonString);
var text = Prismic.Fragments.initField(jsonObject);
equal(
text.asHtml(),
"<p>&lt;not a real tag&gt;</p>"
);
start();
});
asyncTest('Handles multiple fields', 1, function() {
Prismic.Api(testRepository, function(err, Api) {
if (err) { console.log(err); return; }
Api.form('everything').query('[[:d = at(document.id, "UlfoxUnM0wkXYXbX")]]').ref(Api.master()).submit(function(err, documents) {
if (err) { console.log(err); return; }
equal(documents.results[0].getAll('blog-post.relatedpost')[0].asHtml(getLinkResolver()), '<a href="/testing_url/UlfoxUnM0wkXYXbm/tips-to-dress-a-pastry">/testing_url/UlfoxUnM0wkXYXbm/tips-to-dress-a-pastry</a>');
start();
});
}, previewToken);
});
test('Dates are well retrieved', function() {
var timestampHtml = Prismic.Fragments.initField({"type" : "Date", "value" : "2014-04-01"}).asHtml();
equal(
(new RegExp('<time>... ... \\d\\d 2014 \\d\\d:00:00 GMT[-+]\\d\\d00 \\(.+\\)</time>')).test(timestampHtml),
true
);
});
test('Timestamps are well retrieved', function() {
var timestampHtml = Prismic.Fragments.initField({"type" : "Timestamp", "value" : "2014-06-18T15:30:00+0000"}).asHtml();
equal(
(new RegExp('<time>... ... \\d\\d 2014 \\d\\d:30:00 GMT[-+]\\d\\d00 \\(.+\\)</time>')).test(timestampHtml),
true,
timestampHtml
);
});
test('Link in images are parsed', function() {
var jsonString = '{ "type": "StructuredText", "value": [ { "spans": [], "text": "Here is some introductory text.", "type": "paragraph" }, { "spans": [], "text": "The following image is linked.", "type": "paragraph" }, { "alt": "", "copyright": "", "dimensions": { "height": 129, "width": 260 }, "linkTo": { "type": "Link.web", "value": { "url": "http://google.com/" } }, "type": "image", "url": "http://fpoimg.com/129x260" }, { "spans": [ { "end": 20, "start": 0, "type": "strong" } ], "text": "More important stuff", "type": "paragraph" }, { "spans": [], "text": "The next is linked to a valid document:", "type": "paragraph" }, { "alt": "", "copyright": "", "dimensions": { "height": 400, "width": 400 }, "linkTo": { "type": "Link.document", "value": { "document": { "id": "UxCQFFFFFFFaaYAH", "slug": "something-fantastic", "type": "lovely-thing" }, "isBroken": false } }, "type": "image", "url": "http://fpoimg.com/400x400" }, { "spans": [], "text": "The next is linked to a broken document:", "type": "paragraph" }, { "alt": "", "copyright": "", "dimensions": { "height": 250, "width": 250 }, "linkTo": { "type": "Link.document", "value": { "document": { "id": "UxERPAEAAHQcsBUH", "slug": "-", "type": "event-calendar" }, "isBroken": true } }, "type": "image", "url": "http://fpoimg.com/250x250" }, { "spans": [], "text": "One more image, this one is not linked:", "type": "paragraph" }, { "alt": "", "copyright": "", "dimensions": { "height": 199, "width": 300 }, "type": "image", "url": "http://fpoimg.com/199x300" } ] }';
var jsonObject = JSON.parse(jsonString);
var text = Prismic.Fragments.initField(jsonObject);
equal(text.asHtml(getLinkResolver()), '<p>Here is some introductory text.</p><p>The following image is linked.</p><p class=\"block-img\"><a href=\"http://google.com/\"><img src=\"http://fpoimg.com/129x260\" alt=\"\"></a></p><p><strong>More important stuff</strong></p><p>The next is linked to a valid document:</p><p class=\"block-img\"><a href=\"/testing_url/UxCQFFFFFFFaaYAH/something-fantastic\"><img src=\"http://fpoimg.com/400x400\" alt=\"\"></a></p><p>The next is linked to a broken document:</p><p class=\"block-img\"><a href=\"#broken\"><img src=\"http://fpoimg.com/250x250\" alt=\"\"></a></p><p>One more image, this one is not linked:</p><p class=\"block-img\"><img src=\"http://fpoimg.com/199x300\" alt=\"\"></p>');
});
test('List items are correctly grouped', function() {
var jsonString = '{ "type":"StructuredText", "value":[ { "spans":[], "text":"Here is some introductory text.", "type":"paragraph" }, { "spans":[], "text":"first item", "type":"list-item" }, { "spans":[], "text":"second item", "type":"list-item" }, { "spans":[], "text":"The following image is linked.", "type":"paragraph" }, { "spans":[], "text":"first item 2", "type":"list-item" }, { "spans":[], "text":"second item 2", "type":"list-item" } ] }';
var jsonObject = JSON.parse(jsonString);
var text = Prismic.Fragments.initField(jsonObject);
equal(text.asHtml(getLinkResolver()), '<p>Here is some introductory text.</p><ul><li>first item</li><li>second item</li></ul><p>The following image is linked.</p><ul><li>first item 2</li><li>second item 2</li></ul>');
});
asyncTest('ImageViews are well retrieved', 2, function() {
Prismic.Api(testRepository, function(err, Api) {
if (err) { console.log(err); return; }
Api.form('everything').query('[[:d = at(document.id, "UlfoxUnM0wkXYXbO")]]').ref(Api.master()).submit(function(err, documents) {
if (err) { console.log(err); return; }
equal(documents.results[0].getImageView('product.image', 'main').asHtml(), '<img src=https://prismic-io.s3.amazonaws.com/lesbonneschoses/f606ad513fcc2a73b909817119b84d6fd0d61a6d.png width=500 height=500 alt="">');
equal(documents.results[0].getImageView('product.image', 'icon').asHtml(), '<img src=https://prismic-io.s3.amazonaws.com/lesbonneschoses/fe4f9379ee325456992d48204b8d94aeb60cc976.png width=250 height=250 alt="">');
start();
});
}, previewToken);
});
asyncTest('GeoPoint is retrieved', 1, function() {
Prismic.Api(microRepository, function(err, Api) {
if (err) { console.log(err); return; }
Api.form('everything').query('[[:d = at(document.id, "U9pjvjQAADAAehbf")]]').ref(Api.master()).submit(function(err, documents) {
if (err) { console.log(err); return; }
var html = '<div class="geopoint"><span class="latitude">48.87687670000001</span><span class="longitude">2.3338801999999825</span></div>';
equal(documents.results[0].getGeoPoint('contributor.location').asHtml(), html);
start();
});
});
});
asyncTest('Block fragments are accessible, loopable, and serializable', 4, function() {
Prismic.Api(microRepository, function(err, Api) {
if (err) { console.log(err); return; }
Api.form('everything').query('[[:d = at(document.id, "UrDndQEAALQMyrXF")]]').ref(Api.master()).submit(function(err, documents) {
if (err) { console.log(err); return; }
// Group fragments are accessible
equal(documents.results[0].getGroup('docchapter.docs').toArray()[0]['linktodoc'].value.document.type, 'doc');
// Group fragments are loopable
var slugs = "";
for (var i = 0; i<documents.results[0].getGroup('docchapter.docs').toArray().length; i++) {
slugs += documents.results[0].getGroup('docchapter.docs').toArray()[i]['linktodoc'].value.document.slug + ' ';
}
equal(slugs.trim(), 'with-jquery with-bootstrap');
// Group fragments are serializable when asHtml is called directly on them
equal(documents.results[0].getGroup('docchapter.docs').asHtml(getLinkResolver()),
'<section data-field=\"linktodoc\"><a href=\"/testing_url/UrDofwEAALAdpbNH/with-jquery\">/testing_url/UrDofwEAALAdpbNH/with-jquery</a></section>' +
'<section data-field=\"linktodoc\"><a href=\"/testing_url/UrDp8AEAAPUdpbNL/with-bootstrap\">/testing_url/UrDp8AEAAPUdpbNL/with-bootstrap</a></section>');
// Group fragments are serializable when as Html is called on a document
equal(documents.results[0].asHtml(getLinkResolver()),
'<section data-field=\"docchapter.title\"><h1>Using with other projects</h1></section>' +
'<section data-field=\"docchapter.intro\"><p>As advertised, meta-micro knows how to stay out of the way of the rest of your application. Here are some cases of how to use it with some of the most used open-source projects in JavaScript.</p></section>' +
'<section data-field=\"docchapter.priority\"><span>500</span></section>' +
'<section data-field=\"docchapter.docs\">' +
'<section data-field=\"linktodoc\"><a href=\"/testing_url/UrDofwEAALAdpbNH/with-jquery\">/testing_url/UrDofwEAALAdpbNH/with-jquery</a></section>' +
'<section data-field=\"linktodoc\"><a href=\"/testing_url/UrDp8AEAAPUdpbNL/with-bootstrap">/testing_url/UrDp8AEAAPUdpbNL/with-bootstrap</a></section>' +
'</section>');
start();
});
});
});
}(window.Prismic));

@@ -27,2 +27,9 @@ (function(Prismic) {

function getLinkResolver(ref) {
return function(doc, isBroken) {
if (isBroken) return '#broken';
return "/testing_url/" + doc.id + "/" + doc.slug + (ref ? ('?ref=' + ref) : '');
}
}
module('Prismic.io', {

@@ -38,2 +45,80 @@ setup: function() {}

});
test('HTML content (2 spans on the same text - one bigger 1)', 1, function() {
var text = 'abcdefghijklmnopqrstuvwxyz';
var spans = [{
"type": "em",
"start": 2,
"end": 6
}, {
"type": "strong",
"start": 2,
"end": 4
}];
var html = Prismic.Fragments.insertSpans(text, spans, {});
equal(html, 'ab<em><strong>cd</strong>ef</em>ghijklmnopqrstuvwxyz');
});
test('HTML content (2 spans on the same text - one bigger 2)', 1, function() {
var text = 'abcdefghijklmnopqrstuvwxyz';
var spans = [{
"type": "em",
"start": 2,
"end": 4
}, {
"type": "strong",
"start": 2,
"end": 6
}];
var html = Prismic.Fragments.insertSpans(text, spans, {});
equal(html, 'ab<strong><em>cd</em>ef</strong>ghijklmnopqrstuvwxyz');
});
test("HTML content with span labels", 1, function() {
var text = 'abcdefghijklmnopqrstuvwxyz';
var spans = [{
"type": "label",
"start": 2,
"end": 6,
"data": {
"label": "tip"
}
}];
var html = Prismic.Fragments.insertSpans(text, spans, {});
equal(html, 'ab<span class="tip">cdef</span>ghijklmnopqrstuvwxyz');
});
test('List items are correctly grouped', function() {
var jsonString = '{ "type":"StructuredText", "value":[ { "spans":[], "text":"Here is some introductory text.", "type":"paragraph" }, { "spans":[], "text":"first item", "type":"list-item" }, { "spans":[], "text":"second item", "type":"list-item" }, { "spans":[], "text":"The following image is linked.", "type":"paragraph" }, { "spans":[], "text":"first item 2", "type":"list-item" }, { "spans":[], "text":"second item 2", "type":"list-item" } ] }';
var jsonObject = JSON.parse(jsonString);
var text = Prismic.Fragments.initField(jsonObject);
equal(text.asHtml(getLinkResolver()), '<p>Here is some introductory text.</p><ul><li>first item</li><li>second item</li></ul><p>The following image is linked.</p><ul><li>first item 2</li><li>second item 2</li></ul>');
});
test('Dates are well retrieved', function() {
var timestampHtml = Prismic.Fragments.initField({"type" : "Date", "value" : "2014-04-01"}).asHtml();
equal(
(new RegExp('<time>... ... \\d\\d 2014 \\d\\d:00:00 GMT[-+]\\d\\d00 \\(.+\\)</time>')).test(timestampHtml),
true
);
});
test('Timestamps are well retrieved', function() {
var timestampHtml = Prismic.Fragments.initField({"type" : "Timestamp", "value" : "2014-06-18T15:30:00+0000"}).asHtml();
equal(
(new RegExp('<time>... ... \\d\\d 2014 \\d\\d:30:00 GMT[-+]\\d\\d00 \\(.+\\)</time>')).test(timestampHtml),
true,
timestampHtml
);
});
test('Link in images are parsed', function() {
var jsonString = '{ "type": "StructuredText", "value": [ { "spans": [], "text": "Here is some introductory text.", "type": "paragraph" }, { "spans": [], "text": "The following image is linked.", "type": "paragraph" }, { "alt": "", "copyright": "", "dimensions": { "height": 129, "width": 260 }, "linkTo": { "type": "Link.web", "value": { "url": "http://google.com/" } }, "type": "image", "url": "http://fpoimg.com/129x260" }, { "spans": [ { "end": 20, "start": 0, "type": "strong" } ], "text": "More important stuff", "type": "paragraph" }, { "spans": [], "text": "The next is linked to a valid document:", "type": "paragraph" }, { "alt": "", "copyright": "", "dimensions": { "height": 400, "width": 400 }, "linkTo": { "type": "Link.document", "value": { "document": { "id": "UxCQFFFFFFFaaYAH", "slug": "something-fantastic", "type": "lovely-thing" }, "isBroken": false } }, "type": "image", "url": "http://fpoimg.com/400x400" }, { "spans": [], "text": "The next is linked to a broken document:", "type": "paragraph" }, { "alt": "", "copyright": "", "dimensions": { "height": 250, "width": 250 }, "linkTo": { "type": "Link.document", "value": { "document": { "id": "UxERPAEAAHQcsBUH", "slug": "-", "type": "event-calendar" }, "isBroken": true } }, "type": "image", "url": "http://fpoimg.com/250x250" }, { "spans": [], "text": "One more image, this one is not linked:", "type": "paragraph" }, { "alt": "", "copyright": "", "dimensions": { "height": 199, "width": 300 }, "type": "image", "url": "http://fpoimg.com/199x300" } ] }';
var jsonObject = JSON.parse(jsonString);
var text = Prismic.Fragments.initField(jsonObject);
equal(text.asHtml(getLinkResolver()), '<p>Here is some introductory text.</p><p>The following image is linked.</p><p class=\"block-img\"><a href=\"http://google.com/\"><img src=\"http://fpoimg.com/129x260\" alt=\"\"></a></p><p><strong>More important stuff</strong></p><p>The next is linked to a valid document:</p><p class=\"block-img\"><a href=\"/testing_url/UxCQFFFFFFFaaYAH/something-fantastic\"><img src=\"http://fpoimg.com/400x400\" alt=\"\"></a></p><p>The next is linked to a broken document:</p><p class=\"block-img\"><a href=\"#broken\"><img src=\"http://fpoimg.com/250x250\" alt=\"\"></a></p><p>One more image, this one is not linked:</p><p class=\"block-img\"><img src=\"http://fpoimg.com/199x300\" alt=\"\"></p>');
});
})(window.Prismic);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc