Gathering detailed insights and metrics for grunt-handlebars-layouts
Gathering detailed insights and metrics for grunt-handlebars-layouts
npm install grunt-handlebars-layouts
Typescript
Module System
Min. Node Version
Node Version
NPM Version
44.6
Supply Chain
82.6
Quality
67.1
Maintenance
25
Vulnerability
95.7
License
JavaScript (81.46%)
HTML (18.54%)
Love this project? Help keep it running β sponsor us today! π
Total Downloads
28,242
Last Day
7
Last Week
55
Last Month
347
Last Year
2,585
MIT License
14 Stars
85 Commits
10 Forks
4 Watchers
3 Branches
3 Contributors
Updated on Jun 10, 2020
Latest Version
0.3.0
Package Id
grunt-handlebars-layouts@0.3.0
Size
11.50 kB
NPM Version
3.10.9
Node Version
6.9.2
Cumulative downloads
Total Downloads
Last Day
-53.3%
7
Compared to previous day
Last Week
-36.8%
55
Compared to previous week
Last Month
81.7%
347
Compared to previous month
Last Year
51.5%
2,585
Compared to previous year
5
1
Handlebars helpers which implement Jade-like layout blocks.
A grunt.js task to render Handlebars templates against a context & produce HTML.
If you want to pre-compilation your Handlebars use the grunt-contrib-handlebars Grunt task. This task will pre-compile multiple templates into a single file.
This task renders Handlebars templates against a context to produce HTML.
Inspired by grunt-dust-html and handlebars-layouts
This plugin requires Grunt ~0.4.0
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
1npm install grunt-handlebars-layouts --save-dev
Next, add this line to your project's grunt file:
1grunt.loadNpmTasks("grunt-handlebars-layouts");
This plugin was designed to work with Grunt 0.4.x. If you're still using grunt v0.3.x it's strongly recommended that you upgrade, but in case you can't please use v0.3.3.
Lastly, add the configuration settings (see below) to your grunt file.
This task has two required properties, src
and dest
. src
is the path to your source file and dest
is the file this task will write to (relative to the grunt.js file). If this file already exists it will be overwritten.
1 files: { 2 'dest.html': 'src.html' 3 },
An example configuration looks like this:
1 grunt.initConfig({
2 handlebarslayouts: {
3 home: {
4 files: {
5 'dist/home.html': 'src/home.html'
6 },
7 options: {
8 partials: [
9 'src/partials/*.hbs',
10 'src/layout.html'
11 ],
12 modules: [
13 'src/helpers/helpers-*.js'
14 ],
15 basePath: 'src/',
16 context: {
17 title: 'Layout Test',
18 items: [
19 'apple',
20 'orange',
21 'banana'
22 ]
23 }
24 }
25 }
26 }
27 });
28 grunt.registerTask('default', ['handlebarslayouts']);
This plugin can be customized by specifying the following options:
partials
: partials files.basePath
: The base location to all your templates so that includes/partials can be resolved correctly.context
: A JavaScript object to render the template against. This option supports a few different types:modules
: add your customs helpersstrict
: when is true the process fails if one file is missing (when is false juste a warning is trigger)Useful Handlebars Helpers : handlebars-helpers
String: the location to a file containing valid JSON:
1context: '/path/to/file.json'
Object: a regular ol' JavaScript object:
1context: { 2 pageTitle: 'My Awesome Website' 3}
Array: an array of contexts, either string (files to parse) or JavaScript objects (>= 0.2.5), or both. Each item in the array will be merged into a single context and rendered against the template:
1context: [ 2 'path/to/context.json', 3 'path/to/another/context.json', 4 { more: 'data' } 5]
__filename (add in 0.2.7)
This is the resolved local path of this src file.
use it like {{ __filename }}
or in combination with a helper
{{slug __filename}}
Take a look to the example/example_4/.
1{{#extend "layout"}} 2 {{#append "head"}} 3 <link rel="stylesheet" href="assets/css/home.css" /> 4 {{/append}} 5 6 {{#replace "body"}} 7 <h2>Welcome Home</h2> 8 9 <ul> 10 {{#items}} 11 <li>{{.}}</li> 12 {{/items}} 13 </ul> 14 {{/replace}} 15 16 {{#prepend "footer"}} 17 <script src="assets/js/analytics.js"></script> 18 {{/prepend}} 19{{/extend}}
1<!DOCTYPE html> 2<html lang="en"> 3 <head> 4 <meta charset="utf-8"> 5 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 6 {{#block "head"}} 7 <title>{{title}}</title> 8 <meta name="description" content=""> 9 {{/block}} 10 </head> 11 12 <body> 13 <div class="site"> 14 <div class="site-hd" role="banner"> 15 {{#block "header"}} 16 <h1>{{title}}</h1> 17 {{/block}} 18 </div> 19 20 <div class="site-bd" role="main"> 21 {{#block "body"}} 22 <h2>Hello World</h2> 23 {{/block}} 24 </div> 25 26 <div class="site-ft" role="contentinfo"> 27 {{#block "footer"}} 28 <small>© 2014</small> 29 {{/block}} 30 </div> 31 </div> 32 33 {{#block "footer"}} 34 <p>footer</p> 35 {{/block}} 36 37 {{> footer}} 38 </body> 39</html>
1<footer>footer</footer>
Helpers can either be an object or a single register function. If register is on the object, then it calls the register function, passing in the engine.
1module.exports.register = function (Handlebars, options) { 2 Handlebars.registerHelper('foo', function () { 3 return 'foo'; 4 }); 5};
1'use strict'; 2 3var crypto = require('crypto'), 4 fs = require('fs'); 5 6// The module to be exported 7var helpers = { 8 md5: function (path) { 9 var content = fs.readFileSync(path); 10 return crypto.createHash('md5').update(content).digest('hex'); 11 } 12}; 13 14// Export helpers 15module.exports.register = function (Handlebars, options) { 16 options = options || {}; 17 18 for (var helper in helpers) { 19 if (helpers.hasOwnProperty(helper)) { 20 Handlebars.registerHelper(helper, helpers[helper]); 21 } 22 } 23};
1'use strict'; 2 3// The module to be exported 4var helpers = { 5 foo: function () { 6 return 'foo'; 7 }, 8 bar: function () { 9 return 'bar'; 10 } 11}; 12 13// Export helpers 14module.exports.register = function (Handlebars, options) { 15 options = options || {}; 16 17 for (var helper in helpers) { 18 if (helpers.hasOwnProperty(helper)) { 19 Handlebars.registerHelper(helper, helpers[helper]); 20 } 21 } 22};
Very simple Markdown for partial. do not forget to add your .md files to the partial list.
1options: { 2 partials: 'src/partials/*.md', 3 ... 4}
1/** 2 * Handlebars Markdown Helpers 3 * Copyright (c) 2014 Thierry Charbonnel 4 * Licensed under the MIT License (MIT). 5 */ 6'use strict'; 7 8var marked = require('marked'); 9 10// Export helpers 11module.exports.register = function (Handlebars, options) { 12 options = options || {}; 13 options.marked = options.marked || { 14 renderer: new marked.Renderer(), 15 gfm: true, 16 tables: true, 17 breaks: false, 18 pedantic: false, 19 sanitize: true, 20 smartLists: true, 21 smartypants: false 22 }; 23 24 Handlebars.registerHelper('md', function(name, context){ 25 var result; 26 marked.setOptions(options.marked); 27 // Convert inline markdown by prepending the name string with `:` 28 if(name.match(/^:/)) { 29 result = marked(name.replace(/^:/, '')); 30 } else { 31 try { 32 result = marked(Handlebars.partials[name]); 33 } catch(err) { 34 result = '<!-- error -->'; 35 } 36 } 37 return new Handlebars.SafeString(result); 38 }); 39}; 40
Add it in devDependencies and in gruntfiles.js
1"devDependencies": { 2 "handlebars-helper-moment": "*" 3},
Add it in gruntfiles.js
1handlebarslayouts: { 2 home: { 3 files: { 4 'dist/home.html': 'src/home.html', 5 'dist/index.html': 'src/index.html' 6 }, 7 options: { 8 ... 9 modules: ['src/helpers/helpers-*.js', 'handlebars-helper-moment'], 10 ... 11 } 12 } 13}
or ( v0.1.4 > )
1handlebarslayouts: { 2 home: { 3 files: { 4 'dist/*.html': 'src/*.hsb' 5 }, 6 options: { 7 ... 8 modules: ['src/helpers/helpers-*.js', 'handlebars-helper-moment'], 9 ... 10 } 11 } 12}
npm install
.
βββ partials
| βββ footer.(html|hsb|md)
| βββ header.(html|hsb|md)
βββ pages
| βββ 2014-08-14-Handlebars-layouts-foo.(html|hsb)
| βββ 2014-08-14-Handlebars-layouts-bar.(html|hsb)
βββ data
| βββ members.json
βββ helpers
| βββ helpers-*.js
βββ index.html
1
2/*global module:false*/
3module.exports = function(grunt) {
4 'use strict';
5 grunt.initConfig({
6
7 handlebarslayouts: {
8 dev: {
9 files: {
10 //'dist/home.html': 'src/home.html'
11 'dist/*.html': 'src/*.hsb'
12 },
13 options: {
14 partials: ['src/partials/*.hbs', 'src/partials/*.md', 'src/layout.html'],
15 basePath: 'src/',
16 modules: ['src/helpers/helpers-*.js', 'handlebars-helper-moment'],
17 context: {
18 title: 'Layout Test',
19 projectName: 'Grunt handlebars layout',
20 items: [
21 'apple',
22 'orange',
23 'banana'
24 ]
25 }
26 }
27 }
28 },
29
30 connect: {
31 server: {
32 options: {
33 livereload: true,
34 port: 8000,
35 base:'dist/',
36 open: true
37 }
38 }
39 },
40
41 watch: {
42 layout: {
43 files: 'src/layout.html',
44 tasks: 'handlebarslayouts:dev'
45 },
46 hsb: {
47 files: 'src/**/*.hsb',
48 tasks: 'handlebarslayouts:dev'
49 },
50 options: {
51 livereload: true
52 }
53 },
54
55 });
56
57 grunt.loadTasks('../tasks');
58
59 grunt.loadNpmTasks('grunt-contrib-connect');
60 grunt.loadNpmTasks('grunt-contrib-watch');
61
62 grunt.registerTask('default', ['handlebarslayouts']);
63
64 grunt.registerTask('serve', ['handlebarslayouts', 'connect:server', 'watch']);
65
66};
67
68
69
70
71
=======
Copyright Β© 2014 Thierry Charbonnel, contributors.
Released under the MIT license
Soon. Help is welcome. (contact me)
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 2/27 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
66 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-02-10
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More