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

71 lines
1.7 KiB
JavaScript
Raw 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-01-27 16:12:06 +09:00
}) => [
'<html' + Object.keys(htmlAttributes || {}).map(
key => template(' <%= attrName %>="<%- attrValue %>"')({
attrName: key,
attrValue: htmlAttributes[key],
})
).join('') + '>',
'<head>',
head,
dynamicHead,
2018-01-27 16:12:06 +09:00
...(css || []).map(file =>
template(' <link rel="stylesheet" type="text/css" class="__meteor-css__" href="<%- href %>">')({
href: bundledJsCssUrlRewriteHook(file.url),
})
),
2018-01-27 16:12:06 +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>'
].join('\n');