Skip to content

Commit

Permalink
Merge pull request #75 from nzzdev/release-2.6.0
Browse files Browse the repository at this point in the history
v 2.6.0
  • Loading branch information
benib committed Oct 30, 2017
2 parents bd505c0 + a0bd356 commit 4c93ec0
Show file tree
Hide file tree
Showing 13 changed files with 2,038 additions and 1,062 deletions.
2 changes: 2 additions & 0 deletions docs/_data/navigation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ main:
url: rendering-info.html
- title: "toolRuntimeConfig"
url: tool-runtime-config.html
- title: "Plugins"
url: "plugins.html"
- title: "Migrations"
url: "migrations.html"
8 changes: 5 additions & 3 deletions docs/about-targets.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,15 @@ const tools = {
## Preview in Q editor
To have a preview environment that matches your target as close as possible, you can configure stylesheets and scripts that will be loaded within the Shadow Root of the preview element in Q editor in _config/targets.js_. Use these to load any stylesheets and scripts that may influence the behaviour of your visual element when embedded in the target environment.
To have a preview environment that matches your target as close as possible, you can configure stylesheets and scripts that will be loaded within the Shadow Root of the preview element in Q editor in _config/targets.js_. Use these to load any stylesheets and scripts that may influence the behaviour of your visual element when embedded in the target environment. Any stylesheets and scripts configured in `context` will be loaded in the preview.
```javascript
const targets = [
{
key: 'demo1',
label: 'Demo 1',
preview: {
type: 'web',
context: {
stylesheets: [
/*{
url: 'url to stylesheet specific for target'
Expand All @@ -113,7 +114,8 @@ const targets = [
{
key: 'demo2',
label: 'Demo 2',
preview: {
type: 'web',
context: {
stylesheets: [
/*{
url: 'url to stylesheet specific for target'
Expand Down
2 changes: 1 addition & 1 deletion docs/assets/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ a:hover {
}

header, main, footer {
max-width: 760px;
max-width: 900px;
margin: 0 auto;
}

Expand Down
37 changes: 37 additions & 0 deletions docs/plugins.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
title: Plugins
---

## screenshot
To use the screenshot plugin you have to configure it.
You do this by passing these settings in the `hapi` object in the config object passed to Q server init function:
```javascript
init({
hapi: {
plugins: {
'q-screenshot': {
methods: {
getScripts: function(renderingInfo) {
const scripts = [];
// implement your specific loader logic here, turning whatever your tools return as renderingInfo
// into an array of scripts. every object in this array needs to have one of two properties: content, url
return scripts;
},
getStylesheets: function(renderingInfo) {
const stylesheets = [];
// implement your specific loader logic here, turning whatever your tools return as renderingInfo
// into an array of stylesheets. every object in this array needs to have one of two properties: content, url
return stylesheets;
}
}
}
}
},
config: {
// ...
}
}
```
You need to have a _config/targets.js_ in your Q server implementation that configures the targets to be used with the screenshot api as `type: 'web'`.
This gives you an endpoint `/screenshot/{id}.png?target=your_target&width=600&dpr=2&background=white&padding=20` where `dpr` (default: `1`), `background` (default: no background) and `padding` (default: `0`) are optional.
46 changes: 30 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const defaultOptions = {
]
}

module.exports.init = function(options = {hapi: {}, config: {}}, callbacks) {
module.exports.init = async function(options = {hapi: {}, config: {}}, callbacks) {
let hapiOptions = Object.assign(
defaultOptions,
options.hapi,
Expand All @@ -43,9 +43,12 @@ module.exports.init = function(options = {hapi: {}, config: {}}, callbacks) {
}
});

let plugins = require('./server-plugins');
let routes = require('./routes/routes');
if (typeof callbacks === 'object' && callbacks['onBeforePlugins']) {
await callbacks['onBeforePlugins'](server)
}

let plugins = require('./server-plugins');

// if couchdb-cookie-auth-strategy is enabled, we load the required plugin
const couchdbCookieStrategy = options.config.misc.get('/authStrategy/couchdb_cookie');
if (couchdbCookieStrategy) {
Expand All @@ -61,24 +64,34 @@ module.exports.init = function(options = {hapi: {}, config: {}}, callbacks) {
})
}

if (server.settings.plugins && server.settings.plugins.hasOwnProperty('q-screenshot')) {
plugins = plugins.concat(require('./plugins/q-screenshot/index.js'));
}

server.register(plugins, async (err) => {
Hoek.assert(!err, err);
try {
Hoek.assert(!err, err);

if (typeof callbacks === 'object' && callbacks['onBeforeRoutes']) {
await callbacks['onBeforeRoutes'](server)
}
if (typeof callbacks === 'object' && callbacks['onBeforeRoutes']) {
await callbacks['onBeforeRoutes'](server)
}

// register the auth strategy if any
if (couchdbCookieStrategy) {
require('./auth/couchdb-cookie/strategy');
require('./auth/couchdb-cookie/state');
server.route(require('./auth/couchdb-cookie/routes'));
}
// register the auth strategy if any
if (couchdbCookieStrategy) {
require('./auth/couchdb-cookie/strategy');
require('./auth/couchdb-cookie/state');
server.route(require('./auth/couchdb-cookie/routes'));
}

server.route(routes);
let routes = require('./routes/routes').getRoutes();
server.route(routes);

if (typeof callbacks === 'object' && callbacks['onAfterRoutes']) {
await callbacks['onAfterRoutes'](server)
if (typeof callbacks === 'object' && callbacks['onAfterRoutes']) {
await callbacks['onAfterRoutes'](server)
}
} catch (e) {
console.log(e);
process.exit(1);
}
});
}
Expand All @@ -89,6 +102,7 @@ module.exports.start = function(callback) {
let server = getServer();

server.start(() => {
server.log(['info'], `server running: ${server.info.uri}`);
console.log('server running: ', server.info.uri);
if (callback) {
callback(server.info);
Expand Down
Loading

0 comments on commit 4c93ec0

Please sign in to comment.