Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
gulp-hogan-compile
Advanced tools
A gulp plugin to compile mustache HTML templates to JavaScript functions using hogan.
A gulp plugin to compile mustache HTML templates to JavaScript functions using hogan.
In templates/test.html
:
<p>Hello {{place}}</p>
In your gulpfile:
var compiler = require('gulp-hogan-compile');
gulp.task('templates', function() {
gulp.src('templates/**/*.html')
.pipe(compiler('templates.js'))
.pipe(gulp.dest('js/'));
});
In your code:
var templates = require('js/templates.js');
var html = templates.test.render({
place: 'world';
})
console.log(html); // <p>Hello world</p>
This will compile the templates into a JavaScript AMD module using hogan.compile
.
It will require('hogan')
so that module needs to be available. You can change the name/path of the hogan module at compile time with options.hoganModule
.
Alternatively you can pass an object to have it populated with executable templates, which is useful if you need templates as part of a build step, for example:
var compiler = require('gulp-hogan-compile');
var templates = {};
gulp.task('templates', function() {
gulp.src('templates/**/*.html')
.pipe(compiler(templates));
});
gulp.task('render', ['templates'], function() {
// Do something with templates, like passing to a static site generator
});
string|object
object
string
The line delimiter, defaults to your operating system's newline. Ignored if dest
is an object.
string
Either amd
, commonjs
or false
for no wrapper, defaults to amd
. If wrapper is false
a local var templates
will be defined containing the templates. Ignored if dest
is an object.
object
Options passed through to hogan.compile
. The asString
option will be set depending on whether output is a file or an object, any passed setting is ignored.
function(file)
A function that will be passed the file and should return a name for the template. By default uses the relative path and basename of the file without an extension.
'templates'
Override the variable name used for the templates, default is templates
. Useful when not using a wrapper in the browser and don't want it assigned to window.templates
.
string
The name of the hogan module in your app, defaults to hogan
. If you're not using a wrapper then the global Hogan
must be available.
FAQs
A gulp plugin to compile mustache HTML templates to JavaScript functions using hogan.
We found that gulp-hogan-compile demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.