npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gulp-hbs-router

v1.0.6

Published

Gulp plugin that runs a router file, converting them to HTML

Downloads

4

Readme

gulp-hbs-router

NPM version

Gulp plugin that runs like a router, converting template language into HTML.

Why you need?
  • When you don't want to use some frontend framwork like react, vue, angular... cuz your website actually isn't need it...
  • Multiple pages controlled by module.
  • If you are a senior frontend-er. You should try!

Install

npm install gulp-hbs-router --save-dev

Usage

const gulpHbsRouter = require('gulp-hbs-router');

gulp.src('./layout/**/*.hbs')
    .pipe(gulpHbsRouter({
	    cwdPath: `${__dirname}/`,
	    routerPath: 'hbsRouter.js',
	    partialPath: 'partial.js',
	    minify: true,
    }))
    .pipe(gulp.dest('./'))

You have to create ./hbsRouter.js ./partial.js

  • hbsRouter.js : Listing all Templata DATA here. You can set data(object) in this file, and each data correspond into its file independently. Default: './hbsRouter.js'.

  • partial.js : You should write your partial here. Then, router will catch partial by this file in handlebars. Default: './partial.js'.

How to write? Look Example.

API

gulpHbsRouter([, options])

  • cwdPath (default ../../) In gulp-hbs-router, we should get data from 'hbsRouter.js' and partial from 'partial.js' , so we need to set the cwdPath

  • routerPath (default 'hbsRouter.js') set router's path.

  • partialPath (default 'partial.js') set partial's path.

  • minify (default false) set to minify html.

  • compile (default to handlebars.compile) compile options. See handlebars reference for possible values

gulpHbsRouter.registerHelper(name, helperFn)

Register a handlebars helper.

Example

gulpfile.js

const gulp = require('gulp');
const gulpHbsRouter = require('gulp-compile-handlebars');
const gulpPlumber = require('gulp-plumber');

gulp.task('hbs', () => {
  gulp.src(['./layout/**/*.hbs'])
    .pipe(gulpPlumber())
    .pipe(gulpPlumber())
    .pipe(gulpHbsRouter({
	  cwdPath: `${__dirname}/`,
      minify: true,
    }))
    .pipe(gulp.dest('./'));
})

./hbsRouter.js

const hbsRouter = {
  home: {
    description: 'I love home.',
    title: 'Home',
  },
  index: {
    description: 'Simple router',
    title:'Gulp-Hbs-Router Example',
  }
};

module.exports = hbsRouter;

./partial.js

const fs = require('fs');
const DEFAULT_PATH = 'partial/';

module.exports = (hbs) => {
  hbs.registerPartial('head', getPartials('head.hbs', DEFAULT_PATH));
  hbs.registerPartial('footer', getPartials('footer.hbs', DEFAULT_PATH));
};

function getPartials(filename, path) {
  const template = fs.readFileSync(`./layout/${path}${filename}`, 'utf8');
  return template;
}

./layout/index.hbs ./layout/home.hbs

<head>
  {{> head}}
  <title>{{title}}</title>
</head>
<body>
  <h1>Hi, {{title}}</h1>
  {{> footer}}
</body>

./layout/partial/head.hbs

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=2.0">
<meta htt0-equiv = "X-UA-Compatible" content = "IE=edge">
<meta name="description" content="{{description}}" >

./layout/partial/footer.hbs

<footer>
  <h1>The end!</h1>
</footer>

You have to add in STRUCTURE

...

- gulpfile.js
- hbsRouter.js
- partial.js
- layout/
	- index.hbs
	- home.hbs

	partial/
		- head.hbs
		- footer.hbs

...

License

MIT © TsaHang