Socket
Socket
Sign inDemoInstall

prismic.io

Package Overview
Dependencies
Maintainers
4
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.4.0 to 2.0.0-beta

.eslintrc.js

36

package.json

@@ -13,16 +13,17 @@ {

],
"version": "1.4.0",
"version": "2.0.0-beta",
"devDependencies": {
"uglify-js": "^2.6.1",
"babel-preset-es2015": "^6.3.13",
"babelify": "^7.2.0",
"browserify": "^12.0.1",
"chai": "*",
"codeclimate-test-reporter": "~0.0.4",
"gulp": "~3.9.0",
"gulp-uglify": "~1.2.0",
"gulp-util": "~3.0.6",
"gulp-concat": "~2.6.0",
"chai": "*",
"es6-promise": "^3.0.2",
"eslint": "^1.10.3",
"gh-pages": "^0.8.0",
"jsdoc": "^3.4.0",
"mocha": "*",
"gulp-mocha-phantomjs": "git://github.com/erwan/gulp-mocha-phantomjs.git#phantomjs198",
"gulp-jsdoc": "~0.1.4",
"gulp-jshint": "~1.11.2",
"gulp-gist": "~1.0.3",
"gulp-gh-pages": "~0.5.0"
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0"
},

@@ -33,6 +34,15 @@ "repository": {

},
"main": "dist/prismic.io",
"main": "lib/api.js",
"scripts": {
"test": "gulp test"
"build": "scripts/browser.js",
"uglify": "uglifyjs -c -o=dist/prismic.io.min.js dist/prismic.io.js",
"preuglify": "npm run build",
"prepublish": "npm run uglify",
"lint": "eslint lib",
"test": "mocha",
"posttest": "eslint lib",
"builddoc": "jsdoc dist/prismic.io.js README.md",
"pushdoc": "scripts/pushdoc.js",
"prepushdoc": "npm run builddoc"
}
}

@@ -15,30 +15,39 @@ ## JavaScript development kit for prismic.io

