Vulcan/packages/_boilerplate-generator/template-web.browser.js

77 lines
2 KiB
JavaScript
Raw Permalink Normal View History

2018-01-27 16:12:06 +09:00
import template from './template';
2018-01-27 16:12:06 +09:00
export const headTemplate = ({
css,
htmlAttributes,
bundledJsCssUrlRewriteHook,
head,
dynamicHead,
2018-06-10 10:37:33 +09:00
}) => {
var headSections = head.split(/<meteor-bundled-css[^<>]*>/, 2);
var cssBundle = [...(css || []).map(file =>
2018-01-27 16:12:06 +09:00
template(' <link rel="stylesheet" type="text/css" class="__meteor-css__" href="<%- href %>">')({
href: bundledJsCssUrlRewriteHook(file.url),
})
2018-06-10 10:37:33 +09:00
)].join('\n');
return [
'<html' + Object.keys(htmlAttributes || {}).map(
key => template(' <%= attrName %>="<%- attrValue %>"')({
attrName: key,
attrValue: htmlAttributes[key],
})
).join('') + '>',
'<head>',
dynamicHead,
(headSections.length === 1)
? [cssBundle, headSections[0]].join('\n')
: [headSections[0], cssBundle, headSections[1]].join('\n'),
2018-06-10 10:37:33 +09:00
'</head>',
'<body>',
].join('\n');
};
2018-01-27 16:12:06 +09:00
// Template function for rendering the boilerplate html for browsers
export const closeTemplate = ({
meteorRuntimeConfig,
rootUrlPathPrefix,
inlineScriptsAllowed,
js,
additionalStaticJs,
bundledJsCssUrlRewriteHook,
}) => [
'',
inlineScriptsAllowed
? template(' <script type="text/javascript">__meteor_runtime_config__ = JSON.parse(decodeURIComponent(<%= conf %>))</script>')({
conf: meteorRuntimeConfig,
})
: template(' <script type="text/javascript" src="<%- src %>/meteor_runtime_config.js"></script>')({
src: rootUrlPathPrefix,
}),
'',
2018-01-27 16:12:06 +09:00
...(js || []).map(file =>
template(' <script type="text/javascript" src="<%- src %>"></script>')({
src: bundledJsCssUrlRewriteHook(file.url),
})
),
2018-01-27 16:12:06 +09:00
...(additionalStaticJs || []).map(({ contents, pathname }) => (
inlineScriptsAllowed
? template(' <script><%= contents %></script>')({
contents,
})
: template(' <script type="text/javascript" src="<%- src %>"></script>')({
src: rootUrlPathPrefix + pathname,
})
)),
2018-01-27 16:12:06 +09:00
'',
'',
'</body>',
'</html>'
2018-06-10 10:37:33 +09:00
].join('\n');