-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update paper 2.x branch to pull in latest helpers #204
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
language: node_js | ||
sudo: false | ||
node_js: | ||
- 6 | ||
- 8 | ||
- 10 | ||
script: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use strict'; | ||
const { getObjectStorageImage } = require('../lib/getObjectStorageImage') | ||
|
||
function helper(paper) { | ||
paper.handlebars.registerHelper('getContentImage', function(path) { | ||
const cdnUrl = paper.settings['cdn_url'] || ''; | ||
|
||
const options = arguments[arguments.length - 1]; | ||
|
||
return getObjectStorageImage(cdnUrl, 'content', path, options); | ||
}); | ||
} | ||
|
||
module.exports = helper; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use strict'; | ||
const { getObjectStorageImageSrcset } = require('../lib/getObjectStorageImage') | ||
|
||
function helper(paper) { | ||
paper.handlebars.registerHelper('getContentImageSrcset', function(path) { | ||
const cdnUrl = paper.settings['cdn_url'] || ''; | ||
|
||
return getObjectStorageImageSrcset(cdnUrl, 'content', path); | ||
}); | ||
} | ||
|
||
module.exports = helper; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use strict'; | ||
const { getObjectStorageImage } = require('../lib/getObjectStorageImage') | ||
|
||
function helper(paper) { | ||
paper.handlebars.registerHelper('getImageManagerImage', function(path) { | ||
const cdnUrl = paper.settings['cdn_url'] || ''; | ||
|
||
const options = arguments[arguments.length - 1]; | ||
|
||
return getObjectStorageImage(cdnUrl, 'image-manager', path, options); | ||
}); | ||
} | ||
|
||
module.exports = helper; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use strict'; | ||
const { getObjectStorageImageSrcset } = require('../lib/getObjectStorageImage') | ||
|
||
function helper(paper) { | ||
paper.handlebars.registerHelper('getImageManagerImageSrcset', function(path) { | ||
const cdnUrl = paper.settings['cdn_url'] || ''; | ||
|
||
return getObjectStorageImageSrcset(cdnUrl, 'image-manager', path); | ||
}); | ||
} | ||
|
||
module.exports = helper; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
'use strict'; | ||
const utils = require('handlebars-utils'); | ||
const max_length = 1024; | ||
const max_keys = 50; | ||
|
||
function helper(paper) { | ||
paper.handlebars.registerHelper('getVar', function (key) { | ||
if (!utils.isString(key)) { | ||
throw new Error("getVar helper key must be a string"); | ||
} | ||
|
||
return paper.variables[key] | ||
}); | ||
|
||
paper.handlebars.registerHelper('assignVar', function (key, value) { | ||
// Validate that key is a string | ||
if (!utils.isString(key)) { | ||
throw new Error("assignVar helper key must be a string"); | ||
} | ||
|
||
// Validate that value is a string or integer | ||
if (!utils.isString(value) && !Number.isInteger(value)) { | ||
throw new Error("assignVar helper value must be a string or a number (integer)"); | ||
} | ||
|
||
// Validate that string is not longer than the max length | ||
if (utils.isString(value) && value.length >= max_length) { | ||
throw new Error(`assignVar helper value must be less than ${max_length} characters, | ||
but a ${value.length} character value was set to ${key}`); | ||
} | ||
|
||
// Make sure the number of total keys is within the limit | ||
if (Object.keys(paper.variables).length >= max_keys) { | ||
throw new Error(`Unique keys in variable storage may not exceed ${max_keys} in total`); | ||
} | ||
|
||
// Store value for later use by getVar helper | ||
paper.variables[key] = value; | ||
}); | ||
|
||
paper.handlebars.registerHelper('incrementVar', function (key) { | ||
if (!utils.isString(key)) { | ||
throw new Error("incrementVar helper key must be a string"); | ||
} | ||
|
||
if (Number.isInteger(paper.variables[key])) { | ||
// Increment value if it already exists | ||
paper.variables[key] += 1; | ||
} else { | ||
// Make sure the number of total keys is within the limit | ||
if (Object.keys(paper.variables).length >= max_keys) { | ||
throw new Error(`Unique keys in variable storage may not exceed ${max_keys} in total`); | ||
} | ||
// Initialize or re-initialize value | ||
paper.variables[key] = 0; | ||
} | ||
|
||
// Return current value | ||
return paper.variables[key]; | ||
}); | ||
|
||
paper.handlebars.registerHelper('decrementVar', function (key) { | ||
if (!utils.isString(key)) { | ||
throw new Error("decrementVar helper key must be a string"); | ||
} | ||
|
||
if (Number.isInteger(paper.variables[key])) { | ||
// Decrement value if it already exists | ||
paper.variables[key] -= 1; | ||
} else { | ||
// Make sure the number of total keys is within the limit | ||
if (Object.keys(paper.variables).length >= max_keys) { | ||
throw new Error(`Unique keys in variable storage may not exceed ${max_keys} in total`); | ||
} | ||
// Initialize or re-initialize value | ||
paper.variables[key] = 0; | ||
} | ||
|
||
// Return current value | ||
return paper.variables[key]; | ||
}); | ||
} | ||
|
||
module.exports = helper; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
'use strict'; | ||
const utils = require('handlebars-utils'); | ||
const common = require('./common'); | ||
const SafeString = require('handlebars').SafeString; | ||
|
||
const srcsets = { | ||
'80w': '80w', | ||
'160w': '160w', | ||
'320w': '320w', | ||
'640w': '640w', | ||
'960w': '960w', | ||
'1280w': '1280w', | ||
'1920w': '1920w', | ||
'2560w': '2560w', | ||
}; | ||
|
||
function getObjectStorageImage(cdnUrl, source, path, options) { | ||
if (!utils.isString (path) || common.isValidURL(path)) { | ||
throw new TypeError("Invalid image path - please use a filename or folder path starting from the appropriate folder"); | ||
} | ||
|
||
// Return original image if there are no arguments | ||
let size = 'original'; | ||
|
||
if (Number.isInteger(options.hash['width'])) { | ||
if (Number.isInteger(options.hash['height'])) { | ||
// Return image of specified size | ||
size = `${options.hash['width']}x${options.hash['height']}` | ||
} else { | ||
// Return image of specified width | ||
size = `${options.hash['width']}w` | ||
} | ||
} | ||
|
||
return new SafeString(`${cdnUrl}/images/stencil/${size}/${source}/${path}`); | ||
} | ||
|
||
function getObjectStorageImageSrcset(cdnUrl, source, path) { | ||
if (!utils.isString (path) || common.isValidURL(path)) { | ||
throw new TypeError("Invalid image path - please use a filename or folder path starting from the appropriate folder"); | ||
} | ||
|
||
return new SafeString(Object.keys(srcsets).map(descriptor => { | ||
return ([`${cdnUrl}/images/stencil/${srcsets[descriptor]}/${source}/${path} ${descriptor}`].join(' ')); | ||
}).join(', ')); | ||
} | ||
|
||
module.exports = { | ||
getObjectStorageImage, | ||
getObjectStorageImageSrcset | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing this as we no longer use 6.