```sh
npm install prismic.io
npm install prismic.io --save
```
Or using __bower__:
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).
```sh
bower install prismic.io
```
The kit is universal, it can be used:
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).
* Server-side with NodeJS
* Client-side as part of your build with Browserify, Webpack (you need a [Promise polyfill](https://github.com/jakearchibald/es6-promise) to support IE11 and below)
* Client-side with a simple script tag
### Starter kits
For new project, you can start from a sample project:
* [Node.js project](https://github.com/prismicio/nodejs-sdk)
* [Simple in-browser project](https://github.com/prismicio/javascript-jquery-starter)
* [Static pages generation with baked.js](https://github.com/prismicio/baked.js)
### Usage
If you don't have a Prismic.io repository yet, find out [how to get one](https://developers.prismic.io/documentation/UjBaQsuvzdIHvE4D/getting-started).
To fetch documents from your repository, you need to fetch the Api data first. All asynchronous calls return ES2015 promises.
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:
```javascript
var Prismic = require('prismic.io');
* [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)
Prismic.api("http://lesbonneschoses.prismic.io/api").then(function(api) {
return api.query(""); // An empty query will return all the documents
}).then(function(response) {
console.log("Documents: ", response.documents);
}, function(err) {
console.log("Something went wrong: ", err);
});
```
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.
See the (https://prismic.io/docs)[developer documentation] or the (http://prismicio.github.io/javascript-kit/)[API documentation] for more details on how to use it.
You can then read the documentation from the [Developer's Portal](https://developers.prismic.io/) for more details on how to use
### Contribute to the kit

@@ -50,24 +59,10 @@

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).
Source files are in the `lib/` directory. You only need [Node.js and npm](http://www.joyent.com/blog/installing-node-and-npm/)
to work on the codebase.
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 gulp
npm install
npm test
```
#### Test
Please write tests in [test/test.js](test/test.js) for any bugfix or new feature, following the [very simple QUnit syntax](http://qunitjs.com/), if you need to test with a real Prismic.io repository. Otherwise use [test/unit.js](test/unit.js) for unit testing features.
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:
* ```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))
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.
#### Documentation

@@ -85,3 +80,3 @@

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

@@ -88,0 +83,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.

@@ -1,204 +0,210 @@

(function(Prismic) {
/*eslint-env node, mocha */
/*eslint no-unused-vars: 0 */
// Test snippets for the documentation, and keep them in sync with Gist
var Prismic = require('../lib/prismic.js');
var chai = require('chai');
var testRepository = 'https://lesbonneschoses.prismic.io/api',
assert = chai.assert;
// Test snippets for the documentation, and keep them in sync with Gist
function getLinkResolver(ref) {
return function(doc, isBroken) {
if (isBroken) return '#broken';
return "/testing_url/" + doc.id + "/" + doc.slug + (ref ? ('?ref=' + ref) : '');
};
}
var testRepository = 'https://lesbonneschoses.prismic.io/api',
assert = chai.assert;
describe('Previews', function() {
function getLinkResolver(ref) {
return function(doc, isBroken) {
if (isBroken) return '#broken';
return "/testing_url/" + doc.id + "/" + doc.slug + (ref ? ('?ref=' + ref) : '');
};
}
it('preview-js', function() {
// startgist:51f9c95c4ea58e7e3877:preview-js.js
// todo
// endgist
});
describe('Previews', function() {
it('endpoint-js', function() {
// startgist:563d0601f954aa7b492c:endpoint-js.js
// todo
// endgist
});
it('preview-js', function() {
// startgist:51f9c95c4ea58e7e3877:preview-js.js
// todo
// endgist
});
it('preview-ref', function() {
// startgist:fc7786d7c1cec52f0d36:preview-ref.js
// todo
// endgist
});
it('endpoint-js', function() {
// startgist:563d0601f954aa7b492c:endpoint-js.js
// todo
// endgist
});
it('preview-ref', function() {
// startgist:fc7786d7c1cec52f0d36:preview-ref.js
// todo
// endgist
});
});
describe('API', function() {
it('prismic-api.js', function (done) {
// startgist:1af7b5cb53a5d7cc8561:prismic-api.js
Prismic.api('https://lesbonneschoses.prismic.io/api', function (err, Api) {
if (err) throw err; // gisthide
// You can use the Api object inside this block
console.log("References: ", Api.data.refs);
assert.operator(Api.data.refs.length, '>', 0, 'at least one reference'); // gisthide
done(); // gisthide
});
// endgist
});
describe('API', function() {
it('prismic-apiPrivate.js', function (done) {
// startgist:6ad513d7d0f784de36d9:prismic-apiPrivate.js
Prismic.api('https://lesbonneschoses.prismic.io/api', function (err) {
// This will fail because the token is invalid, but this is how to access a private API
assert.equal(err.message, "Unexpected status code [401] on URL https://lesbonneschoses.prismic.io/api?access_token=MC5-XXXXXXX-vRfvv70"); // gisthide
done(); // gisthide
}, "MC5-XXXXXXX-vRfvv70");
// endgist
});
it('prismic-api.js', function (done) {
// startgist:1af7b5cb53a5d7cc8561:prismic-api.js
Prismic.Api('https://lesbonneschoses.prismic.io/api', function (err, Api) {
if (err) throw err; // gisthide
// You can use the Api object inside this block
console.log("References: ", Api.data.refs);
assert.operator(Api.data.refs.length, '>', 0, 'at least one reference'); // gisthide
done(); // gisthide
});
// endgist
});
it('prismic-references.js', function (done) {
// startgist:c737c4588742c328026f:prismic-references.js
var previewToken = 'MC5VbDdXQmtuTTB6Z0hNWHF3.c--_vVbvv73vv73vv73vv71EA--_vS_vv73vv70T77-9Ke-_ve-_vWfvv70ebO-_ve-_ve-_vQN377-9ce-_vRfvv70';
Prismic.api('https://lesbonneschoses.prismic.io/api', function (err, Api) {
if (err) throw err; // gisthide
var stPatrickRef = Api.ref("St-Patrick specials");
// Now we'll use this reference for all our calls
Api.query(Prismic.Predicates.at("document.type", "product"), {
ref: stPatrickRef
}, function (err, response) {
if (err) {
console.log(err);
done();
} // gisthide
// The documents object contains a Response object with all documents of type "product"
// including the new "Saint-Patrick's Cupcake"
assert.equal(response.results.length, 17); // gisthide
done(); // gisthide
});
}, previewToken);
// endgist
});
it('prismic-apiPrivate.js', function (done) {
// startgist:6ad513d7d0f784de36d9:prismic-apiPrivate.js
Prismic.Api('https://lesbonneschoses.prismic.io/api', function (err, Api) {
// This will fail because the token is invalid, but this is how to access a private API
assert.equal(err.message, "Unexpected status code [401] on URL https://lesbonneschoses.prismic.io/api?access_token=MC5-XXXXXXX-vRfvv70"); // gisthide
done(); // gisthide
}, "MC5-XXXXXXX-vRfvv70");
// endgist
});
});
it('prismic-references.js', function (done) {
// startgist:c737c4588742c328026f:prismic-references.js
var previewToken = 'MC5VbDdXQmtuTTB6Z0hNWHF3.c--_vVbvv73vv73vv73vv71EA--_vS_vv73vv70T77-9Ke-_ve-_vWfvv70ebO-_ve-_ve-_vQN377-9ce-_vRfvv70';
Prismic.Api('https://lesbonneschoses.prismic.io/api', function (err, Api) {
if (err) throw err; // gisthide
var stPatrickRef = Api.ref("St-Patrick specials");
// Now we'll use this reference for all our calls
Api.query(Prismic.Predicates.at("document.type", "product"), {
ref: stPatrickRef
}, function (err, response) {
if (err) {
console.log(err);
done();
} // gisthide
// The documents object contains a Response object with all documents of type "product"
// including the new "Saint-Patrick's Cupcake"
assert.equal(response.results.length, 17); // gisthide
done(); // gisthide
});
}, previewToken);
// endgist
});
describe('Query', function() {
it('prismic-simplequery.js', function (done) {
// startgist:9b6ff487190a429d7fbc:prismic-simplequery.js
Prismic.api('https://lesbonneschoses.prismic.io/api', function (err, Api) {
if (err) throw err; // gisthide
Api.query(Prismic.Predicates.at("document.type", "product"), {}, function (err, response) {
if (err) { console.log(err); done(); } // gisthide
// The documents object contains a Response object with all documents of type "product".
var page = response.page; // The current page number, the first one being 1
assert.equal(page, 1); // gisthide
var results = response.results; // An array containing the results of the current page;
// you may need to retrieve more pages to get all results
assert.equal(results.length, 16); // gisthide
var prev_page = response.prev_page; // the URL of the previous page (may be null)
var next_page = response.next_page; // the URL of the next page (may be null)
var results_per_page = response.results_per_page; // max number of results per page
var results_size = response.results_size; // the size of the current page
var total_pages = response.total_pages; // the number of pages
var total_results_size = response.total_results_size; // the total size of results across all pages
done(); // gisthide
});
});
describe('Query', function() {
// endgist
});
it('prismic-simplequery.js', function (done) {
// startgist:9b6ff487190a429d7fbc:prismic-simplequery.js
Prismic.Api('https://lesbonneschoses.prismic.io/api', function (err, Api) {
if (err) throw err; // gisthide
Api.query(Prismic.Predicates.at("document.type", "product"), {}, function (err, response) {
if (err) { console.log(err); done(); } // gisthide
// The documents object contains a Response object with all documents of type "product".
var page = response.page; // The current page number, the first one being 1
assert.equal(page, 1); // gisthide
var results = response.results; // An array containing the results of the current page;
// you may need to retrieve more pages to get all results
assert.equal(results.length, 16); // gisthide
var prev_page = response.prev_page; // the URL of the previous page (may be null)
var next_page = response.next_page; // the URL of the next page (may be null)
var results_per_page = response.results_per_page; // max number of results per page
var results_size = response.results_size; // the size of the current page
var total_pages = response.total_pages; // the number of pages
var total_results_size = response.total_results_size; // the total size of results across all pages
done(); // gisthide
});
});
// endgist
it('prismic-orderings.js', function (done) {
// startgist:92bdec9ace554b9f95c0:prismic-orderings.js
Prismic.api('https://lesbonneschoses.prismic.io/api', function (err, Api) {
if (err) throw err; // gisthide
Api.form('everything')
.ref(Api.master())
.query(Prismic.Predicates.at("document.type", "product"))
.pageSize(100)
.orderings('[my.product.price desc]')
.submit(function (err, response) {
// The products are now ordered by price, highest first
var results = response.results;
assert.equal(response.results_per_page, 100); // gisthide
done(); // gisthide
});
});
// endgist
});
it('prismic-orderings.js', function (done) {
// startgist:92bdec9ace554b9f95c0:prismic-orderings.js
Prismic.Api('https://lesbonneschoses.prismic.io/api', function (err, Api) {
if (err) throw err; // gisthide
Api.form('everything')
.ref(Api.master())
.query(Prismic.Predicates.at("document.type", "product"))
.pageSize(100)
.orderings('[my.product.price desc]')
.submit(function (err, response) {
// The products are now ordered by price, highest first
var results = response.results;
assert.equal(response.results_per_page, 100); // gisthide
done(); // gisthide
});
});
// endgist
});
it('prismic-predicates.js', function (done) {
// startgist:c90d98f6c77ef6505094:prismic-predicates.js
Prismic.api('https://lesbonneschoses.prismic.io/api', function (err, Api) {
if (err) throw err; // gisthide
Api.form('everything').ref(Api.master()).query(
Prismic.Predicates.at("document.type", "blog-post"),
Prismic.Predicates.dateAfter("my.blog-post.date", new Date(2014, 6, 1))
).submit(function (err, response) {
if (err) throw err; // gisthide
// All documents of type "product", updated after June 1st, 2014
assert.equal(response.results.length, 0); // gisthide
done(); // gisthide
});
});
// endgist
});
it('prismic-predicates.js', function (done) {
// startgist:c90d98f6c77ef6505094:prismic-predicates.js
Prismic.Api('https://lesbonneschoses.prismic.io/api', function (err, Api) {
if (err) throw err; // gisthide
Api.form('everything').ref(Api.master()).query(
Prismic.Predicates.at("document.type", "blog-post"),
Prismic.Predicates.dateAfter("my.blog-post.date", new Date(2014, 6, 1))
).submit(function (err, response) {
if (err) throw err; // gisthide
// All documents of type "product", updated after June 1st, 2014
assert.equal(response.results.length, 0); // gisthide
done(); // gisthide
});
});
// endgist
});
it('prismic-allPredicates.js', function () {
// startgist:1650e3b498d99076f65b:prismic-allPredicates.js
// "at" predicate: equality of a fragment to a value.
var at = Prismic.Predicates.at("document.type", "article");
assert.deepEqual(at, ["at", "document.type", "article"]); // gisthide
// "any" predicate: equality of a fragment to a value.
var any = Prismic.Predicates.any("document.type", ["article", "blog-post"]);
assert.deepEqual(any, ["any", "document.type", ["article", "blog-post"]]); // gisthide
// "missing" predicate: documents having a non-empty field
var missing = Prismic.Predicates.missing("my.article.author");
// "has" predicate: documents having a non-empty field
var has = Prismic.Predicates.has("my.article.author");
it('prismic-allPredicates.js', function () {
// startgist:1650e3b498d99076f65b:prismic-allPredicates.js
// "at" predicate: equality of a fragment to a value.
var at = Prismic.Predicates.at("document.type", "article");
assert.deepEqual(at, ["at", "document.type", "article"]); // gisthide
// "any" predicate: equality of a fragment to a value.
var any = Prismic.Predicates.any("document.type", ["article", "blog-post"]);
assert.deepEqual(any, ["any", "document.type", ["article", "blog-post"]]); // gisthide
// "missing" predicate: documents having a non-empty field
var missing = Prismic.Predicates.missing("my.article.author");
// "has" predicate: documents having a non-empty field
var has = Prismic.Predicates.has("my.article.author");
// "fulltext" predicate: fulltext search in a fragment.
var fulltext = Prismic.Predicates.fulltext("my.article.body", "sausage");
// "fulltext" predicate: fulltext search in a fragment.
var fulltext = Prismic.Predicates.fulltext("my.article.body", "sausage");
// "similar" predicate, with a document id as reference
var similar = Prismic.Predicates.similar("UXasdFwe42D", 10);
// endgist
});
// "similar" predicate, with a document id as reference
var similar = Prismic.Predicates.similar("UXasdFwe42D", 10);
// endgist
});
});
});
describe('Fragments', function() {
describe('Fragments', function() {
it('prismic-htmlSerializer.js', function (done) {
Prismic.Api(testRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').query(Prismic.Predicates.at("document.id", "UlfoxUnM0wkXYXbl"))
.ref(Api.master()).submit(function (err, documents) {
if (err) throw err;
var doc = documents.results[0];
// startgist:ad67f185eefe842e4a12:prismic-htmlSerializer.js
var htmlSerializer = function (element, content) {
// Don't wrap images in a <p> tag
if (element.type == "image") {
return '<img src="' + element.url + '" alt="' + element.alt + '">';
}
it('prismic-htmlSerializer.js', function (done) {
Prismic.api(testRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').query(Prismic.Predicates.at("document.id", "UlfoxUnM0wkXYXbl"))
.ref(Api.master()).submit(function (err, documents) {
if (err) throw err;
var doc = documents.results[0];
// startgist:ad67f185eefe842e4a12:prismic-htmlSerializer.js
var htmlSerializer = function (element, content) {
// Don't wrap images in a <p> tag
if (element.type == "image") {
return '<img src="' + element.url + '" alt="' + element.alt + '">';
}
// Add a class to hyperlinks
if (element.type == "hyperlink") {
return '<a class="some-link" href="' + element.url + '">' + content + '</a>';
}
// Add a class to hyperlinks
if (element.type == "hyperlink") {
return '<a class="some-link" href="' + element.url + '">' + content + '</a>';
}
// Return null to stick with the default behavior
return null;
};
var html = doc.getStructuredText('blog-post.body').asHtml(getLinkResolver(), htmlSerializer);
// endgist
assert.equal(html,
'<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>' +
// Return null to stick with the default behavior
return null;
};
var html = doc.getStructuredText('blog-post.body').asHtml(getLinkResolver(), htmlSerializer);
// endgist
assert.equal(html,
'<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>' +

@@ -213,359 +219,354 @@ '<h2>As seen by the pastry amateurs</h2>' +

'<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>');
'<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>');
done();
});
});
done();
});
});
});
it('prismic-getText.js', function (done) {
Prismic.Api('https://lesbonneschoses.prismic.io/api', function (err, Api) {
if (err) throw err; // gisthide
Api.form('everything').query(Prismic.Predicates.at("document.id", "UlfoxUnM0wkXYXbl")).ref(Api.master()).submit(function (err, documents) {
if (err) throw err; // gisthide
var doc = documents.results[0];
// startgist:39e5df50e5f10c574fde:prismic-getText.js
var author = doc.getText("blog-post.author");
if (!author) author = "Anonymous";
assert.equal(author, "John M. Martelle, Fine Pastry Magazine"); // gisthide
// endgist
done();
});
});
});
it('prismic-getText.js', function (done) {
Prismic.api('https://lesbonneschoses.prismic.io/api', function (err, Api) {
if (err) throw err; // gisthide
Api.form('everything').query(Prismic.Predicates.at("document.id", "UlfoxUnM0wkXYXbl")).ref(Api.master()).submit(function (err, documents) {
if (err) throw err; // gisthide
var doc = documents.results[0];
// startgist:39e5df50e5f10c574fde:prismic-getText.js
var author = doc.getText("blog-post.author");
if (!author) author = "Anonymous";
assert.equal(author, "John M. Martelle, Fine Pastry Magazine"); // gisthide
// endgist
done();
});
});
});
it('prismic-getNumber.js', function (done) {
Prismic.Api('https://lesbonneschoses.prismic.io/api', function (err, Api) {
if (err) throw err;
Api.form('everything').query(Prismic.Predicates.at("document.id", "UlfoxUnM0wkXYXbO")).ref(Api.master()).submit(function (err, documents) {
if (err) throw err;
var doc = documents.results[0];
// startgist:17fab0179019f272f947:prismic-getNumber.js
// Number predicates
var gt = Prismic.Predicates.gt("my.product.price", 10);
var lt = Prismic.Predicates.lt("my.product.price", 20);
var inRange = Prismic.Predicates.inRange("my.product.price", 10, 20);
it('prismic-getNumber.js', function (done) {
Prismic.api('https://lesbonneschoses.prismic.io/api', function (err, Api) {
if (err) throw err;
Api.form('everything').query(Prismic.Predicates.at("document.id", "UlfoxUnM0wkXYXbO")).ref(Api.master()).submit(function (err, documents) {
if (err) throw err;
var doc = documents.results[0];
// startgist:17fab0179019f272f947:prismic-getNumber.js
// Number predicates
var gt = Prismic.Predicates.gt("my.product.price", 10);
var lt = Prismic.Predicates.lt("my.product.price", 20);
var inRange = Prismic.Predicates.inRange("my.product.price", 10, 20);
// Accessing number fields
var price = doc.getNumber("product.price");
// endgist
assert.equal(price, 2.5);
done();
});
});
});
// Accessing number fields
var price = doc.getNumber("product.price");
// endgist
assert.equal(price, 2.5);
done();
});
});
});
it('prismic-images.js', function (done) {
Prismic.Api('https://lesbonneschoses.prismic.io/api', function (err, Api) {
if (err) throw err;
Api.form('everything').query(Prismic.Predicates.at("document.id", "UlfoxUnM0wkXYXbO")).ref(Api.master()).submit(function (err, documents) {
if (err) throw err;
var doc = documents.results[0];
// startgist:a7be4722af6671f87797:prismic-images.js
// Accessing image fields
var image = doc.getImage("product.image");
// Most of the time you will be using the "main" view
var url = image.main.url;
// endgist
assert.equal(url, "https://prismic-io.s3.amazonaws.com/lesbonneschoses/f606ad513fcc2a73b909817119b84d6fd0d61a6d.png");
done();
});
});
});
it('prismic-images.js', function (done) {
Prismic.api('https://lesbonneschoses.prismic.io/api', function (err, Api) {
if (err) throw err;
Api.form('everything').query(Prismic.Predicates.at("document.id", "UlfoxUnM0wkXYXbO")).ref(Api.master()).submit(function (err, documents) {
if (err) throw err;
var doc = documents.results[0];
// startgist:a7be4722af6671f87797:prismic-images.js
// Accessing image fields
var image = doc.getImage("product.image");
// Most of the time you will be using the "main" view
var url = image.main.url;
// endgist
assert.equal(url, "https://prismic-io.s3.amazonaws.com/lesbonneschoses/f606ad513fcc2a73b909817119b84d6fd0d61a6d.png");
done();
});
});
});
it('prismic-dateTimestamp.js', function (done) {
Prismic.Api('https://lesbonneschoses.prismic.io/api', function (err, Api) {
if (err) throw err;
Api.form('everything').query(Prismic.Predicates.at("document.id", "UlfoxUnM0wkXYXbl")).ref(Api.master()).submit(function (err, documents) {
if (err) throw err;
var doc = documents.results[0];
// startgist:1c9514ef4f31701732ac:prismic-dateTimestamp.js
var Predicates = Prismic.Predicates;
// Date and Timestamp predicates
var dateBefore = Predicates.dateBefore("my.product.releaseDate", new Date(2014, 6, 1));
var dateAfter = Predicates.dateAfter("my.product.releaseDate", new Date(2014, 1, 1));
var dateBetween = Predicates.dateBetween("my.product.releaseDate", new Date(2014, 1, 1), new Date(2014, 6, 1));
var dayOfMonth = Predicates.dayOfMonth("my.product.releaseDate", 14);
var dayOfMonthAfter = Predicates.dayOfMonthAfter("my.product.releaseDate", 14);
var dayOfMonthBefore = Predicates.dayOfMonthBefore("my.product.releaseDate", 14);
var dayOfWeek = Predicates.dayOfWeek("my.product.releaseDate", "Tuesday");
var dayOfWeekAfter = Predicates.dayOfWeekAfter("my.product.releaseDate", "Wednesday");
var dayOfWeekBefore = Predicates.dayOfWeekBefore("my.product.releaseDate", "Wednesday");
var month = Predicates.month("my.product.releaseDate", "June");
var monthBefore = Predicates.monthBefore("my.product.releaseDate", "June");
var monthAfter = Predicates.monthAfter("my.product.releaseDate", "June");
var year = Predicates.year("my.product.releaseDate", 2014);
var hour = Predicates.hour("my.product.releaseDate", 12);
var hourBefore = Predicates.hourBefore("my.product.releaseDate", 12);
var hourAfter = Predicates.hourAfter("my.product.releaseDate", 12);
it('prismic-dateTimestamp.js', function (done) {
Prismic.api('https://lesbonneschoses.prismic.io/api', function (err, Api) {
if (err) throw err;
Api.form('everything').query(Prismic.Predicates.at("document.id", "UlfoxUnM0wkXYXbl")).ref(Api.master()).submit(function (err, documents) {
if (err) throw err;
var doc = documents.results[0];
// startgist:1c9514ef4f31701732ac:prismic-dateTimestamp.js
var Predicates = Prismic.Predicates;
// Date and Timestamp predicates
var dateBefore = Predicates.dateBefore("my.product.releaseDate", new Date(2014, 6, 1));
var dateAfter = Predicates.dateAfter("my.product.releaseDate", new Date(2014, 1, 1));
var dateBetween = Predicates.dateBetween("my.product.releaseDate", new Date(2014, 1, 1), new Date(2014, 6, 1));
var dayOfMonth = Predicates.dayOfMonth("my.product.releaseDate", 14);
var dayOfMonthAfter = Predicates.dayOfMonthAfter("my.product.releaseDate", 14);
var dayOfMonthBefore = Predicates.dayOfMonthBefore("my.product.releaseDate", 14);
var dayOfWeek = Predicates.dayOfWeek("my.product.releaseDate", "Tuesday");
var dayOfWeekAfter = Predicates.dayOfWeekAfter("my.product.releaseDate", "Wednesday");
var dayOfWeekBefore = Predicates.dayOfWeekBefore("my.product.releaseDate", "Wednesday");
var month = Predicates.month("my.product.releaseDate", "June");
var monthBefore = Predicates.monthBefore("my.product.releaseDate", "June");
var monthAfter = Predicates.monthAfter("my.product.releaseDate", "June");
var year = Predicates.year("my.product.releaseDate", 2014);
var hour = Predicates.hour("my.product.releaseDate", 12);
var hourBefore = Predicates.hourBefore("my.product.releaseDate", 12);
var hourAfter = Predicates.hourAfter("my.product.releaseDate", 12);
// Accessing Date and Timestamp fields
var date = doc.getDate("blog-post.date");
var resultYear = date ? date.getFullYear() : null;
var updateTime = doc.getTimestamp("blog-post.update");
var updateHour = updateTime ? updateTime.getHours() : 0;
assert.equal(resultYear, 2013); // gisthide
// endgist
done();
});
});
});
// Accessing Date and Timestamp fields
var date = doc.getDate("blog-post.date");
var resultYear = date ? date.getFullYear() : null;
var updateTime = doc.getTimestamp("blog-post.update");
var updateHour = updateTime ? updateTime.getHours() : 0;
assert.equal(resultYear, 2013); // gisthide
// endgist
done();
});
});
});
it('prismic-group.js', function () {
var doc = Prismic.Api("").parseDoc({
id: "abcd",
type: "article",
data: {
article: {
documents: {
type: "Group",
"value": [
{
"linktodoc": {
"type": "Link.document",
"value": {
"document": {
"id": "UrDejAEAAFwMyrW9",
"type": "doc",
"tags": [ ],
"slug": "installing-meta-micro"
},
"isBroken": false
}
},
"desc": {
"type": "StructuredText",
"value": [
{
"type": "paragraph",
"text": "A detailed step by step point of view on how installing happens.",
"spans": []
}
]
}
},
{
"linktodoc": {
"type": "Link.document",
"value": {
"document": {
"id": "UrDmKgEAALwMyrXA",
"type": "doc",
"tags": [ ],
"slug": "using-meta-micro"
},
"isBroken": false
}
}
}
]
}
}
it('prismic-group.js', function () {
var doc = Prismic.parseDoc({
id: "abcd",
type: "article",
data: {
article: {
documents: {
type: "Group",
"value": [{
"linktodoc": {
"type": "Link.document",
"value": {
"document": {
"id": "UrDejAEAAFwMyrW9",
"type": "doc",
"tags": [ ],
"slug": "installing-meta-micro"
},
"isBroken": false
}
});
// startgist:1c9514ef4f31701732ac:prismic-group.js
var group = doc.getGroup("article.documents");
var docs = group ? group.toArray() : [];
for (var i = 0; i < docs.length; i++) {
// Desc and Link are Fragments, their type depending on what's declared in the Document Mask
var desc = docs[i].getStructuredText("desc");
var link = docs[i].getLink("linktodoc");
}
// endgist
assert.equal(
docs[0].getStructuredText("desc").asHtml(),
"<p>A detailed step by step point of view on how installing happens.</p>"
);
});
it('prismic-link.js', function () {
var doc = Prismic.Api("").parseDoc({
id: "abcd",
type: "article",
data: {
article: {
source: {
type: "Link.document",
value: {
document: {
id: "UlfoxUnM0wkXYXbE",
type: "product",
tags: ["Macaron"],
slug: "dark-chocolate-macaron"
},
isBroken: false
}
}
}
},
"desc": {
"type": "StructuredText",
"value": [{
"type": "paragraph",
"text": "A detailed step by step point of view on how installing happens.",
"spans": []
}]
}
}, {
"linktodoc": {
"type": "Link.document",
"value": {
"document": {
"id": "UrDmKgEAALwMyrXA",
"type": "doc",
"tags": [ ],
"slug": "using-meta-micro"
},
"isBroken": false
}
});
// startgist:0c86d1fe3471baf52f59:prismic-link.js
var resolver = function (doc, isBroken) {
if (isBroken) return '#broken';
return "/testing_url/" + doc.id + "/" + doc.slug;
};
var source = doc.getLink("article.source");
var url = source ? source.url(resolver) : null;
// endgist
assert.equal(url, "/testing_url/UlfoxUnM0wkXYXbE/dark-chocolate-macaron");
});
}
}]
}
}
}
});
// startgist:1c9514ef4f31701732ac:prismic-group.js
var group = doc.getGroup("article.documents");
var docs = group ? group.toArray() : [];
for (var i = 0; i < docs.length; i++) {
// Desc and Link are Fragments, their type depending on what's declared in the Document Mask
var desc = docs[i].getStructuredText("desc");
var link = docs[i].getLink("linktodoc");
}
// endgist
assert.equal(
docs[0].getStructuredText("desc").asHtml(),
"<p>A detailed step by step point of view on how installing happens.</p>"
);
});
it('prismic-embed.js', function () {
var doc = Prismic.Api("").parseDoc({
id: "abcd",
type: "article",
data: {
article: {
"video": {
"type": "Embed",
"value": {
"oembed": {
"provider_url": "http://www.youtube.com/",
"type": "video",
"thumbnail_height": 360,
"height": 270,
"thumbnail_url": "http://i1.ytimg.com/vi/baGfM6dBzs8/hqdefault.jpg",
"width": 480,
"provider_name": "YouTube",
"html": "<iframe width=\"480\" height=\"270\" src=\"http://www.youtube.com/embed/baGfM6dBzs8?feature=oembed\" frameborder=\"0\" allowfullscreen></iframe>",
"author_name": "Siobhan Wilson",
"version": "1.0",
"author_url": "http://www.youtube.com/user/siobhanwilsonsongs",
"thumbnail_width": 480,
"title": "Siobhan Wilson - All Dressed Up",
"embed_url": "https://www.youtube.com/watch?v=baGfM6dBzs8"
}
}
}
}
}
});
// startgist:407c6960a6a7bb407c88:prismic-embed.js
var video = doc.get("article.video");
// Html is the code to include to embed the object, and depends on the embedded service
var html = video ? video.asHtml() : "";
// endgist
assert.equal(html, "<iframe width=\"480\" height=\"270\" src=\"http://www.youtube.com/embed/baGfM6dBzs8?feature=oembed\" frameborder=\"0\" allowfullscreen></iframe>");
});
it('prismic-link.js', function () {
var doc = Prismic.parseDoc({
id: "abcd",
type: "article",
data: {
article: {
source: {
type: "Link.document",
value: {
document: {
id: "UlfoxUnM0wkXYXbE",
type: "product",
tags: ["Macaron"],
slug: "dark-chocolate-macaron"
},
isBroken: false
}
}
}
}
});
// startgist:0c86d1fe3471baf52f59:prismic-link.js
var resolver = function (doc, isBroken) {
if (isBroken) return '#broken';
return "/testing_url/" + doc.id + "/" + doc.slug;
};
var source = doc.getLink("article.source");
var url = source ? source.url(resolver) : null;
// endgist
assert.equal(url, "/testing_url/UlfoxUnM0wkXYXbE/dark-chocolate-macaron");
});
it('prismic-color.js', function () {
var doc = Prismic.Api("").parseDoc({
id: "abcd",
type: "article",
data: {
article: {
"background": {
"type": "Color",
"value": "#000000"
}
}
}
});
var $ = function (x) {
return { css: function (y, z) {
} };
};
// startgist:4d5072768603847ede43:prismic-color.js
var bgcolor = doc.getColor("article.background");
$("#article").css("background-color", bgcolor);
// endgist
assert.equal(bgcolor, "#000000");
});
it('prismic-embed.js', function () {
var doc = Prismic.parseDoc({
id: "abcd",
type: "article",
data: {
article: {
"video": {
"type": "Embed",
"value": {
"oembed": {
"provider_url": "http://www.youtube.com/",
"type": "video",
"thumbnail_height": 360,
"height": 270,
"thumbnail_url": "http://i1.ytimg.com/vi/baGfM6dBzs8/hqdefault.jpg",
"width": 480,
"provider_name": "YouTube",
"html": "<iframe width=\"480\" height=\"270\" src=\"http://www.youtube.com/embed/baGfM6dBzs8?feature=oembed\" frameborder=\"0\" allowfullscreen></iframe>",
"author_name": "Siobhan Wilson",
"version": "1.0",
"author_url": "http://www.youtube.com/user/siobhanwilsonsongs",
"thumbnail_width": 480,
"title": "Siobhan Wilson - All Dressed Up",
"embed_url": "https://www.youtube.com/watch?v=baGfM6dBzs8"
}
}
}
}
}
});
// startgist:407c6960a6a7bb407c88:prismic-embed.js
var video = doc.get("article.video");
// Html is the code to include to embed the object, and depends on the embedded service
var html = video ? video.asHtml() : "";
// endgist
assert.equal(html, "<iframe width=\"480\" height=\"270\" src=\"http://www.youtube.com/embed/baGfM6dBzs8?feature=oembed\" frameborder=\"0\" allowfullscreen></iframe>"
);
});
it('prismic-geopoint.js', function () {
var doc = Prismic.Api("").parseDoc({
id: "abcd",
type: "article",
data: {
article: {
"location": {
"type": "GeoPoint",
"value": {
"latitude": 48.877108,
"longitude": 2.3338790
}
}
}
}
});
// startgist:6eb5436349a2e7fc9f5a:prismic-geopoint.js
// "near" predicate for GeoPoint fragments
var near = Prismic.Predicates.near("my.store.location", 48.8768767, 2.3338802, 10);
it('prismic-color.js', function () {
var doc = Prismic.parseDoc({
id: "abcd",
type: "article",
data: {
article: {
"background": {
"type": "Color",
"value": "#000000"
}
}
}
});
var $ = function (x) {
return { css: function (y, z) {
} };
};
// startgist:4d5072768603847ede43:prismic-color.js
var bgcolor = doc.getColor("article.background");
$("#article").css("background-color", bgcolor);
// endgist
assert.equal(bgcolor, "#000000");
});
// Accessing GeoPoint fragments
var place = doc.getGeoPoint("article.location");
var coordinates;
if (place) {
coordinates = place.latitude + "," + place.longitude;
it('prismic-geopoint.js', function () {
var doc = Prismic.parseDoc({
id: "abcd",
type: "article",
data: {
article: {
"location": {
"type": "GeoPoint",
"value": {
"latitude": 48.877108,
"longitude": 2.3338790
}
// endgist
assert.equal(coordinates, "48.877108,2.333879");
});
}
}
}
});
// startgist:6eb5436349a2e7fc9f5a:prismic-geopoint.js
// "near" predicate for GeoPoint fragments
var near = Prismic.Predicates.near("my.store.location", 48.8768767, 2.3338802, 10);
it('prismic-asHtml.js', function (done) {
Prismic.Api('https://lesbonneschoses.prismic.io/api', function (err, Api) {
if (err) {
console.log(err);
done();
}
Api.form('everything').ref(Api.master()).query(Prismic.Predicates.at("document.id", "UlfoxUnM0wkXYXbX")).submit(function (err, response) {
if (err) {
console.log(err);
done();
}
// startgist:6bf3785fbacac021c7ee:prismic-asHtml.js
var doc = response.results[0];
var html = doc.getStructuredText('blog-post.body').asHtml({
linkResolver: function (ctx, doc, isBroken) {
if (isBroken) return '#broken';
return "/testing_url/" + doc.id + "/" + doc.slug + ( ctx.maybeRef ? '?ref=' + ctx.maybeRef : '' );
}
});
// endgist
assert.equal(html, '<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>');
done();
});
});
// Accessing GeoPoint fragments
var place = doc.getGeoPoint("article.location");
var coordinates;
if (place) {
coordinates = place.latitude + "," + place.longitude;
}
// endgist
assert.equal(coordinates, "48.877108,2.333879");
});
it('prismic-asHtml.js', function (done) {
Prismic.api('https://lesbonneschoses.prismic.io/api', function (err, Api) {
if (err) {
console.log(err);
done();
}
Api.form('everything').ref(Api.master()).query(Prismic.Predicates.at("document.id", "UlfoxUnM0wkXYXbX")).submit(function (err, response) {
if (err) {
console.log(err);
done();
}
// startgist:6bf3785fbacac021c7ee:prismic-asHtml.js
var doc = response.results[0];
var html = doc.getStructuredText('blog-post.body').asHtml({
linkResolver: function (ctx, doc, isBroken) {
if (isBroken) return '#broken';
return "/testing_url/" + doc.id + "/" + doc.slug + ( ctx.maybeRef ? '?ref=' + ctx.maybeRef : '' );
}
});
// endgist
assert.equal(
html,
'<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>'
);
done();
});
});
});
describe('Cache', function() {
});
it('prismic-cache.js', function(done) {
// startgist:6bf3785fbacac021c7ee:prismic-cache.js
var cache = {
get: function (key, cb) {
// Retrieve a value from the key
return cb();
},
describe('Cache', function() {
set: function (key, value, ttl, cb) {
return cb();
},
it('prismic-cache.js', function(done) {
// startgist:6bf3785fbacac021c7ee:prismic-cache.js
var cache = {
get: function (key, cb) {
// Retrieve a value from the key
return cb();
},
remove: function (key, cb) {
// Remove a value
return cb();
},
set: function (key, value, ttl, cb) {
return cb();
},
clear: function (key, cb) {
return cb();
}
};
remove: function (key, cb) {
// Remove a value
return cb();
},
Prismic.Api('https://lesbonneschoses.prismic.io/api', function (err, Api) {
if (err) return done(err); // gisthide
// The Api in this block will use the custom cache object
assert.notEqual(Api, null); // gisthide
done(); // gisthide
}, null, null, cache);
// endgist
});
clear: function (key, cb) {
return cb();
}
};
});
Prismic.api('https://lesbonneschoses.prismic.io/api', function (err, Api) {
if (err) { done(err); return; } // gisthide
// The Api in this block will use the custom cache object
assert.notEqual(Api, null); // gisthide
done(); // gisthide
}, null, null, cache);
// endgist
});
}(window.Prismic));
});

@@ -1,778 +0,771 @@

(function(Prismic) {
/*eslint-env node, mocha */
var assert = chai.assert,
testRepository = 'https://lesbonneschoses.prismic.io/api',
previewToken = 'MC5VbDdXQmtuTTB6Z0hNWHF3.c--_vVbvv73vv73vv73vv71EA--_vS_vv73vv70T77-9Ke-_ve-_vWfvv70ebO-_ve-_ve-_vQN377-9ce-_vRfvv70',
microRepository = 'https://micro.prismic.io/api',
Predicates = Prismic.Predicates;
var Prismic = require('../lib/prismic.js');
var chai = require('chai');
function getLinkResolver(ref) {
return function(doc, isBroken) {
if (isBroken) return '#broken';
return "/testing_url/" + doc.id + "/" + doc.slug + (ref ? ('?ref=' + ref) : '');
}
}
var assert = chai.assert,
testRepository = 'https://lesbonneschoses.prismic.io/api',
previewToken = 'MC5VbDdXQmtuTTB6Z0hNWHF3.c--_vVbvv73vv73vv73vv71EA--_vS_vv73vv70T77-9Ke-_ve-_vWfvv70ebO-_ve-_ve-_vQN377-9ce-_vRfvv70',
microRepository = 'https://micro.prismic.io/api';
describe('Document manipulation', function() {
function getLinkResolver(ref) {
return function(doc, isBroken) {
if (isBroken) return '#broken';
return "/testing_url/" + doc.id + "/" + doc.slug + (ref ? ('?ref=' + ref) : '');
};
}
it('Stores and retrieves all document slugs well', function (done) {
Prismic.Api(testRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').query('[[:d = at(document.id, "UlfoxUnM0wkXYXbg")]]').ref(Api.master()).submit(function (err, documents) {
if (err) throw err;
var doc = documents.results[0];
assert.equal(doc.slugs.length, 2);
done();
});
});
});
describe('Document manipulation', function() {
it('Render a document to Html', function (done) {
Prismic.Api(testRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').ref(Api.master()).submit(function (err, documents) {
if (err) throw err;
var first = documents.results[0];
assert.notEqual(null, first);
first.asHtml(getLinkResolver());
done();
});
});
});
it('Stores and retrieves all document slugs well', function (done) {
Prismic.api(testRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').query('[[:d = at(document.id, "UlfoxUnM0wkXYXbg")]]').ref(Api.master()).submit(function (err, documents) {
if (err) throw err;
var doc = documents.results[0];
assert.equal(doc.slugs.length, 2);
done();
});
});
});
it('Render a document to Text', function (done) {
Prismic.Api(testRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').query('[[:d = at(document.id, "UlfoxUnM0wkXYXbX")]]').ref(Api.master()).submit(function (err, documents) {
if (err) throw err;
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>');
}
it('Render a document to Html', function (done) {
Prismic.api(testRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').ref(Api.master()).submit(function (err, documents) {
if (err) throw err;
var first = documents.results[0];
assert.notEqual(null, first);
first.asHtml(getLinkResolver());
done();
});
});
});
assert.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"));
done();
});
});
});
it('Render a document to Text', function (done) {
Prismic.api(testRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').query('[[:d = at(document.id, "UlfoxUnM0wkXYXbX")]]').ref(Api.master()).submit(function (err, documents) {
if (err) throw err;
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>');
}
assert.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"));
done();
});
});
});
describe('Multiple fragment level global test', function() {
});
it('getFirstImage in slice zone works', function (done) {
var doc = Prismic.Api("").parseDoc({
"id":"VQ_hV31Za5EAy02H",
"uid":null,
"type":"article",
"href":"http://toto.wroom.dev/api/documents/search?ref=VQ_uWX1Za0oCy46m&q=%5B%5B%3Ad+%3D+at%28document.id%2C+%22VQ_hV31Za5EAy02H%22%29+%5D%5D",
"tags":[],
"slugs":["une-activite"],
"linked_documents":[],
"data":{
"article":{
"activities":{
"type":"Group",
"value":[{
"title":{
"type":"StructuredText",
"value":[{
"type":"paragraph",
"text":"Une activité",
"spans":[]
}]
},
"image":{
"type":"Image",
"value":{
"main":{
"url":"https://wroomdev.s3.amazonaws.com/toto/ce3f52b933c4934a13422e09ed0ff6ad03a29621_hsf_evilsquall.jpg",
"alt":"",
"copyright":"",
"dimensions":{"width":860,"height":640}
},
"views":{
"headline":{
"url":"https://wroomdev.s3.amazonaws.com/toto/5445d2dcd2b0c541b0406ca867ab3d07b309c944_hsf_evilsquall.jpg",
"alt":"",
"copyright":"",
"dimensions":{"width":570,"height":400}
}
}
}
},
"body":{
"type":"StructuredText",
"value":[{
"type":"paragraph",
"text":"elle est bien",
"spans":[]
}]
}
}]
},
"un_champ_texte":{
"type":"Text",
"value":"stuffgg"
},
"blocks":{
"type":"SliceZone",
"value":[{
"type":"Slice",
"slice_type": "features",
"value":{
"type":"Group",
"value":[{
"illustration":{
"type":"Image",
"value":{
"main":{
"url":"https://wroomdev.s3.amazonaws.com/toto/db3775edb44f9818c54baa72bbfc8d3d6394b6ef_hsf_evilsquall_first_in_slice.jpg",
"alt":"",
"copyright":"",
"dimensions":{"width":4285,"height":709}
},
"views":{}
}
},
"title":{
"type":"Text",
"value":"c'est un bloc features"
}
}]
}
},{
"type":"Slice",
"slice_type":"text",
"value":{
"type":"StructuredText",
"value":[{
"type":"paragraph",
"text":"C'est un bloc content",
"spans":[]
}]
}
}]
}
describe('Multiple fragment level global test', function() {
it('getFirstImage in slice zone works', function (done) {
var doc = Prismic.parseDoc({
"id":"VQ_hV31Za5EAy02H",
"uid":null,
"type":"article",
"href":"http://toto.wroom.dev/api/documents/search?ref=VQ_uWX1Za0oCy46m&q=%5B%5B%3Ad+%3D+at%28document.id%2C+%22VQ_hV31Za5EAy02H%22%29+%5D%5D",
"tags":[],
"slugs":["une-activite"],
"linked_documents":[],
"data":{
"article":{
"activities":{
"type":"Group",
"value":[{
"title":{
"type":"StructuredText",
"value":[{
"type":"paragraph",
"text":"Une activité",
"spans":[]
}]
},
"image":{
"type":"Image",
"value":{
"main":{
"url":"https://wroomdev.s3.amazonaws.com/toto/ce3f52b933c4934a13422e09ed0ff6ad03a29621_hsf_evilsquall.jpg",
"alt":"",
"copyright":"",
"dimensions":{"width":860,"height":640}
},
"views":{
"headline":{
"url":"https://wroomdev.s3.amazonaws.com/toto/5445d2dcd2b0c541b0406ca867ab3d07b309c944_hsf_evilsquall.jpg",
"alt":"",
"copyright":"",
"dimensions":{"width":570,"height":400}
}
}
}
});
var sliceSingleElem = Prismic.Api("").parseDoc({
"id":"VQ_hV31Za5EAy02H",
"uid":null,
"type":"article",
"href":"http://toto.wroom.dev/api/documents/search?ref=VQ_uWX1Za0oCy46m&q=%5B%5B%3Ad+%3D+at%28document.id%2C+%22VQ_hV31Za5EAy02H%22%29+%5D%5D",
"tags":[],
"slugs":["une-activite"],
"linked_documents":[],
"data":{
"article":{
"blocks":{
"type":"SliceZone",
"value":[{
"type":"Slice",
"slice_type": "features",
"value": {
"type":"Image",
"value":{
"main":{
"url":"https://wroomdev.s3.amazonaws.com/toto/db3775edb44f9818c54baa72bbfc8d3d6394b6ef_hsf_evilsquall_slice_single.jpg",
"alt":"",
"copyright":"",
"dimensions":{"width":4285,"height":709}
},
"views":{}
}
}
}]
}
},
"body":{
"type":"StructuredText",
"value":[{
"type":"paragraph",
"text":"elle est bien",
"spans":[]
}]
}
}]
},
"un_champ_texte":{
"type":"Text",
"value":"stuffgg"
},
"blocks":{
"type":"SliceZone",
"value":[{
"type":"Slice",
"slice_type": "features",
"value":{
"type":"Group",
"value":[{
"illustration":{
"type":"Image",
"value":{
"main":{
"url":"https://wroomdev.s3.amazonaws.com/toto/db3775edb44f9818c54baa72bbfc8d3d6394b6ef_hsf_evilsquall_first_in_slice.jpg",
"alt":"",
"copyright":"",
"dimensions":{"width":4285,"height":709}
},
"views":{}
}
},
"title":{
"type":"Text",
"value":"c'est un bloc features"
}
}]
}
},{
"type":"Slice",
"slice_type":"text",
"value":{
"type":"StructuredText",
"value":[{
"type":"paragraph",
"text":"C'est un bloc content",
"spans":[]
}]
}
}]
}
}
}
});
var sliceSingleElem = Prismic.parseDoc({
"id":"VQ_hV31Za5EAy02H",
"uid":null,
"type":"article",
"href":"http://toto.wroom.dev/api/documents/search?ref=VQ_uWX1Za0oCy46m&q=%5B%5B%3Ad+%3D+at%28document.id%2C+%22VQ_hV31Za5EAy02H%22%29+%5D%5D",
"tags":[],
"slugs":["une-activite"],
"linked_documents":[],
"data":{
"article":{
"blocks":{
"type":"SliceZone",
"value":[{
"type":"Slice",
"slice_type": "features",
"value": {
"type":"Image",
"value":{
"main":{
"url":"https://wroomdev.s3.amazonaws.com/toto/db3775edb44f9818c54baa72bbfc8d3d6394b6ef_hsf_evilsquall_slice_single.jpg",
"alt":"",
"copyright":"",
"dimensions":{"width":4285,"height":709}
},
"views":{}
}
});
}
}]
}
}
}
});
// Testing get First Image on doc level.
assert.equal(doc.getFirstImage().getView('main').url, "https://wroomdev.s3.amazonaws.com/toto/ce3f52b933c4934a13422e09ed0ff6ad03a29621_hsf_evilsquall.jpg");
// Testing get First Image on doc level.
assert.equal(doc.getFirstImage().getView('main').url, "https://wroomdev.s3.amazonaws.com/toto/ce3f52b933c4934a13422e09ed0ff6ad03a29621_hsf_evilsquall.jpg");
// Testing get First Image on slice level.
var slices = doc.getSliceZone('article.blocks');
assert.equal(slices.getFirstImage().getView('main').url, "https://wroomdev.s3.amazonaws.com/toto/db3775edb44f9818c54baa72bbfc8d3d6394b6ef_hsf_evilsquall_first_in_slice.jpg");
// Testing get First Image on slice level.
var slices = doc.getSliceZone('article.blocks');
assert.equal(slices.getFirstImage().getView('main').url, "https://wroomdev.s3.amazonaws.com/toto/db3775edb44f9818c54baa72bbfc8d3d6394b6ef_hsf_evilsquall_first_in_slice.jpg");
var slicesWithSingleElem = sliceSingleElem.getSliceZone('article.blocks');
assert.equal(slicesWithSingleElem.getFirstImage().getView('main').url, "https://wroomdev.s3.amazonaws.com/toto/db3775edb44f9818c54baa72bbfc8d3d6394b6ef_hsf_evilsquall_slice_single.jpg");
done();
});
var slicesWithSingleElem = sliceSingleElem.getSliceZone('article.blocks');
assert.equal(slicesWithSingleElem.getFirstImage().getView('main').url, "https://wroomdev.s3.amazonaws.com/toto/db3775edb44f9818c54baa72bbfc8d3d6394b6ef_hsf_evilsquall_slice_single.jpg");
done();
});
it('getFirstTitle in slice zone works', function (done) {
var doc = Prismic.Api("").parseDoc({
"id":"VQ_hV31Za5EAy02H",
"uid":null,
"type":"article",
"href":"http://toto.wroom.dev/api/documents/search?ref=VQ_uWX1Za0oCy46m&q=%5B%5B%3Ad+%3D+at%28document.id%2C+%22VQ_hV31Za5EAy02H%22%29+%5D%5D",
"tags":[],
"slugs":["une-activite"],
"linked_documents":[],
"data":{
"article":{
"blocks":{
"type":"SliceZone",
"value":[{
"type":"Slice",
"slice_type": "features",
"value":{
"type":"Group",
"value":[{
"illustration":{
"type":"Image",
"value":{
"main":{
"url":"https://wroomdev.s3.amazonaws.com/toto/db3775edb44f9818c54baa72bbfc8d3d6394b6ef_hsf_evilsquall_first_in_slice.jpg",
"alt":"",
"copyright":"",
"dimensions":{"width":4285,"height":709}
},
"views":{}
}
},
"title":{
"type":"Text",
"value":"c'est un bloc features"
}
}]
}
},{
"type":"Slice",
"slice_type":"text",
"value":{
"type":"StructuredText",
"value":[
{
type: "heading2",
text: "As seen by fine pastry as a field",
spans: [ ]
},
{
"type":"paragraph",
"text":"C'est un bloc content",
"spans":[]
}
]
}
}]
}
it('getFirstTitle in slice zone works', function (done) {
var doc = Prismic.parseDoc({
"id":"VQ_hV31Za5EAy02H",
"uid":null,
"type":"article",
"href":"http://toto.wroom.dev/api/documents/search?ref=VQ_uWX1Za0oCy46m&q=%5B%5B%3Ad+%3D+at%28document.id%2C+%22VQ_hV31Za5EAy02H%22%29+%5D%5D",
"tags":[],
"slugs":["une-activite"],
"linked_documents":[],
"data":{
"article":{
"blocks":{
"type":"SliceZone",
"value":[{
"type":"Slice",
"slice_type": "features",
"value":{
"type":"Group",
"value":[{
"illustration":{
"type":"Image",
"value":{
"main":{
"url":"https://wroomdev.s3.amazonaws.com/toto/db3775edb44f9818c54baa72bbfc8d3d6394b6ef_hsf_evilsquall_first_in_slice.jpg",
"alt":"",
"copyright":"",
"dimensions":{"width":4285,"height":709}
},
"views":{}
}
}
});
},
"title":{
"type":"Text",
"value":"c'est un bloc features"
}
}]
}
},{
"type":"Slice",
"slice_type":"text",
"value":{
"type":"StructuredText",
"value":[{
type: "heading2",
text: "As seen by fine pastry as a field",
spans: [ ]
}, {
"type":"paragraph",
"text":"C'est un bloc content",
"spans":[]
}]
}
}]
}
}
}
});
var sliceSingleElem = Prismic.Api("").parseDoc({
"id":"VQ_hV31Za5EAy02H",
"uid":null,
"type":"article",
"href":"http://toto.wroom.dev/api/documents/search?ref=VQ_uWX1Za0oCy46m&q=%5B%5B%3Ad+%3D+at%28document.id%2C+%22VQ_hV31Za5EAy02H%22%29+%5D%5D",
"tags":[],
"slugs":["une-activite"],
"linked_documents":[],
"data":{
"article":{
"blocks":{
"type":"SliceZone",
"value":[{
"type":"Slice",
"slice_type": "features",
"value": {
"type":"Image",
"type":"StructuredText",
"value":[
{
type: "heading2",
text: "As seen by fine pastry as a field",
spans: [ ]
},
{
"type":"paragraph",
"text":"C'est un bloc content",
"spans":[]
}]
}
}]
}
}
}
});
var sliceSingleElem = Prismic.parseDoc({
"id":"VQ_hV31Za5EAy02H",
"uid":null,
"type":"article",
"href":"http://toto.wroom.dev/api/documents/search?ref=VQ_uWX1Za0oCy46m&q=%5B%5B%3Ad+%3D+at%28document.id%2C+%22VQ_hV31Za5EAy02H%22%29+%5D%5D",
"tags":[],
"slugs":["une-activite"],
"linked_documents":[],
"data":{
"article":{
"blocks":{
"type":"SliceZone",
"value":[{
"type":"Slice",
"slice_type": "features",
"value": {
"type":"StructuredText",
"value":[{
type: "heading2",
text: "As seen by fine pastry as a field",
spans: [ ]
}, {
"type":"paragraph",
"text":"C'est un bloc content",
"spans":[]
}]
}
}]
}
}
}
});
// Testing get First title on doc level.
assert.equal(doc.getFirstTitle().text, "As seen by fine pastry as a field");
// Testing get First title on doc level.
assert.equal(doc.getFirstTitle().text, "As seen by fine pastry as a field");
var slices = doc.getSliceZone('article.blocks');
assert.equal(slices.getFirstTitle().text, "As seen by fine pastry as a field");
var slices = doc.getSliceZone('article.blocks');
assert.equal(slices.getFirstTitle().text, "As seen by fine pastry as a field");
var slicesWithSingleElem = sliceSingleElem.getSliceZone('article.blocks');
assert.equal(slicesWithSingleElem.getFirstTitle().text, "As seen by fine pastry as a field");
done();
});
var slicesWithSingleElem = sliceSingleElem.getSliceZone('article.blocks');
assert.equal(slicesWithSingleElem.getFirstTitle().text, "As seen by fine pastry as a field");
done();
});
it('getFirstParagraph in slice zone works', function (done) {
var doc = Prismic.Api("").parseDoc({
"id":"VQ_hV31Za5EAy02H",
"uid":null,
"type":"article",
"href":"http://toto.wroom.dev/api/documents/search?ref=VQ_uWX1Za0oCy46m&q=%5B%5B%3Ad+%3D+at%28document.id%2C+%22VQ_hV31Za5EAy02H%22%29+%5D%5D",
"tags":[],
"slugs":["une-activite"],
"linked_documents":[],
"data":{
"article":{
"blocks":{
"type":"SliceZone",
"value":[{
"type":"Slice",
"slice_type": "features",
"value":{
"type":"Group",
"value":[{
"illustration":{
"type":"Image",
"value":{
"main":{
"url":"https://wroomdev.s3.amazonaws.com/toto/db3775edb44f9818c54baa72bbfc8d3d6394b6ef_hsf_evilsquall_first_in_slice.jpg",
"alt":"",
"copyright":"",
"dimensions":{"width":4285,"height":709}
},
"views":{}
}
},
"title":{
"type":"Text",
"value":"c'est un bloc features"
}
}]
}
},{
"type":"Slice",
"slice_type":"text",
"value":{
"type":"StructuredText",
"value":[
{
type: "heading2",
text: "As seen by fine pastry as a field",
spans: [ ]
},
{
"type":"paragraph",
"text":"C'est un bloc content",
"spans":[]
}
]
}
}]
}
it('getFirstParagraph in slice zone works', function (done) {
var doc = Prismic.parseDoc({
"id":"VQ_hV31Za5EAy02H",
"uid":null,
"type":"article",
"href":"http://toto.wroom.dev/api/documents/search?ref=VQ_uWX1Za0oCy46m&q=%5B%5B%3Ad+%3D+at%28document.id%2C+%22VQ_hV31Za5EAy02H%22%29+%5D%5D",
"tags":[],
"slugs":["une-activite"],
"linked_documents":[],
"data":{
"article":{
"blocks":{
"type":"SliceZone",
"value":[{
"type":"Slice",
"slice_type": "features",
"value":{
"type":"Group",
"value":[{
"illustration":{
"type":"Image",
"value":{
"main":{
"url":"https://wroomdev.s3.amazonaws.com/toto/db3775edb44f9818c54baa72bbfc8d3d6394b6ef_hsf_evilsquall_first_in_slice.jpg",
"alt":"",
"copyright":"",
"dimensions":{"width":4285,"height":709}
},
"views":{}
}
}
});
},
"title":{
"type":"Text",
"value":"c'est un bloc features"
}
}]
}
},{
"type":"Slice",
"slice_type":"text",
"value":{
"type":"StructuredText",
"value":[{
type: "heading2",
text: "As seen by fine pastry as a field",
spans: [ ]
}, {
"type":"paragraph",
"text":"C'est un bloc content",
"spans":[]
}]
}
}]
}
}
}
});
var sliceSingleElem = Prismic.Api("").parseDoc({
"id":"VQ_hV31Za5EAy02H",
"uid":null,
"type":"article",
"href":"http://toto.wroom.dev/api/documents/search?ref=VQ_uWX1Za0oCy46m&q=%5B%5B%3Ad+%3D+at%28document.id%2C+%22VQ_hV31Za5EAy02H%22%29+%5D%5D",
"tags":[],
"slugs":["une-activite"],
"linked_documents":[],
"data":{
"article":{
"blocks":{
"type":"SliceZone",
"value":[{
"type":"Slice",
"slice_type": "features",
"value": {
"type":"Image",
"type":"StructuredText",
"value":[
{
type: "heading2",
text: "As seen by fine pastry as a field",
spans: [ ]
},
{
"type":"paragraph",
"text":"C'est un bloc content",
"spans":[]
}]
}
}]
}
}
}
});
var sliceSingleElem = Prismic.parseDoc({
"id":"VQ_hV31Za5EAy02H",
"uid":null,
"type":"article",
"href":"http://toto.wroom.dev/api/documents/search?ref=VQ_uWX1Za0oCy46m&q=%5B%5B%3Ad+%3D+at%28document.id%2C+%22VQ_hV31Za5EAy02H%22%29+%5D%5D",
"tags":[],
"slugs":["une-activite"],
"linked_documents":[],
"data":{
"article":{
"blocks":{
"type":"SliceZone",
"value":[{
"type":"Slice",
"slice_type": "features",
"value": {
"type":"StructuredText",
"value":[{
type: "heading2",
text: "As seen by fine pastry as a field",
spans: [ ]
}, {
"type":"paragraph",
"text":"C'est un bloc content",
"spans":[]
}]
}
}]
}
}
}
});
// Testing get First paragraph on doc level.
assert.equal(doc.getFirstParagraph().text, "C'est un bloc content");
// Testing get First paragraph on doc level.
assert.equal(doc.getFirstParagraph().text, "C'est un bloc content");
var slices = doc.getSliceZone('article.blocks');
assert.equal(slices.getFirstParagraph().text, "C'est un bloc content");
var slicesWithSingleElem = sliceSingleElem.getSliceZone('article.blocks');
assert.equal(slicesWithSingleElem.getFirstParagraph().text, "C'est un bloc content");
done();
});
var slices = doc.getSliceZone('article.blocks');
assert.equal(slices.getFirstParagraph().text, "C'est un bloc content");
var slicesWithSingleElem = sliceSingleElem.getSliceZone('article.blocks');
assert.equal(slicesWithSingleElem.getFirstParagraph().text, "C'est un bloc content");
done();
});
});
});
describe('StructuredText', function() {
describe('StructuredText', function() {
it('asHtml handles embeds and lists', function (done) {
Prismic.Api(testRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').query('[[:d = at(document.id, "UlfoxUnM0wkXYXbX")]]').ref(Api.master()).submit(function (err, documents) {
if (err) throw err;
assert.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>');
done();
});
}, previewToken);
});
it('asHtml handles embeds and lists', function (done) {
Prismic.api(testRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').query('[[:d = at(document.id, "UlfoxUnM0wkXYXbX")]]').ref(Api.master()).submit(function (err, documents) {
if (err) throw err;
assert.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>'
);
done();
});
}, previewToken);
});
it('asText works', function (done) {
Prismic.Api(testRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').query('[[:d = at(document.id, "UlfoxUnM0wkXYXbX")]]').ref(Api.master()).submit(function (err, documents) {
if (err) throw err;
assert.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.");
done();
});
}, previewToken);
});
it('asText works', function (done) {
Prismic.api(testRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').query('[[:d = at(document.id, "UlfoxUnM0wkXYXbX")]]').ref(Api.master()).submit(function (err, documents) {
if (err) throw err;
assert.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.");
done();
});
}, previewToken);
});
it('asHtml handles preformatted', function (done) {
Prismic.Api(microRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').query('[[:d = at(document.id, "UrDejAEAAFwMyrW9")]]').ref(Api.master()).submit(function (err, documents) {
if (err) throw err;
assert.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>');
done();
});
});
});
it('asHtml handles preformatted', function (done) {
Prismic.api(microRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').query('[[:d = at(document.id, "UrDejAEAAFwMyrW9")]]').ref(Api.master()).submit(function (err, documents) {
if (err) throw err;
assert.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>'
);
done();
});
});
});
it('Test backward-compatibility with passing a ctx instead of just a linkResolver', function (done) {
Prismic.Api(microRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').query('[[:d = at(document.id, "UrDejAEAAFwMyrW9")]]').ref(Api.master()).submit(function (err, documents) {
if (err) throw err;
assert.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>');
done();
});
});
});
it('Test backward-compatibility with passing a ctx instead of just a linkResolver', function (done) {
Prismic.api(microRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').query('[[:d = at(document.id, "UrDejAEAAFwMyrW9")]]').ref(Api.master()).submit(function (err, documents) {
if (err) throw err;
assert.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>');
done();
});
});
});
it('asHtml handles spans', function (done) {
Prismic.Api(testRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').query('[[:d = at(document.id, "UlfoxUnM0wkXYXbt")]]').ref(Api.master()).submit(function (err, documents) {
if (err) throw err;
assert.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>');
done();
});
}, previewToken);
});
it('asHtml handles spans', function (done) {
Prismic.api(testRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').query('[[:d = at(document.id, "UlfoxUnM0wkXYXbt")]]').ref(Api.master()).submit(function (err, documents) {
if (err) throw err;
assert.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>');
done();
});
}, previewToken);
});
it('asHtml handles span Link.web', function (done) {
Prismic.Api(testRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').query('[[:d = at(document.id, "UlfoxUnM0wkXYXbW")]]').ref(Api.master()).submit(function (err, documents) {
if (err) throw err;
assert.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>');
done();
});
}, previewToken);
});
it('asHtml handles span Link.web', function (done) {
Prismic.api(testRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').query('[[:d = at(document.id, "UlfoxUnM0wkXYXbW")]]').ref(Api.master()).submit(function (err, documents) {
if (err) throw err;
assert.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>');
done();
});
}, previewToken);
});
it('asHtml handles span Link.document', function (done) {
Prismic.Api(testRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').query('[[:d = at(document.id, "UlfoxUnM0wkXYXbl")]]').ref(Api.master()).submit(function (err, documents) {
if (err) throw err;
assert.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>');
done();
});
}, previewToken);
});
it('asHtml handles span Link.document', function (done) {
Prismic.api(testRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').query('[[:d = at(document.id, "UlfoxUnM0wkXYXbl")]]').ref(Api.master()).submit(function (err, documents) {
if (err) throw err;
assert.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>');
done();
});
}, previewToken);
});
it('asHtml with custom serializer', function (done) {
Prismic.Api(testRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').query('[[:d = at(document.id, "UlfoxUnM0wkXYXbl")]]').ref(Api.master()).submit(function (err, documents) {
if (err) throw err;
var htmlSerializer = function (element, content) {
if (element.type == "image") {
return '<img src="' + element.url + '" alt="' + element.alt + '">';
}
it('asHtml with custom serializer', function (done) {
Prismic.api(testRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').query('[[:d = at(document.id, "UlfoxUnM0wkXYXbl")]]').ref(Api.master()).submit(function (err, documents) {
if (err) throw err;
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>';
}
if (element.type == "hyperlink") {
return '<a class="some-link" href="' + element.url + '">' + content + '</a>';
}
return null;
};
assert.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>');
done();
});
}, previewToken);
});
return null;
};
assert.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>'
);
done();
});
}, previewToken);
});
it('getFirstImage works', function (done) {
Prismic.Api(testRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').query('[[:d = at(document.id, "UlfoxUnM0wkXYXbl")]]').ref(Api.master()).submit(function (err, documents) {
assert.equal(documents.results[0].getStructuredText('blog-post.body').getFirstImage().url, "https://prismic-io.s3.amazonaws.com/lesbonneschoses/c38f9e5a1a6c43aa7aae516c154013a2cee2bc75.jpg");
assert.equal(documents.results[0].getStructuredText('blog-post.body').getFirstImage().alt, "");
assert.equal(documents.results[0].getStructuredText('blog-post.body').getFirstImage().height, 427);
assert.equal(documents.results[0].getStructuredText('blog-post.body').getFirstImage().width, 640);
assert.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="">');
done();
});
}, previewToken);
});
it('getFirstImage works', function (done) {
Prismic.api(testRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').query('[[:d = at(document.id, "UlfoxUnM0wkXYXbl")]]').ref(Api.master()).submit(function (err, documents) {
assert.equal(documents.results[0].getStructuredText('blog-post.body').getFirstImage().url, "https://prismic-io.s3.amazonaws.com/lesbonneschoses/c38f9e5a1a6c43aa7aae516c154013a2cee2bc75.jpg");
assert.equal(documents.results[0].getStructuredText('blog-post.body').getFirstImage().alt, "");
assert.equal(documents.results[0].getStructuredText('blog-post.body').getFirstImage().height, 427);
assert.equal(documents.results[0].getStructuredText('blog-post.body').getFirstImage().width, 640);
assert.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="">');
done();
});
}, previewToken);
});
it('asHtml handles span Link.file', 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);
assert.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>');
});
it('asHtml handles span Link.file', 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);
assert.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>');
});
it('Proper escaping in asHtml', function (done) {
var jsonString = "{ \"type\": \"StructuredText\", \"value\": [ { \"type\": \"paragraph\", \"text\": \"<not a real tag>\\nsome text\", \"spans\": [] } ]}";
var jsonObject = JSON.parse(jsonString);
var text = Prismic.Fragments.initField(jsonObject);
assert.equal(
text.asHtml(),
"<p>&lt;not a real tag&gt;<br>some text</p>"
);
done();
});
it('Proper escaping in asHtml', function (done) {
var jsonString = "{ \"type\": \"StructuredText\", \"value\": [ { \"type\": \"paragraph\", \"text\": \"<not a real tag>\\nsome text\", \"spans\": [] } ]}";
var jsonObject = JSON.parse(jsonString);
var text = Prismic.Fragments.initField(jsonObject);
assert.equal(
text.asHtml(),
"<p>&lt;not a real tag&gt;<br>some text</p>"
);
done();
});
});
});
describe('Various fragment types', function() {
describe('Various fragment types', function() {
it('Handles multiple fields', function (done) {
Prismic.Api(testRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').query('[[:d = at(document.id, "UlfoxUnM0wkXYXbX")]]').ref(Api.master()).submit(function (err, documents) {
if (err) throw err;
assert.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>');
done();
});
}, previewToken);
});
it('Handles multiple fields', function (done) {
Prismic.api(testRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').query('[[:d = at(document.id, "UlfoxUnM0wkXYXbX")]]').ref(Api.master()).submit(function (err, documents) {
if (err) throw err;
assert.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>');
done();
});
}, previewToken);
});
it('ImageViews are well retrieved', function (done) {
Prismic.Api(testRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').query('[[:d = at(document.id, "UlfoxUnM0wkXYXbO")]]').ref(Api.master()).submit(function (err, documents) {
if (err) throw err;
assert.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="">');
assert.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="">');
done();
});
}, previewToken);
});
it('ImageViews are well retrieved', function (done) {
Prismic.api(testRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').query('[[:d = at(document.id, "UlfoxUnM0wkXYXbO")]]').ref(Api.master()).submit(function (err, documents) {
if (err) throw err;
assert.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="">');
assert.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="">');
done();
});
}, previewToken);
});
it('GeoPoint is retrieved', function (done) {
Prismic.Api(microRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').query('[[:d = at(document.id, "U9pjvjQAADAAehbf")]]').ref(Api.master()).submit(function (err, documents) {
if (err) throw err;
var html = '<div class="geopoint"><span class="latitude">48.87687670000001</span><span class="longitude">2.3338801999999825</span></div>';
assert.equal(documents.results[0].getGeoPoint('contributor.location').asHtml(), html);
done();
});
});
});
it('GeoPoint is retrieved', function (done) {
Prismic.api(microRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').query('[[:d = at(document.id, "U9pjvjQAADAAehbf")]]').ref(Api.master()).submit(function (err, documents) {
if (err) throw err;
var html = '<div class="geopoint"><span class="latitude">48.87687670000001</span><span class="longitude">2.3338801999999825</span></div>';
assert.equal(documents.results[0].getGeoPoint('contributor.location').asHtml(), html);
done();
});
});
});
it('Date and Timestamp are parsed correctly', function () {
var json = JSON.parse('{ "id": "UlfoxUnM0wkXYXbm", "type": "blog-post", "href": "https://lesbonneschoses-vcerzcwaaohojzo.prismic.io/api/documents/...",' +
'"tags": [], "slugs": [], "linked_documents": [],' +
'"data": { "blog-post": {' +
'"date": { "type": "Date", "value": "2013-08-17" },' +
'"timestamp": { "type": "Timestamp", "value": "2014-10-06T12:24:36+0000" } ' +
'}}}');
var doc = Prismic.Api("").parseDoc(json);
var date = doc.getDate("blog-post.date");
assert.equal(date.getFullYear(), 2013);
var ts = doc.getTimestamp("blog-post.timestamp");
assert.equal(ts.getFullYear(), 2014);
});
it('Date and Timestamp are parsed correctly', function () {
var json = JSON.parse('{ "id": "UlfoxUnM0wkXYXbm", "type": "blog-post", "href": "https://lesbonneschoses-vcerzcwaaohojzo.prismic.io/api/documents/...",' +
'"tags": [], "slugs": [], "linked_documents": [],' +
'"data": { "blog-post": {' +
'"date": { "type": "Date", "value": "2013-08-17" },' +
'"timestamp": { "type": "Timestamp", "value": "2014-10-06T12:24:36+0000" } ' +
'}}}');
var doc = Prismic.parseDoc(json);
var date = doc.getDate("blog-post.date");
assert.equal(date.getFullYear(), 2013);
var ts = doc.getTimestamp("blog-post.timestamp");
assert.equal(ts.getFullYear(), 2014);
});
it('Block fragments are accessible, loopable, and serializable', function (done) {
Prismic.Api(microRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').query('[[:d = at(document.id, "UrDndQEAALQMyrXF")]]').ref(Api.master()).submit(function (err, documents) {
if (err) throw err;
// Group fragments are accessible
assert.equal(documents.results[0].getGroup('docchapter.docs').toArray()[0].getLink('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].getLink('linktodoc').value.document.slug + ' ';
}
assert.equal(slugs.trim(), 'with-jquery with-bootstrap');
// Group fragments are serializable when asHtml is called directly on them
assert.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
assert.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>');
done();
});
});
});
it('Block fragments are accessible, loopable, and serializable', function (done) {
Prismic.api(microRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').query('[[:d = at(document.id, "UrDndQEAALQMyrXF")]]').ref(Api.master()).submit(function (err, documents) {
if (err) throw err;
// Group fragments are accessible
assert.equal(documents.results[0].getGroup('docchapter.docs').toArray()[0].getLink('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].getLink('linktodoc').value.document.slug + ' ';
}
assert.equal(slugs.trim(), 'with-jquery with-bootstrap');
// Group fragments are serializable when asHtml is called directly on them
assert.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
assert.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>');
done();
});
});
});
it('Slices correctly parsed and serializable', function () {
var doc = Prismic.Api("").parseDoc({
"id":"VQ_hV31Za5EAy02H",
"uid":null,
"type":"article",
"href":"http://toto.wroom.dev/api/documents/search?ref=VQ_uWX1Za0oCy46m&q=%5B%5B%3Ad+%3D+at%28document.id%2C+%22VQ_hV31Za5EAy02H%22%29+%5D%5D",
"tags":[],
"slugs":["une-activite"],
"linked_documents":[],
"data":{
"article":{
"activities":{
"type":"Group",
"value":[{
"title":{
"type":"StructuredText",
"value":[{
"type":"paragraph",
"text":"Une activité",
"spans":[]
}]
},
"image":{
"type":"Image",
"value":{
"main":{
"url":"https://wroomdev.s3.amazonaws.com/toto/ce3f52b933c4934a13422e09ed0ff6ad03a29621_hsf_evilsquall.jpg",
"alt":"",
"copyright":"",
"dimensions":{"width":860,"height":640}
},
"views":{
"headline":{
"url":"https://wroomdev.s3.amazonaws.com/toto/5445d2dcd2b0c541b0406ca867ab3d07b309c944_hsf_evilsquall.jpg",
"alt":"",
"copyright":"",
"dimensions":{"width":570,"height":400}
}
}
}
},
"body":{
"type":"StructuredText",
"value":[{
"type":"paragraph",
"text":"elle est bien",
"spans":[]
}]
}
}]
},
"un_champ_texte":{
"type":"Text",
"value":"stuffgg"
},
"blocks":{
"type":"SliceZone",
"value":[{
"type":"Slice",
"slice_type": "features",
"value":{
"type":"Group",
"value":[{
"illustration":{
"type":"Image",
"value":{
"main":{
"url":"https://wroomdev.s3.amazonaws.com/toto/db3775edb44f9818c54baa72bbfc8d3d6394b6ef_hsf_evilsquall.jpg",
"alt":"",
"copyright":"",
"dimensions":{"width":4285,"height":709}
},
"views":{}
}
},
"title":{
"type":"Text",
"value":"c'est un bloc features"
}
}]
}
},{
"type":"Slice",
"slice_type":"text",
"value":{
"type":"StructuredText",
"value":[{
"type":"paragraph",
"text":"C'est un bloc content",
"spans":[]
}]
}
}]
}
it('Slices correctly parsed and serializable', function () {
var doc = Prismic.parseDoc({
"id":"VQ_hV31Za5EAy02H",
"uid":null,
"type":"article",
"href":"http://toto.wroom.dev/api/documents/search?ref=VQ_uWX1Za0oCy46m&q=%5B%5B%3Ad+%3D+at%28document.id%2C+%22VQ_hV31Za5EAy02H%22%29+%5D%5D",
"tags":[],
"slugs":["une-activite"],
"linked_documents":[],
"data":{
"article":{
"activities":{
"type":"Group",
"value":[{
"title":{
"type":"StructuredText",
"value":[{
"type":"paragraph",
"text":"Une activité",
"spans":[]
}]
},
"image":{
"type":"Image",
"value":{
"main":{
"url":"https://wroomdev.s3.amazonaws.com/toto/ce3f52b933c4934a13422e09ed0ff6ad03a29621_hsf_evilsquall.jpg",
"alt":"",
"copyright":"",
"dimensions":{"width":860,"height":640}
},
"views":{
"headline":{
"url":"https://wroomdev.s3.amazonaws.com/toto/5445d2dcd2b0c541b0406ca867ab3d07b309c944_hsf_evilsquall.jpg",
"alt":"",
"copyright":"",
"dimensions":{"width":570,"height":400}
}
}
}
});
var slices = doc.getSliceZone('article.blocks');
assert.equal(slices.asText(getLinkResolver()), "c'est un bloc features\n\nC'est un bloc content\n");
assert.equal(slices.asHtml(getLinkResolver()), '<div data-slicetype="features" class="slice"><section data-field="illustration"><img src="https://wroomdev.s3.amazonaws.com/toto/db3775edb44f9818c54baa72bbfc8d3d6394b6ef_hsf_evilsquall.jpg" width="4285" height="709" alt=""></section><section data-field="title"><span>c\'est un bloc features</span></section></div><div data-slicetype="text" class="slice"><p>C\'est un bloc content</p></div>');
});
},
"body":{
"type":"StructuredText",
"value":[{
"type":"paragraph",
"text":"elle est bien",
"spans":[]
}]
}
}]
},
"un_champ_texte":{
"type":"Text",
"value":"stuffgg"
},
"blocks":{
"type":"SliceZone",
"value":[{
"type":"Slice",
"slice_type": "features",
"value":{
"type":"Group",
"value":[{
"illustration":{
"type":"Image",
"value":{
"main":{
"url":"https://wroomdev.s3.amazonaws.com/toto/db3775edb44f9818c54baa72bbfc8d3d6394b6ef_hsf_evilsquall.jpg",
"alt":"",
"copyright":"",
"dimensions":{"width":4285,"height":709}
},
"views":{}
}
},
"title":{
"type":"Text",
"value":"c'est un bloc features"
}
}]
}
},{
"type":"Slice",
"slice_type":"text",
"value":{
"type":"StructuredText",
"value":[{
"type":"paragraph",
"text":"C'est un bloc content",
"spans":[]
}]
}
}]
}
}
}
});
}(window.Prismic));
var slices = doc.getSliceZone('article.blocks');
assert.equal(slices.asText(getLinkResolver()), "c'est un bloc features\n\nC'est un bloc content\n");
assert.equal(slices.asHtml(getLinkResolver()), '<div data-slicetype="features" class="slice"><section data-field="illustration"><img src="https://wroomdev.s3.amazonaws.com/toto/db3775edb44f9818c54baa72bbfc8d3d6394b6ef_hsf_evilsquall.jpg" width="4285" height="709" alt=""></section><section data-field="title"><span>c\'est un bloc features</span></section></div><div data-slicetype="text" class="slice"><p>C\'est un bloc content</p></div>');
});
});

