Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ registerHeaderContentHelper({

- {{ extend name options }} -- calls the function options.fn with content of block **name** as param and adds it to named block
- {{ prefixScript url name }} -- add a script tag with version set to script block **name**
- {{ prefixModuleScript url name }} -- add a script tag with type module and with version set to script block **name**
- {{ prefixStyle url name media }} -- add a style tag for named media type with version set to style block **name**
- {{ render name }} -- used by a layout to render script and style blocks in appropriate places
- {{ withVersion url }} -- appends `'?v=' + version` to the passed string
Expand Down
24 changes: 24 additions & 0 deletions lib/handlebars/helpers/headerContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,30 @@ module.exports = function headerContent(options) {
_blocks[blockName].push(`<script src="${url}"></script>`)
})

/** @function prefixModuleScript
*
* @param {string} url -- local path to script excluding proxyPrefixPath
* @param {string} blockName -- (optional) name of script block to include with, defaults to 'scripts'
*
* @return output with {{ render blockName }}
*
* @example
* {{prefixModuleScript '/path/to/script.js' 'scripts'}}
*/
Handlebars.registerHelper('prefixModuleScript', function prefixModuleScript(urlIn, blockNameIn) {
// Check params and give useful error message since stack traces aren't very useable in layouts
if (typeof urlIn !== 'string') {
throw new Error('[prefixModuleScript] helper requires first parameter (url) to be a string. Got: ' + urlIn)
}

const blockName = typeof blockNameIn === 'string' ? blockNameIn : 'scripts'
_blocks[blockName] = _blocks[blockName] || []

const url = `${proxyPrefixPathUri}${urlIn}?v=${encodeURIComponent(version)}`

_blocks[blockName].push(`<script type="module" src="${url}"></script>`)
})

/** @function prefixStyle
*
* @param {string} url -- local path to script excluding proxyPrefixPath
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kth/kth-node-web-common",
"version": "9.0.2",
"version": "9.0.3-0",
"description": "Common components for node-web projects",
"scripts": {
"test": "jest",
Expand Down