Security News
Opengrep Emerges as Open Source Alternative Amid Semgrep Licensing Controversy
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
@hopin/render
Advanced tools
`hopin-render` uses mustache rendering with a set of wrappers to make it easier to group templates and partials as "components" with CSS and JS. This allows CSS and JS to be loaded in a "best practice-y" way.
npm install @hopin/render --save
There are two approaches to using @hopin/render
, create a template file and
use that to generate your HTML or use a string and use that as a template.
Create a template file, in this case template.tmpl
, with any scripts, styles or partials
you want to include:
---
styles:
inline:
- ./inline-styles-for-template-tmpl.css
sync:
- ./sync-styles-for-template-tmpl.css
async:
- ./async-styles-for-template-tmpl.css
scripts:
inline:
- ./inline-scripts-for-template-tmpl.js
sync:
- ./sync-scripts-for-template-tmpl.js
async:
- ./async-scripts-for-template-tmpl.js
partials:
- ./templates/nav.tmpl
---
<html>
<head>
<title>Example page title</title>
<!-- Load all inline and sync styles in head of document -->
{{hopin_headAssets}}
</head>
<body>
{{> "./templates/nav.tmpl"}}
<main>
<!-- TODO: Add main content here -->
</main>
<!-- Load inline, sync, async scripts and async styles -->
{{hopin_bodyAssets}}
</body>
</html>
Tell hopin to compile the template and render it.
const {compileFile} = require('@hopin/render');
const templatePath = path.join(__dirname, 'template.tmpl');
const template = await compileFile(templatePath);
const data = {
hello: 'world',
};
const options = {
styles: {
inline: ['/* Add Inline CSS Here */'],
sync: ['/synchronous-styles-here.css'],
async: ['/asynchronous-styles-here.css'],
},
scripts: {
inline: ['/* Add Inline JS Here */'],
sync: ['/synchronous-scripts-here.css'],
async: ['/asynchronous-scripts-here.css'],
},
};
const htmlString = await template.render(data, options);
console.log(htmlString);
const {compile} = require('@hopin/render');
const tmplString = `
---
styles:
inline:
- /user/matt/site/styles/index.css
---
{{hopin_headAssets}}
{{hopin_bodyAssets}}
`;
const template = await compile(tmpString);
const result = await template.render();
You can pass in an option "relative path" variable to the compile function so paths for styles and scripts can be relative.
const {compile} = require('@hopin/render');
const tmplString = `
---
styles:
inline:
- styles/index.css
---
{{hopin_headAssets}}
{{hopin_bodyAssets}}
`;
const template = await compile(tmpString, '/user/matt/site/');
const result = await template.render();
FAQs
Module to render HTML, CSS and JS in a "best practice-y" way.
We found that @hopin/render demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.