@@ -1,436 +0,450 @@

(function(Prismic) {
/*eslint-env node, mocha */
/*eslint no-unused-vars: 0 */
var assert = chai.assert;
var Prismic = require('../lib/prismic.js').Prismic;
var chai = require('chai');
/* === TESTS ARE RUN OVER "LES BONNES CHOSES" EXAMPLE REPOSITORY === */
var assert = chai.assert;
var testRepository = 'https://lesbonneschoses.prismic.io/api',
previewToken = 'MC5VbDdXQmtuTTB6Z0hNWHF3.c--_vVbvv73vv73vv73vv71EA--_vS_vv73vv70T77-9Ke-_ve-_vWfvv70ebO-_ve-_ve-_vQN377-9ce-_vRfvv70',
microRepository = 'https://micro.prismic.io/api',
Predicates = Prismic.Predicates;
/* === TESTS ARE RUN OVER "LES BONNES CHOSES" EXAMPLE REPOSITORY === */
describe('API retrieval and parsing', function(){
var testRepository = 'https://lesbonneschoses.prismic.io/api',
previewToken = 'MC5VbDdXQmtuTTB6Z0hNWHF3.c--_vVbvv73vv73vv73vv71EA--_vS_vv73vv70T77-9Ke-_ve-_vWfvv70ebO-_ve-_ve-_vQN377-9ce-_vRfvv70',
microRepository = 'https://micro.prismic.io/api',
Predicates = Prismic.Predicates;
it('Retrieve the API', function(done) {
Prismic.Api(testRepository, function(err, Api) {
if (err) throw err;
assert.operator(Api.data.refs.length, '>', 0, 'at least one reference');
assert.equal(Api.url, testRepository);
done();
});
});
describe('API retrieval and parsing', function(){
it('Correctly handles the error if the URL is wrong', function(done) {
console.log('\n*** Note by tester: The following error is a "normal" error (see note in test.js): ');
// We can't help it because whatever you do, the JS engine contains a "console.error" statement when this error occurs,
// and we're exactly trying to test how the kit reacts when this error occurs.
Prismic.Api(testRepository+"/errormaker", function(err, Api) {
assert.equal(err.message, "Unexpected status code [0] on URL https://lesbonneschoses.prismic.io/api/errormaker");
done();
});
});
it('Retrieve the API', function(done) {
Prismic.api(testRepository, function(err, Api) {
if (err) throw err;
assert.operator(Api.data.refs.length, '>', 0, 'at least one reference');
assert.equal(Api.url, testRepository);
done();
});
});
it('Parsing stores types and tags', function(done) {
Prismic.Api(testRepository, function(err, Api) {
if (err) throw err;
assert.equal(Object.keys(Api.data.types).length, 6);
assert.equal(Api.data.tags.length, 4);
done();
});
});
it('Retrieve the API with a Promise', function(done) {
Prismic.api(testRepository).then(function(api) {
assert.operator(api.data.refs.length, '>', 0, 'at least one reference');
assert.equal(api.url, testRepository);
done();
}, function(err) {
throw err;
});
});
it('Retrieve the API with master+releases privilege', function(done) {
Prismic.Api(testRepository, function(err, Api) {
if (err) throw err;
assert.equal(Api.data.refs.length, 3);
done();
}, previewToken);
});
it('Correctly handles the error if the URL is wrong', function(done) {
console.log('\n*** Note by tester: The following error is a "normal" error (see note in test.js): ');
// We can't help it because whatever you do, the JS engine contains a "console.error" statement when this error occurs,
// and we're exactly trying to test how the kit reacts when this error occurs.
Prismic.api(testRepository+"/errormaker", function(err, Api) {
assert.equal(err.message, "Unexpected status code [404] on URL https://lesbonneschoses.prismic.io/api/errormaker");
done();
});
});
describe('API form submissions', function() {
it('Parsing stores types and tags', function(done) {
Prismic.api(testRepository, function(err, Api) {
if (err) throw err;
assert.equal(Object.keys(Api.data.types).length, 6);
assert.equal(Api.data.tags.length, 4);
done();
});
});
it('Submit the `everything` form', function (done) {
Prismic.Api(testRepository, function (err, Api) {
if (err) {
console.log(err);
done();
}
Api.form('everything').ref(Api.master()).submit(function (err, documents) {
if (err) {
console.log(err);
return;
}
assert.equal(documents.results.length, 20);
assert.equal(documents.next_page, "https://lesbonneschoses.prismic.io/api/documents/search?ref=UlfoxUnM08QWYXdl&page=2&pageSize=20");
assert.equal(documents.page, 1);
assert.equal(documents.prev_page, null);
assert.equal(documents.results_per_page, 20);
assert.equal(documents.results_size, 20);
assert.equal(documents.total_pages, 2);
assert.equal(documents.total_results_size, 40);
done();
});
});
});
it('Retrieve the API with master+releases privilege', function(done) {
Prismic.api(testRepository, function(err, Api) {
if (err) throw err;
assert.equal(Api.data.refs.length, 3);
done();
}, previewToken);
});
});
it('Get linked documents', function (done) {
Prismic.Api(microRepository, function (err, Api) {
if (err) {
console.log(err);
done();
}
Api.form('everything').query('[[:d = any(document.type, ["doc","docchapter"])]]').ref(Api.master()).submit(function (err, response) {
if (err) {
console.log(err);
return;
}
var document = response.results[0];
assert.equal(document.linkedDocuments().length, 1);
assert.equal(document.linkedDocuments()[0].id, 'U0w8OwEAACoAQEvB');
done();
});
});
});
describe('API form submissions', function() {
it('Use an Array to query', function (done) {
Prismic.Api(microRepository, function (err, Api) {
if (err) {
console.log(err);
done();
}
Api.form('everything')
.query(Predicates.any("document.type", ["doc", "docchapter"]))
.ref(Api.master())
.submit(function (err, response) {
if (err) { console.log(err);
}
var document = response.results[0];
assert.equal(document.linkedDocuments().length, 1);
assert.equal(document.linkedDocuments()[0].id, 'U0w8OwEAACoAQEvB');
done();
});
});
});
it('Submit the `everything` form', function (done) {
Prismic.api(testRepository, function (err, Api) {
if (err) {
console.log(err);
done();
}
Api.form('everything').ref(Api.master()).submit(function (err, documents) {
if (err) {
console.log(err);
return;
}
assert.equal(documents.results.length, 20);
assert.equal(documents.next_page, "https://lesbonneschoses.prismic.io/api/documents/search?ref=UlfoxUnM08QWYXdl&page=2&pageSize=20");
assert.equal(documents.page, 1);
assert.equal(documents.prev_page, null);
assert.equal(documents.results_per_page, 20);
assert.equal(documents.results_size, 20);
assert.equal(documents.total_pages, 2);
assert.equal(documents.total_results_size, 40);
done();
});
});
});
it('Use getByID', function(done) {
Prismic.Api(testRepository, function (err, Api) {
if (err) throw err;
Api.getByID('UlfoxUnM0wkXYXbt', {}, function (err, document) {
assert.equal(document.id, 'UlfoxUnM0wkXYXbt');
done();
});
});
});
it('Get linked documents', function (done) {
Prismic.api(microRepository, function (err, Api) {
if (err) {
console.log(err);
done();
}
Api.form('everything').query('[[:d = any(document.type, ["doc","docchapter"])]]').ref(Api.master()).submit(function (err, response) {
if (err) {
console.log(err);
return;
}
var document = response.results[0];
assert.equal(document.linkedDocuments().length, 1);
assert.equal(document.linkedDocuments()[0].id, 'U0w8OwEAACoAQEvB');
done();
});
});
});
it('Use getByIDs', function(done) {
Prismic.Api(testRepository, function (err, Api) {
if (err) throw err;
Api.getByIDs(['UlfoxUnM0wkXYXbt', 'UlfoxUnM0wkXYXbj'], {}, function (err, res) {
assert.equal(res.results.length, 2);
done();
});
});
it('Use an Array to query', function (done) {
Prismic.api(microRepository, function (err, Api) {
if (err) {
console.log(err);
done();
}
Api.form('everything')
.query(Predicates.any("document.type", ["doc", "docchapter"]))
.ref(Api.master())
.submit(function (err, response) {
if (err) {
console.log(err);
}
var document = response.results[0];
assert.equal(document.linkedDocuments().length, 1);
assert.equal(document.linkedDocuments()[0].id, 'U0w8OwEAACoAQEvB');
done();
});
});
});
it('Submit the `everything` form with an ordering', function (done) {
Prismic.Api(testRepository, function (err, Api) {
if (err) {
console.log(err);
done();
}
Api.form('everything').ref(Api.master()).orderings('[my.product.price desc]').submit(function (err, documents) {
if (err) { console.log(err); }
assert.equal(documents.results.length, 20);
assert.equal(documents.results[0].id, 'UlfoxUnM0wkXYXbj');
done();
});
});
});
it('Use getByID', function(done) {
Prismic.api(testRepository, function (err, Api) {
if (err) throw err;
Api.getByID('UlfoxUnM0wkXYXbt', {}, function (err, document) {
assert.equal(document.id, 'UlfoxUnM0wkXYXbt');
done();
});
});
});
it('Submit with an ordering array', function(done) {
Prismic.Api(testRepository, function (err, Api) {
if (err) {
console.log(err);
done();
}
Api.form('everything').ref(Api.master()).orderings(['my.product.price desc']).submit(function (err, documents) {
if (err) {
console.log(err);
}
assert.equal(documents.results.length, 20);
assert.equal(documents.results[0].id, 'UlfoxUnM0wkXYXbj');
done();
});
});
});
it('Use getByIDs', function(done) {
Prismic.api(testRepository, function (err, Api) {
if (err) throw err;
Api.getByIDs(['UlfoxUnM0wkXYXbt', 'UlfoxUnM0wkXYXbj'], {}, function (err, res) {
assert.equal(res.results.length, 2);
done();
});
});
});
it('Get page 2 of the `everything` form', function (done) {
Prismic.Api(testRepository, function (err, Api) {
if (err) {
console.log(err);
done();
}
Api.form('everything').page(2).ref(Api.master()).submit(function (err, documents) {
if (err) {
console.log(err);
return;
}
assert.equal(documents.results.length, 20);
assert.equal(documents.next_page, null);
assert.equal(documents.page, 2);
assert.equal(documents.prev_page, "https://lesbonneschoses.prismic.io/api/documents/search?ref=UlfoxUnM08QWYXdl&page=1&pageSize=20");
assert.equal(documents.results_per_page, 20);
assert.equal(documents.results_size, 20);
assert.equal(documents.total_pages, 2);
assert.equal(documents.total_results_size, 40);
done();
});
});
});
it('Submit the `everything` form with an ordering', function (done) {
Prismic.api(testRepository, function (err, Api) {
if (err) {
console.log(err);
done();
}
Api.form('everything').ref(Api.master()).orderings('[my.product.price desc]').submit(function (err, documents) {
if (err) { console.log(err); }
assert.equal(documents.results.length, 20);
assert.equal(documents.results[0].id, 'UlfoxUnM0wkXYXbj');
done();
});
});
});
it('Get page 1 of the `everything` form with pagination set at 10', function (done) {
Prismic.Api(testRepository, function (err, Api) {
if (err) {
console.log(err);
done();
}
Api.form('everything').pageSize(10).ref(Api.master()).submit(function (err, documents) {
if (err) throw err;
assert.equal(documents.results.length, 10);
assert.equal(documents.next_page, "https://lesbonneschoses.prismic.io/api/documents/search?ref=UlfoxUnM08QWYXdl&page=2&pageSize=10");
assert.equal(documents.page, 1);
assert.equal(documents.prev_page, null);
assert.equal(documents.results_per_page, 10);
assert.equal(documents.results_size, 10);
assert.equal(documents.total_pages, 4);
assert.equal(documents.total_results_size, 40);
done();
});
});
});
it('Submit with an ordering array', function(done) {
Prismic.api(testRepository, function (err, Api) {
if (err) {
console.log(err);
done();
}
Api.form('everything').ref(Api.master()).orderings(['my.product.price desc']).submit(function (err, documents) {
if (err) {
console.log(err);
}
assert.equal(documents.results.length, 20);
assert.equal(documents.results[0].id, 'UlfoxUnM0wkXYXbj');
done();
});
});
});
it('Get page 2 of the `everything` form with pagination set at 10', function (done) {
Prismic.Api(testRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').pageSize(10).page(2).ref(Api.master()).submit(function (err, documents) {
if (err) {
console.log(err);
return;
}
assert.equal(documents.results.length, 10);
assert.equal(documents.next_page, "https://lesbonneschoses.prismic.io/api/documents/search?ref=UlfoxUnM08QWYXdl&page=3&pageSize=10");
assert.equal(documents.page, 2);
assert.equal(documents.prev_page, "https://lesbonneschoses.prismic.io/api/documents/search?ref=UlfoxUnM08QWYXdl&page=1&pageSize=10");
assert.equal(documents.results_per_page, 10);
assert.equal(documents.results_size, 10);
assert.equal(documents.total_pages, 4);
assert.equal(documents.total_results_size, 40);
done();
});
});
});
it('Get page 2 of the `everything` form', function (done) {
Prismic.api(testRepository, function (err, Api) {
if (err) {
console.log(err);
done();
}
Api.form('everything').page(2).ref(Api.master()).submit(function (err, documents) {
if (err) {
console.log(err);
return;
}
assert.equal(documents.results.length, 20);
assert.equal(documents.next_page, null);
assert.equal(documents.page, 2);
assert.equal(documents.prev_page, "https://lesbonneschoses.prismic.io/api/documents/search?ref=UlfoxUnM08QWYXdl&page=1&pageSize=20");
assert.equal(documents.results_per_page, 20);
assert.equal(documents.results_size, 20);
assert.equal(documents.total_pages, 2);
assert.equal(documents.total_results_size, 40);
done();
});
});
});
it('Correctly handles the error if wrong submission', function (done) {
Prismic.Api(testRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').ref(Api.master()).query("wrongpredicate").submit(function (err, _) {
assert.equal(err.message, "Unexpected status code [400] on URL https://lesbonneschoses.prismic.io/api/documents/search?page=1&pageSize=20&ref=UlfoxUnM08QWYXdl&q=wrongpredicate");
done();
});
});
});
it('Get page 1 of the `everything` form with pagination set at 10', function (done) {
Prismic.api(testRepository, function (err, Api) {
if (err) {
console.log(err);
done();
}
Api.form('everything').pageSize(10).ref(Api.master()).submit(function (err, documents) {
if (err) throw err;
assert.equal(documents.results.length, 10);
assert.equal(documents.next_page, "https://lesbonneschoses.prismic.io/api/documents/search?ref=UlfoxUnM08QWYXdl&page=2&pageSize=10");
assert.equal(documents.page, 1);
assert.equal(documents.prev_page, null);
assert.equal(documents.results_per_page, 10);
assert.equal(documents.results_size, 10);
assert.equal(documents.total_pages, 4);
assert.equal(documents.total_results_size, 40);
done();
});
});
});
it('Submit the `everything` form with a predicate', function (done) {
Prismic.Api(testRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').ref(Api.master()).query(["at", "document.type", "product"]).submit(function (err, documents) {
if (err) {
console.log(err);
return;
}
assert.equal(documents.results.length, 16);
done();
});
});
});
it('Get page 2 of the `everything` form with pagination set at 10', function (done) {
Prismic.api(testRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').pageSize(10).page(2).ref(Api.master()).submit(function (err, documents) {
if (err) {
console.log(err);
return;
}
assert.equal(documents.results.length, 10);
assert.equal(documents.next_page, "https://lesbonneschoses.prismic.io/api/documents/search?ref=UlfoxUnM08QWYXdl&page=3&pageSize=10");
assert.equal(documents.page, 2);
assert.equal(documents.prev_page, "https://lesbonneschoses.prismic.io/api/documents/search?ref=UlfoxUnM08QWYXdl&page=1&pageSize=10");
assert.equal(documents.results_per_page, 10);
assert.equal(documents.results_size, 10);
assert.equal(documents.total_pages, 4);
assert.equal(documents.total_results_size, 40);
done();
});
});
});
it('Submit the `everything` form with a predicate that give no results', function (done) {
Prismic.Api(testRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').ref(Api.master()).query('[[:d = at(document.type, "youhou")]]').submit(function (err, documents) {
if (err) {
console.log(err);
return;
}
assert.equal(documents.results.length, 0);
done();
});
});
});
it('Correctly handles the error if wrong submission', function (done) {
Prismic.api(testRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').ref(Api.master()).query("wrongpredicate").submit(function (err, _) {
assert.equal(err.message, "Unexpected status code [400] on URL https://lesbonneschoses.prismic.io/api/documents/search?page=1&pageSize=20&ref=UlfoxUnM08QWYXdl&q=wrongpredicate");
done();
});
});
});
it('Fetch additional fields in links with fetchLinks', function (done) {
Prismic.Api(testRepository, function (err, Api) {
if (err) throw err;
Api.form('everything')
.ref(Api.master())
.fetchLinks('blog-post.author')
.query(Predicates.at('document.id', 'UlfoxUnM0wkXYXbt'))
.submit(function (err, response) {
var links = response.results[0].getAll('blog-post.relatedpost');
assert.equal(links[0].getText('blog-post.author'), 'John M. Martelle, Fine Pastry Magazine');
done();
});
});
});
it('Submit the `everything` form with a predicate', function (done) {
Prismic.api(testRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').ref(Api.master()).query(["at", "document.type", "product"]).submit(function (err, documents) {
if (err) {
console.log(err);
return;
}
assert.equal(documents.results.length, 16);
done();
});
});
});
describe('Fragments', function() {
it('Submit the `everything` form with a predicate that give no results', function (done) {
Prismic.api(testRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').ref(Api.master()).query('[[:d = at(document.type, "youhou")]]').submit(function (err, documents) {
if (err) {
console.log(err);
return;
}
assert.equal(documents.results.length, 0);
done();
});
});
});
it('Group fragments', function (done) {
Prismic.Api(microRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').ref(Api.master()).query(["at", "document.id", "UrOaNwEAAM2OpbPy"]).submit(function (err, documents) {
if (err) {
console.log(err);
return;
}
var links = documents.results[0].getGroup("contributor.links");
assert.equal(links.toArray().length, 2);
done();
});
});
it('Fetch additional fields in links with fetchLinks', function (done) {
Prismic.api(testRepository, function (err, Api) {
if (err) throw err;
Api.form('everything')
.ref(Api.master())
.fetchLinks('blog-post.author')
.query(Predicates.at('document.id', 'UlfoxUnM0wkXYXbt'))
.submit(function (err, response) {
var links = response.results[0].getAll('blog-post.relatedpost');
assert.equal(links[0].getText('blog-post.author'), 'John M. Martelle, Fine Pastry Magazine');
done();
});
});
});
});
it('Similarity search', function (done) {
Prismic.Api(testRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').ref(Api.master()).query(["similar", "U9pjvjQAADAAehbf", 10]).submit(function (err, documents) {
if (err) {
console.log(err);
return;
}
assert.equal(0, documents.results.length);
done();
});
});
});
describe('Fragments', function() {
it('"has" predicates', function (done) {
Prismic.Api(microRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').ref(Api.master()).query(
Predicates.has("my.doc.title")
).submit(function (err, documents) {
if (err) {
console.log(err);
return;
}
assert.equal(0, documents.results.length);
done();
});
});
});
it('Group fragments', function (done) {
Prismic.api(microRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').ref(Api.master()).query(["at", "document.id", "UrOaNwEAAM2OpbPy"]).submit(function (err, documents) {
if (err) {
console.log(err);
return;
}
var links = documents.results[0].getGroup("contributor.links");
assert.equal(links.toArray().length, 2);
done();
});
});
});
it('Multiple predicates', function (done) {
Prismic.Api(microRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').ref(Api.master()).query(
Predicates.at("document.type", "article"),
Predicates.fulltext("my.article.title", "meta")
).submit(function (err, documents) {
if (err) {
console.log(err);
return;
}
assert.equal(documents.results.length, 1);
done();
});
});
});
it('Similarity search', function (done) {
Prismic.api(testRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').ref(Api.master()).query(["similar", "U9pjvjQAADAAehbf", 10]).submit(function (err, documents) {
if (err) {
console.log(err);
return;
}
assert.equal(0, documents.results.length);
done();
});
});
});
it('Submit the `products` form', function (done) {
Prismic.Api(testRepository, function (err, Api) {
if (err) throw err;
Api.form('products').ref(Api.master()).submit(function (err, documents) {
if (err) {
console.log(err);
return;
}
assert.equal(documents.results.length, 16);
done();
});
});
});
it('"has" predicates', function (done) {
Prismic.api(microRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').ref(Api.master()).query(
Predicates.has("my.doc.title")
).submit(function (err, documents) {
if (err) {
console.log(err);
return;
}
assert.equal(0, documents.results.length);
done();
});
});
});
it('Submit the `products` form with a predicate', function (done) {
Prismic.Api(testRepository, function (err, Api) {
if (err) throw err;
Api.form('products').ref(Api.master()).query('[[:d = at(my.product.flavour, "Chocolate")]]').submit(function (err, documents) {
if (err) {
console.log(err);
return;
}
assert.equal(documents.results.length, 5);
done();
});
});
});
it('Multiple predicates', function (done) {
Prismic.api(microRepository, function (err, Api) {
if (err) throw err;
Api.form('everything').ref(Api.master()).query(
Predicates.at("document.type", "article"),
Predicates.fulltext("my.article.title", "meta")
).submit(function (err, documents) {
if (err) {
console.log(err);
return;
}
assert.equal(documents.results.length, 1);
done();
});
});
});
it('Submit the `products` form with an empty query', function (done) {
Prismic.Api(testRepository, function (err, Api) {
if (err) throw err;
Api.form('products').ref(Api.master()).query('').submit(function (err, documents) {
if (err) {
console.log(err);
return;
}
assert.equal(documents.results.length, 16);
done();
});
});
});
it('Submit the `products` form', function (done) {
Prismic.api(testRepository, function (err, Api) {
if (err) throw err;
Api.form('products').ref(Api.master()).submit(function (err, documents) {
if (err) {
console.log(err);
return;
}
assert.equal(documents.results.length, 16);
done();
});
});
});
it('Submit the `products` form in the future', function (done) {
Prismic.Api(testRepository, function (err, Api) {
if (err) throw err;
Api.form('products').ref(Api.ref('Announcement of new SF shop')).submit(function (err, documents) {
if (err) {
console.log(err);
return;
}
assert.equal(documents.results.length, 17);
done();
});
}, previewToken);
});
it('Submit the `products` form with a predicate', function (done) {
Prismic.api(testRepository, function (err, Api) {
if (err) throw err;
Api.form('products').ref(Api.master()).query('[[:d = at(my.product.flavour, "Chocolate")]]').submit(function (err, documents) {
if (err) {
console.log(err);
return;
}
assert.equal(documents.results.length, 5);
done();
});
});
});
it('Test cache', function (done) {
Prismic.Api(testRepository, function (err, Api) {
if (err) return done(err);
var form = Api.form('products').ref(Api.master()).query('[[:d = at(my.product.flavour, "Caramel")]]');
var olderKeys = Api.apiCache.lru.keys();
form.submit(function (err, response) {
if (err) {
console.log(err);
return done(err);
}
it('Submit the `products` form with an empty query', function (done) {
Prismic.api(testRepository, function (err, Api) {
if (err) throw err;
Api.form('products').ref(Api.master()).query('').submit(function (err, documents) {
if (err) {
console.log(err);
return;
}
assert.equal(documents.results.length, 16);
done();
});
});
});
var key = null;
Api.apiCache.lru.keys().forEach(function (candidate) {
if (olderKeys.indexOf(candidate) == -1) {
key = candidate;
}
});
it('Submit the `products` form in the future', function (done) {
Prismic.api(testRepository, function (err, Api) {
if (err) throw err;
Api.form('products').ref(Api.ref('Announcement of new SF shop')).submit(function (err, documents) {
if (err) {
console.log(err);
return;
}
assert.equal(documents.results.length, 17);
done();
});
}, previewToken);
});
Api.apiCache.get(key, function (err, value) {
assert.equal(value.results.length, response.results.length);
done();
});
});
});
it('Test cache', function (done) {
Prismic.api(testRepository, function (err, Api) {
if (err) { done(err); return; }
var form = Api.form('products').ref(Api.master()).query('[[:d = at(my.product.flavour, "Caramel")]]');
var olderKeys = Api.apiCache.lru.keys();
form.submit(function (err, response) {
if (err) {
console.log(err);
done(err);
return;
}
var key = null;
Api.apiCache.lru.keys().forEach(function (candidate) {
if (olderKeys.indexOf(candidate) == -1) {
key = candidate;
}
});
Api.apiCache.get(key, function (err, value) {
assert.equal(value.results.length, response.results.length);
done();
});
});
});
});
}(window.Prismic));
});

