prismicio / javascript-kit Goto Github PK
View Code? Open in Web Editor NEWDevelopment kit for the Javascript language
Home Page: https://developers.prismic.io
Development kit for the Javascript language
Home Page: https://developers.prismic.io
To be added in the SearchForm class.
Not sure if it's relevant, depending on whether the language allows to generate them dynamically or not.
Note: this can be worked around through set("orderings", "[my.value.position]")
for now
Updated to version 1.1.6 and getting the following error. Reverting to 1.1.4 fixes the problem.
I'm really sorry I can't be of more help right now but we are about to launch our new website and I'm a little bit busy :)
error 03-Jun-2015 15:44:19 TypeError: Cannot set property 'LRUCache' of undefined
error 03-Jun-2015 15:44:19 at /home/bamboo/bamboo-agent-home/xml-data/build-dir/YW-YW-JOB1/node_modules/prismic.io/dist/prismic.io.js:274:25
error 03-Jun-2015 15:44:19 at Object.<anonymous> (/home/bamboo/bamboo-agent-home/xml-data/build-dir/YW-YW-JOB1/node_modules/prismic.io/dist/prismic.io.js:277:2)
error 03-Jun-2015 15:44:19 at Module._compile (module.js:456:26)
error 03-Jun-2015 15:44:19 at Object.gnodeJsExtensionCompiler [as .js] (/home/bamboo/bamboo-agent-home/xml-data/build-dir/YW-YW-JOB1/node_modules/metalsmith/node_modules/gnode/index.js:61:10)
error 03-Jun-2015 15:44:19 at Module.load (/home/bamboo/bamboo-agent-home/xml-data/build-dir/YW-YW-JOB1/node_modules/coffee-script/lib/coffee-script/register.js:45:36)
error 03-Jun-2015 15:44:19 at Function.Module._load (module.js:312:12)
error 03-Jun-2015 15:44:19 at Module.require (module.js:364:17)
error 03-Jun-2015 15:44:19 at require (module.js:380:17)
error 03-Jun-2015 15:44:19 at Object.<anonymous> (/home/bamboo/bamboo-agent-home/xml-data/build-dir/YW-YW-JOB1/scripts/fetch-prismic/get-api.coffee:1:13)
error 03-Jun-2015 15:44:19 at Object.<anonymous> (/home/bamboo/bamboo-agent-home/xml-data/build-dir/YW-YW-JOB1/scripts/fetch-prismic/get-api.coffee:1:1)
error 03-Jun-2015 15:44:19 at Module._compile (module.js:456:26)
error 03-Jun-2015 15:44:19 at Object.loadFile (/home/bamboo/bamboo-agent-home/xml-data/build-dir/YW-YW-JOB1/node_modules/coffee-script/lib/coffee-script/register.js:16:19)
error 03-Jun-2015 15:44:19 at Module.load (/home/bamboo/bamboo-agent-home/xml-data/build-dir/YW-YW-JOB1/node_modules/coffee-script/lib/coffee-script/register.js:45:36)
error 03-Jun-2015 15:44:19 at Function.Module._load (module.js:312:12)
error 03-Jun-2015 15:44:19 at Module.require (module.js:364:17)
error 03-Jun-2015 15:44:19 at require (module.js:380:17)
error 03-Jun-2015 15:44:19 at Object.<anonymous> (/home/bamboo/bamboo-agent-home/xml-data/build-dir/YW-YW-JOB1/scripts/fetch-prismic/index.coffee:2:10)
error 03-Jun-2015 15:44:19 at Object.<anonymous> (/home/bamboo/bamboo-agent-home/xml-data/build-dir/YW-YW-JOB1/scripts/fetch-prismic/index.coffee:1:1)
error 03-Jun-2015 15:44:19 at Module._compile (module.js:456:26)
error 03-Jun-2015 15:44:19 at Object.loadFile (/home/bamboo/bamboo-agent-home/xml-data/build-dir/YW-YW-JOB1/node_modules/coffee-script/lib/coffee-script/register.js:16:19)
error 03-Jun-2015 15:44:19 at Module.load (/home/bamboo/bamboo-agent-home/xml-data/build-dir/YW-YW-JOB1/node_modules/coffee-script/lib/coffee-script/register.js:45:36)
error 03-Jun-2015 15:44:19 at Function.Module._load (module.js:312:12)
error 03-Jun-2015 15:44:19 at Module.require (module.js:364:17)
error 03-Jun-2015 15:44:19 at require (module.js:380:17)
error 03-Jun-2015 15:44:19 at Object.<anonymous> (/home/bamboo/bamboo-agent-home/xml-data/build-dir/YW-YW-JOB1/scripts/build.coffee:13:16)
error 03-Jun-2015 15:44:19 at Object.<anonymous> (/home/bamboo/bamboo-agent-home/xml-data/build-dir/YW-YW-JOB1/scripts/build.coffee:1:1)
error 03-Jun-2015 15:44:19 at Module._compile (module.js:456:26)
error 03-Jun-2015 15:44:19 at Object.loadFile (/home/bamboo/bamboo-agent-home/xml-data/build-dir/YW-YW-JOB1/node_modules/coffee-script/lib/coffee-script/register.js:16:19)
error 03-Jun-2015 15:44:19 at Module.load (/home/bamboo/bamboo-agent-home/xml-data/build-dir/YW-YW-JOB1/node_modules/coffee-script/lib/coffee-script/register.js:45:36)
error 03-Jun-2015 15:44:19 at Function.Module._load (module.js:312:12)
error 03-Jun-2015 15:44:19 at Module.require (module.js:364:17)
error 03-Jun-2015 15:44:19 at require (module.js:380:17)
error 03-Jun-2015 15:44:19 at Object.<anonymous> (/home/bamboo/bamboo-agent-home/xml-data/build-dir/YW-YW-JOB1/scripts/production-build.coffee:2:9)
error 03-Jun-2015 15:44:19 at Object.<anonymous> (/home/bamboo/bamboo-agent-home/xml-data/build-dir/YW-YW-JOB1/scripts/production-build.coffee:1:1)
error 03-Jun-2015 15:44:19 at Module._compile (module.js:456:26)
error 03-Jun-2015 15:44:19 at Object.exports.run (/home/bamboo/bamboo-agent-home/xml-data/build-dir/YW-YW-JOB1/node_modules/coffee-script/lib/coffee-script/coffee-script.js:119:23)
error 03-Jun-2015 15:44:19 at compileScript (/home/bamboo/bamboo-agent-home/xml-data/build-dir/YW-YW-JOB1/node_modules/coffee-script/lib/coffee-script/command.js:208:29)
error 03-Jun-2015 15:44:19 at compilePath (/home/bamboo/bamboo-agent-home/xml-data/build-dir/YW-YW-JOB1/node_modules/coffee-script/lib/coffee-script/command.js:161:14)
error 03-Jun-2015 15:44:19 at Object.exports.run (/home/bamboo/bamboo-agent-home/xml-data/build-dir/YW-YW-JOB1/node_modules/coffee-script/lib/coffee-script/command.js:96:21)
error 03-Jun-2015 15:44:19 at Object.<anonymous> (/home/bamboo/bamboo-agent-home/xml-data/build-dir/YW-YW-JOB1/node_modules/coffee-script/bin/coffee:7:41)
error 03-Jun-2015 15:44:19 at Module._compile (module.js:456:26)
error 03-Jun-2015 15:44:19 at Object.Module._extensions..js (module.js:474:10)
error 03-Jun-2015 15:44:19 at Module.load (module.js:356:32)
error 03-Jun-2015 15:44:19 at Function.Module._load (module.js:312:12)
error 03-Jun-2015 15:44:19 at Function.Module.runMain (module.js:497:10)
error 03-Jun-2015 15:44:19 at startup (node.js:119:16)
error 03-Jun-2015 15:44:19 at node.js:929:3
error 03-Jun-2015 15:44:19
error 03-Jun-2015 15:44:19
error 03-Jun-2015 15:44:19 npm ERR! Linux 3.16.0-25-generic
error 03-Jun-2015 15:44:19 npm ERR! argv "node" "/opt/node-0.10/bin/npm" "run" "build"
error 03-Jun-2015 15:44:19 npm ERR! node v0.10.35
error 03-Jun-2015 15:44:19 npm ERR! npm v2.6.1
error 03-Jun-2015 15:44:19 npm ERR! code ELIFECYCLE
error 03-Jun-2015 15:44:19 npm ERR! [email protected] build: `webpack && coffee scripts/production-build.coffee`
error 03-Jun-2015 15:44:19 npm ERR! Exit status 1
error 03-Jun-2015 15:44:19 npm ERR!
error 03-Jun-2015 15:44:19 npm ERR! Failed at the [email protected] build script 'webpack && coffee scripts/production-build.coffee'.
error 03-Jun-2015 15:44:19 npm ERR! This is most likely a problem with the yw2 package,
error 03-Jun-2015 15:44:19 npm ERR! not with npm itself.
error 03-Jun-2015 15:44:19 npm ERR! Tell the author that this fails on your system:
error 03-Jun-2015 15:44:19 npm ERR! webpack && coffee scripts/production-build.coffee
error 03-Jun-2015 15:44:19 npm ERR! You can get their info via:
error 03-Jun-2015 15:44:19 npm ERR! npm owner ls yw2
error 03-Jun-2015 15:44:19 npm ERR! There is likely additional logging output above.
error 03-Jun-2015 15:44:19
error 03-Jun-2015 15:44:19 npm ERR! Please include the following file with any support request:
error 03-Jun-2015 15:44:19 npm ERR! /home/bamboo/bamboo-agent-home/xml-data/build-dir/YW-YW-JOB1/npm-debug.log
simple 03-Jun-2015 15:44:19 Failing task since return code of [/opt/node-0.10/bin/npm run build] was 1 while expected 0
simple 03-Jun-2015 15:44:19 Finished task 'Run Build!' with result: Failed
simple 03-Jun-2015 15:44:19 Running post build plugin 'Docker Container Cleanup'
simple 03-Jun-2015 15:44:19 Running post build plugin 'NCover Results Collector'
simple 03-Jun-2015 15:44:19 Running post build plugin 'Clover Results Collector'
simple 03-Jun-2015 15:44:19 Running post build plugin 'npm Cache Cleanup'
simple 03-Jun-2015 15:44:19 Running post build plugin 'Artifact Copier'
simple 03-Jun-2015 15:44:19 Publishing an artifact: YW2 Website
error 03-Jun-2015 15:44:19 Unable to publish artifact [YW2 Website]: the source directory /home/bamboo/bamboo-agent-home/xml-data/build-dir/YW-YW-JOB1/dist does not exist.
simple 03-Jun-2015 15:44:19 Finished publishing of artifact Shared artifact: [YW2 Website], pattern: [**/*.*] anchored at: [dist] in 0s
simple 03-Jun-2015 15:44:19 Finalising the build...
simple 03-Jun-2015 15:44:19 Stopping timer.
simple 03-Jun-2015 15:44:19 Build YW-YW-JOB1-52 completed.
simple 03-Jun-2015 15:44:20 Running on server: post build plugin 'Clover Delta Calculator'
simple 03-Jun-2015 15:44:20 Running on server: post build plugin 'Build Hanging Detection Configuration'
simple 03-Jun-2015 15:44:20 Running on server: post build plugin 'NCover Results Collector'
simple 03-Jun-2015 15:44:20 Running on server: post build plugin 'Maven Dependencies Postprocessor'
simple 03-Jun-2015 15:44:20 All post build plugins have finished
simple 03-Jun-2015 15:44:20 Generating build results summary...
simple 03-Jun-2015 15:44:20 Saving build results to disk...
simple 03-Jun-2015 15:44:20 Logging substituted variables...
simple 03-Jun-2015 15:44:20 Indexing build results...
simple 03-Jun-2015 15:44:20 Finished building YW-YW-JOB1-52.
From https://github.com/prismicio/javascript-kit/blob/master/src/api.js#L277-L320, when we query documents (by, say document.id
) and we don't have any results come back, the callback does not get invoked because of the check on line 315: if (cb && docs.length) {
.
This is an issue if we want to handle a 404 scenario and redirect in the browser. Perhaps I can work with you guys to resolve this!
Hi,
When calling Prismic.Api, you get Doc
objects, which structure is quite close to the raw JSON you would retrieved from a HTTP request to the /api
but with a different format. Investigating why, it looks like Doc
objects should only be manipulate with methods lile get(....)
or getDate(...)
and so on.
If that's the case, I think it would be better to hide the state otherwise people will start using it, and you will no be able to modify it anymore if you need to. It is quite easy using a closure.
Regarding how to it, I would try replacing this line with a private var and include a getFragments
right next to it, and it would call the global getFragments which would be refactored in a more functional way without using this
.
function getFragments = function (fragments, name) {
if (!fragments || !fragments[name]) {
return [];
}
if (Array.isArray(fragments[name])) {
return fragments[name];
} else {
return [fragments[name]];
}
}
var _fragments = fragments;
this.getFragments = function (name) {
return getFragments.call(this, _fragments, name);
};
What do you thing?
Version 1.0.29 deprecated (read removed) linkedDocument which we relied on. It auto-updated when we re-shrinkwrapped before deploying because it was only a revision bump and so the day after launching our new site all the navigation disappeared! Not cool.
I'm getting an error when trying to use the promises syntax described on the readme:
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);
});
I just keep getting Uncaught TypeError: Prismic.Api(...).then is not a function
in console.
Any thoughts?
Right now, the issue is solved by just returning and manipulating the first field.
I can look into this shortly.
I have multiple lists on a page I'm editing. The two lists, separated by a paragraph, are getting merged into the first list. This seems like it started after I updated nodejs to version 0.10.26. At it's simplest the page looks like this:
paragraph --> This is an intro paragraph
list-->List 1 - List Item 1
list-->List 1 - List Item 2
paragraph--> This is another paragraph
list-->List 2 - List Item 1
list-->List 2 - List Item 2
When I get the results from obj.get("article.content").asHtml({linkResolver: linkResolver})
, I get the html as:
<p>This is an intro paragraph</p>
<ul>
<li>List 1 - List Item 1</li>
<li>List 1 - List Item 2</li>
<li>List 2 - List Item 1</li>
<li>List 2 - List Item 2</li>
</ul>
<p>This is another paragraph</p>
I'm using prismic.io version 1.0.17
Thanks
Can you publish v1.0.27, which fixes IE8 issues ?
Thank you
The JS kit test #6 fails because calling this:
Api.forms('products').ref(Api.master()).query('[[:d = at(my.product.flavour, "Chocolate")]]').submit(callback);
generates this URL with two q
parameters (one brought by the form, one brought by the query):
https://lesbonneschoses.prismic.io/api/documents/search?q=%5B%5B%3Ad%20%3D%20any(document.type%2C%20%5B%22product%22%5D)%5D%5D&q=%5B%5B%3Ad%20%3D%20at(my.product.flavour%2C%20%22Chocolate%22)%5D%5D&ref=UkL0hcuvzYUANCrm
The server responds with an error 500:
{"message":"shouldhandlecaseswithseveralqueries!"}
How it happens: SearchForm.query()
method ends up with a this.data.q
which is an array of 2 values:
[[:d = any(document.type, ["product"])]]
and [[:d = at(my.product.flavour, "Chocolate")]]
Later, the SearchForm.submit()
method loops through these and adds one parameter per array item to the URL, therefore sending the two q
parameters.
I wanted to fix this right (should I change the query() method or the submit() method?), so I went to see how it was done in Java, and I think I'm missing some information, because in the Java kit, this is handled within a private method called SearchForm.strip() that comes with a // Temporary hack for Backward compatibility
comment, and does some string parsing.
Is this how it should be done in JS as well for now?
I would like to use code of PR #58 in my project, can you make a release of the kit ?
Thank you
Hi!
Prismic.io is not working for me in Internet Explorer 10,
When you open the ajax request for the authorization step you are appending "#json" after the access_token and Internet Explorer escapes the URL to %23json. So I'm getting an 401 Status Code.
Overview
When accessing values on a document there are nice getters, for example:
(note the following examples use jade templates)
p=doc.getText('name')
div=doc.getStructuredText('description).asHtml()
However, when accessing a group of fragments, this functionality is lost. The following doesn't work as expected:
each value, key in product.getGroup('product.features').asArray()
p=value.getText('name')
div=value.getStructuredText('description).asHtml()
What is the browser support for this kit?
As the title says, the StructuredTextAsHtml method is ignoring the additional data that is included with uploaded images. This occurs not just in the StructuredTextAsHtml function, but also in ImageLink.prototype.asHtml() and ImageView.prototype.asHtml().
PhantomJS uses SSLv3 per default, but the server no longer supports it:
ariya/phantomjs#12655
We need to figure out a way to pass --ssl-protocol=tlsv1 as parameter, that apparently involves patching gulp-qunit.
I assumed from the documentation that the ApiCache
would be used to cache all requests to the API. However it seems the only thing being cached by ApiCache
is the instance of the api itself.
The only request handler that seems to do any caching is the nodeJSRequest
which sets up it's own requestsCache
and doesn't make use of the ApiCache
.
Unless I'm missing something, the ApiCache
seems to be essentially useless as it's only used during initialization, and the ApiCache
is created during initialization. So it seems as though nothing is ever retrieved from the cache, which defeats the purpose of the cache.
Did I miss something, or do something wrong?
I'm getting an error calling this function;
var desc = doc.get('event.description');
var img = desc.getFirstImage();
The error is
Cannot read property 'url' of undefined
.
block.data
does not exist, and removing .data
gets rid of the error.
On this line
return new ImageView(
block.data.url,
block.data.dimensions.width,
block.data.dimensions.height
);
It would be better if the returned HTML did not wrap the <img>
with <p>
.
Hi,
I noticed you've put in some client-enforced rate limiting in the client recently:
https://github.com/prismicio/javascript-kit/blob/master/src/utils.js#L176
There appears to be a bug - when trying to build a menu for our site we make 3 calls in parallel to get the contents of a few prismic collections to build various sections. The first two call back OK, but the 3rd one hangs seemingly indefinitely.
Can you explain the reason why there is rate limiting in the client anyway? I've got a few issues with it:
Overall it just seems like it's adding complexity (and bugs as I've discovered) without much benefit, and is just making me uneasy about using your client.
Thanks
Dave
Some issues only exist on / are worse on Node.js.
I created a test/nodetest.js
file for the bug I've been working on today, that you can launch with node test/nodetest.js
, but it's not exactly great: using a proper testing tool would allow to add these tests as Grunt tasks.
I tried with grunt-node-qunit, but it didn't work, and is terribly documented. Eventually, I figured this was too much effort for a single marginal bug, but let's keep in mind to do this better later.
I'm trying to pull in some linked documents. I have working queries that provide me with Prismic Documents with linked documents available to me.
{
fragments: {...},
linkedDocuments: [...]
...
}
I was hoping there would be a method to select linked documents by Id or Name or some other property. I found this while looking for a solution: https://blog.prismic.io/U5nJQCwAAC4ABCJm/improve-your-content-discovery-similar-predicate-and-linked-documents
However the method near the bottom of the article (doc.getLinkedDocument
) doesn't seem to exist in the Javascript SDK. If there aren't any features in the sdk to handle this I'll just move on to creating my own lookup, but I thought I would check.
I'm running a node script that requires prismic, which I took from the readme:
#!/usr/bin/env node
var Prismic = require('prismic.io');
PRISMIC_CONFIG = {
api: "http://lesbonneschoses.prismic.io/api",
}
Prismic.api(PRISMIC_CONFIG.api, function(error, api) {
api.query("", function(error, response) { // An empty query will return all the documents
if (error) {
console.log("Something went wrong: ", err);
}
console.log("Documents: ", response.documents);
});
});
And I get the error:
> ./js/prismic_tasks/derp.js
/Users/peterconerly/src/2picmonkey/node_modules/prismic.io/lib/prismic.js:39
return new Promise(function(resolve, reject) {
^
ReferenceError: Promise is not defined
at Object.getApi (/Users/peterconerly/src/2picmonkey/node_modules/prismic.io/lib/prismic.js:39:14)
at Object.<anonymous> (/Users/peterconerly/src/2picmonkey/js/prismic_tasks/derp.js:10:9)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
npm ERR! [email protected] prismic: `./js/prismic_tasks/derp.js`
npm ERR! Exit status 8
npm ERR!
npm ERR! Failed at the [email protected] prismic script.
npm ERR! This is most likely a problem with the picmonkey package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! ./js/prismic_tasks/derp.js
npm ERR! You can get their info via:
npm ERR! npm owner ls picmonkey
npm ERR! There is likely additional logging output above.
npm ERR! System Darwin 13.4.0
npm ERR! command "/Users/peterconerly/.nvm/v0.10.30/bin/node" "/Users/peterconerly/.nvm/v0.10.30/bin/npm" "run" "prismic"
npm ERR! cwd /Users/peterconerly/src/2picmonkey
npm ERR! node -v v0.10.30
npm ERR! npm -v 1.4.21
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Users/peterconerly/src/2picmonkey/npm-debug.log
npm ERR! not ok code 0
It seems like the dependencies are messed up :/
I have following document strucutre:
https://gist.github.com/zubairov/20068d148b28e2eaddbb
I experiencing a bug - when StructuredText field contains only one list and no other parts then I see following error when trying to convert such piece into HTML
13:17:27 web.1 | TypeError: Cannot read property 'blocks' of undefined
13:17:27 web.1 | at Object.StructuredTextAsHtml (/Users/zubairov/Repositories/website2/node_modules/prismic.io/dist/prismic.io.js:1380:27)
13:17:27 web.1 | at Object.StructuredText.asHtml (/Users/zubairov/Repositories/website2/node_modules/prismic.io/dist/prismic.io.js:1346:41)
13:17:27 web.1 | at processGroup (/Users/zubairov/Repositories/website2/lib/prismic-dust-helpers.js:16:67)
Where my code on prismic-dust-helpers.js
just calls fragment.asHtml()
.
There were some changes recently on the API side, but maybe this doesn't change anything, and the kit works great. To be checked.
Hi,
I have some optional attributes in my document. I'm using Node.js/Express with ejs
template:
document.get("page.catch_phrase").asText()
The problem is that I need to check that document.get("page.catch_phrase") != null
before calling asText()
. Something like:
<% if (document.get("page.catch_phrase") != null ) { %>
<%- document.get("page.catch_phrase").asText() %>
<% } %>
This is really verbose and I need to be extra careful because if I forget one of them my template will return a HTTP 500 ๐ข
Can we add a shortcut method to handle optional attribute ?
document.getAsText("page.catch_phrase") // corresponding text value or empty ""
Thanks
Module parse failed: /home/jsmankoo/Projects/TemplatesSinglePage/node_modules/prismic.io/package.json Line 2: Unexpected token :
You may need an appropriate loader to handle this file type.
| {
| "_args": [
| [
| "prismic.io",
@ ./~/prismic.io/lib/requests.js 109:16-42 145:16-42
works just fine when used in Node.js
webpack Config
var path = require('path');
var webpack = require('webpack');
var jeet = require('jeet');
var axis = require('axis');
var rupture = require('rupture');
var autoprefixer = require('autoprefixer-stylus');
module.exports = {
devtool: 'eval',
entry: [
'webpack-dev-server/client?http://localhost:3000',
'webpack/hot/only-dev-server',
'./src/index'
],
output: {
path: path.join(__dirname, 'dist'),
filename: 'bundle.js',
publicPath: '/static/'
},
plugins: [
new webpack.HotModuleReplacementPlugin()
],
module: {
loaders: [{
test: /.js$/,
loaders: ['react-hot', 'babel'],
include: path.join(__dirname, 'src')
},{
test: /.styl$/,
loader: 'style-loader!css-loader!stylus-loader'
}]
},
stylus: {
use: [axis(), jeet(), rupture(), autoprefixer()]
}
};
I got a version mismatch when I tried to upgrade to 1.0.10 with bower.
`t-kit/archive/1.0.10.tar.gz failed with ESOCKETTIMEDOUT, retrying in 1.4s
bower prismic.io#1.0.10 progress received 0.0MB of 0.1MB downloaded, 26%
bower prismic.io#1.0.10 extract archive.tar.gz
bower prismic.io#1.0.10 mismatch Version declared in the json (1.0.9) is different than the resolved one (1.0.10)
bower prismic.io#1.0.10 resolved git://github.com/prismicio/javascript-kit.git#1.0.10
bower prismic.io#1.0.10 install prismic.io#1.0.10
We tried to bower install with it's git repo and still saw the error.
var Prismic = require('prismic.io');
the above mentioned statement when console.log'd in node.js works just fine.
But in browserify returns an empty object
At least I think this is a syntax error... previewSession
binds a variable api
and later refers to a self
variable which, AFAICT, is supposed to be the same thing but has not been bound anywhere. This confuses me because no syntax errors are thrown when I use previewSession
, but it doesn't work properly (the callback is never invoked/promise is never resolved). If I consolidate the bindings things work as expected.
I can submit a PR if you like.
I think it would be great if the submit()
method returns a Promise.
In my case I need to query multiple documents to compose my page (the two latest news, the page content, a popular member, etc...) and my code is a callback hell !
ctx.api.form('everything').ref(ctx.ref).query('firstQuery').submit(function (err, docs) {
if (err) { prismic.onPrismicError(err, req, res); return; }
ctx.api.form('everything').ref(ctx.ref).query('secondQuery').submit(function (err, docs) {
if (err) { prismic.onPrismicError(err, req, res); return; }
ctx.api.form('everything').ref(ctx.ref).query('thirdQuery').submit(function (err, docs) {
if (err) { prismic.onPrismicError(err, req, res); return; }
res.render('', {});
});
});
});
But will look much better with Promise:
var firstQuery = ctx.api.form('everything').ref(ctx.ref).query('firstQuery').submit();
var secondQuery = ctx.api.form('everything').ref(ctx.ref).query('secondQuery').submit();
var thirdQuery = ctx.api.form('everything').ref(ctx.ref).query('thirdQuery').submit();
firstQuery.then(secondQuery).then(thirdQuery).then(new function(result) {
res.render('', {});
});
Maybe I'm missing something with the API ? Or my use case is an edge case ?
Thanks, and great product by the way (a pleasure to develop a website with ๐)
This is more of a question on functionality. Should preformatted text automatically convert html entities to code equivalents?
Basically something like? http://css-tricks.com/snippets/javascript/htmlentities-for-javascript/
Hello,
Calling the asText()
method of a Number
fragment with null content throws the following exception:
TypeError: Cannot read property 'toString' of null
at Object.Num.asText (/Users/aeir/Code/firstcard-web/node_modules/prismic.io/dist/prismic.io.js:2280:30)
at Object.WithFragments.asText (/Users/aeir/Code/firstcard-web/node_modules/prismic.io/dist/prismic.io.js:1727:67)
at Object.Group.asText (/Users/aeir/Code/firstcard-web/node_modules/prismic.io/dist/prismic.io.js:2547:41)
at processSingleFragment (/Users/aeir/Code/firstcard-web/node_modules/metalsmith-prismic/lib/index.js:258:46)
...
Right now, are missing the lists, the spans, and the embeds.
Posted a question in prismic Q&A on https://qa.prismic.io/27/how-can-i-get-around-internet-explorers-cross-domain-xhr where I were recommended to post an issue for this.
The error "Access is denied." comes when I try to fetch data from prismic in all IE versions prior 10. With the latest javascript-kit the error is located on row 55 col 17 xhr.open('GET', url, true)
Hi
I have a quite peculiar request. I want to monkeypatch/wrap the html generating function for DocumentLink. More specifically the DocumentLink.prototype.asHtml
-function.
The purpose of this is to pull in the linked document and render it as a custom component (in this case a mail form). This is a use case we really need as we integrate different custom made components that we wish to embed inside StructuredText fields.
I have solved it on the version we're currently using 0.11.0 by replacing the following:
EDIT: Looking a bit closer I see that my change does not really do the job. The url link text is not rendered when I do this.
html.push('<a href="'+ initField(tag.data).url(ctx) +'">');
html.push(textBits.shift());
html.push('</a>');
(Original at: https://github.com/prismicio/javascript-kit/blob/1.0.12/src/fragments.js#L755)
Which was replaced with the following code:
html.push(initField(tag.data).asHtml(ctx));
textBits.shift();
However when I was going to make a pull request I noticed that the logic in the insertSpans-function has been remade in the latest commits making it more efficient I suppose, but much harder for me to solve my problem without tearing out a lot of stuff.
I don't mind exactly how this would be solved, above is just the way I saw forward. I just wish to customize rendering for DocumentLink reliably, regardless if the link is in nested in a StructuredText or not.
If there were callbacks directly in the API, something similar to LinkResolver, that would work as well.
Here is a longer discussion with some background to why we need custom rendering (in that case tables): https://qa.prismic.io/25/how-do-we-best-support-tables
When you go:
npm install jsdoc
./node_modules/.bin/jsdoc dist/prismic.io.js
the result in the out/
folder is all blank pages:
Next step is including it as a Grunt task, but that will be easy enough, once this issue is solved. So, if somebody who knows JsDoc better than I do can have a look at it, that will definitely save me a lot of time; otherwise, I can investigate further myself.
https://github.com/prismicio/javascript-kit/blob/master/src/utils.js#L64
I would offer a PR, but I can't find a way to get the cache-control header on an XDomainRequest to get the ttl.
I get a red screen when I try to require Prismic. It says
Unable to resolve module http from .../node_modules/prismic.io/lib/requests.js: Invalid directory /Users/node_modules/http
I'm reaching the API directly with Fetch but SDK would have been appreciated.
Edit: no better results with 2.1.0 (saw the release comment on react-native). Now it says :
I got rid of that but then got the same error as with 2.1.3. Did the dirty job...
[error][tid:main] Unable to resolve module es6-promise from .../node_modules/prismic.io/lib/browser.js: Invalid directory /Users/node_modules/es6-promise
Just asking...
Is there a good way to use this kit in a Browserify or Webpack project? I'm not very familiar with the nuts and bolts of their module systems but as far as I can tell this is incompatible.
Latest release doesn't seem to bring the features implemented in github.
Did something go wrong with the deploy?
From the documentation, I can see:
Prismic.Api('https://lesbonneschoses.prismic.io/api', function (err, Api) {
...
});
to make a request to my Prismic repository.
What is the best way to use it to make several requests?
Solution 1:
Prismic.Api('https://lesbonneschoses.prismic.io/api', function (err, Api) {
// 1st request
// 2nd request
...
// nth request
});
Api instance is the same for all requests, which may be an issue when repository is updated between all requests.
Sometimes, api must be requested again to update current Prismic's ref.
Solution 2:
Prismic.Api('https://lesbonneschoses.prismic.io/api', function (err, Api) {
// 1st request
});
Prismic.Api('https://lesbonneschoses.prismic.io/api', function (err, Api) {
// 2nd request
});
...
Prismic.Api('https://lesbonneschoses.prismic.io/api', function (err, Api) {
// nth request
});
Api is requested first for all search request. No problem when Prismic repository is updated during requests, but this costs 1 extra request to API for each search request.
I have seen an apiCache in the JS Kit, with a 5s time-to-live. But I don't understand how to use it.
In "solution 1", this cache seems useless as only Prismic.Api call is checking the cache and there is only one Prismic.Api call.
In "solution 2", this cache seems useless again as each Prismic.Api create an instance of ApiCache, which is not shared between Prismic.Api calls.
And "ApiCache" implementation seems to be private, so I can't give my own instance to Prismic.Api calls.
So what's the best way to use Prismic.Api?
Thank you
HEy Guys,
My project updated from 1.2.2 to 1.3.3 and now initField is throwing an error for any StructuredText fragments. the classForType doesn't know what to do with the blocks element I guess because there is no type property for the fragment...
I'm trying to add bookmark support for the metalsmith-prismic library, but noticed that the getBookmark()
method throws the following exception when called:
Uncaught TypeError: this.getById is not a function
at prismic.fn.prismic.getBookmark (node_modules/prismic.io/dist/prismic.io.js:397:14)
...
The method should probably call getByID
, instead of the nonexistent getById
.
I can circumvent this bug by replicating the functionality of getBookmark
in the calling code, so not a major issue. Mainly an annoyance.
SliceZone.asText()
breaks if the slice zone contains any document links. The problem is that it doesn't take a linkResolver
as an argument, and thus does not pass one to nested fragments.
It seems as if Slice.asText()
would also to be updated to pass the linkResolver
to the nested fragment.
I can create a pull-request to fix this if needed.
Hi guys, just curious.
Why does you library have a Prismic property with the library itself?
var Prismic = require('prismic.io').Prismic
import {Prismic} from 'prismic.io';
Cheers,
jaume
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.