@@ -1,128 +0,130 @@

(function(Prismic) {
/*eslint-env node, mocha */
/*eslint no-unused-vars: 0 */
var assert = chai.assert;
var Prismic = require('../lib/prismic.js');
var chai = require('chai');
var structuredText = {
type: 'StructuredText',
value: [{
type: 'paragraph',
text: 'Hi everyone, I am an awesome text!',
spans: [{
start: 0,
end: 11,
type: 'strong'
},{
start: 3,
end: 11,
type: 'em'
},{
start: 13,
end: 17,
type: 'strong'
},{
start: 17,
end: 28,
type: 'em'
}]
}]
};
var assert = chai.assert;
function getLinkResolver(ref) {
return function(doc, isBroken) {
if (isBroken) return '#broken';
return "/testing_url/" + doc.id + "/" + doc.slug + (ref ? ('?ref=' + ref) : '');
}
}
var structuredText = {
type: 'StructuredText',
value: [{
type: 'paragraph',
text: 'Hi everyone, I am an awesome text!',
spans: [{
start: 0,
end: 11,
type: 'strong'
},{
start: 3,
end: 11,
type: 'em'
},{
start: 13,
end: 17,
type: 'strong'
},{
start: 17,
end: 28,
type: 'em'
}]
}]
};
describe("Unit tests", function() {
function getLinkResolver(ref) {
return function(doc, isBroken) {
if (isBroken) return '#broken';
return "/testing_url/" + doc.id + "/" + doc.slug + (ref ? ('?ref=' + ref) : '');
};
}
it('should init and render StructuredText', function () {
var html = '<p><strong>Hi <em>everyone</em></strong>, <strong>I am</strong><em> an awesome</em> text!</p>';
var fragment = Prismic.Fragments.initField(structuredText);
describe("Unit tests", function() {
assert.equal(html, fragment.asHtml());
});
it('should init and render StructuredText', function () {
var html = '<p><strong>Hi <em>everyone</em></strong>, <strong>I am</strong><em> an awesome</em> text!</p>';
var fragment = Prismic.Fragments.initField(structuredText);
});
assert.equal(html, fragment.asHtml());
});
describe("HTML content", function() {
});
it('2 spans on the same text - one bigger 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, {});
assert.equal(html, 'ab<em><strong>cd</strong>ef</em>ghijklmnopqrstuvwxyz');
});
describe("HTML content", function() {
it('2 spans on the same text - one bigger 2', 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, {});
assert.equal(html, 'ab<strong><em>cd</em>ef</strong>ghijklmnopqrstuvwxyz');
});
it('2 spans on the same text - one bigger 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, {});
assert.equal(html, 'ab<em><strong>cd</strong>ef</em>ghijklmnopqrstuvwxyz');
});
it ("with span labels", function() {
var text = 'abcdefghijklmnopqrstuvwxyz';
var spans = [{
"type": "label",
"start": 2,
"end": 6,
"data": {
"label": "tip"
}
}];
var html = Prismic.Fragments.insertSpans(text, spans, {});
assert.equal(html, 'ab<span class="tip">cdef</span>ghijklmnopqrstuvwxyz');
});
it('2 spans on the same text - one bigger 2', 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, {});
assert.equal(html, 'ab<strong><em>cd</em>ef</strong>ghijklmnopqrstuvwxyz');
});
});
it ("with span labels", function() {
var text = 'abcdefghijklmnopqrstuvwxyz';
var spans = [{
"type": "label",
"start": 2,
"end": 6,
"data": {
"label": "tip"
}
}];
var html = Prismic.Fragments.insertSpans(text, spans, {});
assert.equal(html, 'ab<span class="tip">cdef</span>ghijklmnopqrstuvwxyz');
});
it('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);
assert.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>');
});
});
it('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);
assert.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>');
});
it('Dates are well retrieved', function() {
var timestampHtml = Prismic.Fragments.initField({"type" : "Date", "value" : "2014-04-01"}).asHtml();
assert.equal(
(new RegExp('<time>... ... \\d\\d 2014 \\d\\d:00:00 GMT[-+]\\d\\d00 \\(.+\\)</time>')).test(timestampHtml),
true
);
});
it('Timestamps are well retrieved', function() {
var timestampHtml = Prismic.Fragments.initField({"type" : "Timestamp", "value" : "2014-06-18T15:30:00+0000"}).asHtml();
assert.equal(
(new RegExp('<time>... ... \\d\\d 2014 \\d\\d:30:00 GMT[-+]\\d\\d00 \\(.+\\)</time>')).test(timestampHtml),
true,
timestampHtml
);
});
it('Dates are well retrieved', function() {
var timestampHtml = Prismic.Fragments.initField({"type" : "Date", "value" : "2014-04-01"}).asHtml();
assert.equal(
(new RegExp('<time>... ... \\d\\d 2014 \\d\\d:00:00 GMT[-+]\\d\\d00 \\(.+\\)</time>')).test(timestampHtml),
true
);
});
it('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);
assert.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>');
});
it('Timestamps are well retrieved', function() {
var timestampHtml = Prismic.Fragments.initField({"type" : "Timestamp", "value" : "2014-06-18T15:30:00+0000"}).asHtml();
assert.equal(
(new RegExp('<time>... ... \\d\\d 2014 \\d\\d:30:00 GMT[-+]\\d\\d00 \\(.+\\)</time>')).test(timestampHtml),
true,
timestampHtml
);
});
})(window.Prismic);
it('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);
assert.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>');
});

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 too big to display

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