gulp-hbs-router
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 = ; gulp
./hbsRouter.js
./partial.js
You have to create -
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'.
Example.
How to write? LookAPI
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 thecwdPath
-
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 = ;const gulpHbsRouter = ;const gulpPlumber = ; gulp
./hbsRouter.js
const hbsRouter = home: description: 'I love home.' title: 'Home' index: description: 'Simple router' title:'Gulp-Hbs-Router Example' ; moduleexports = hbsRouter;
./partial.js
const fs = ;const DEFAULT_PATH = 'partial/'; module { hbs; hbs;}; { const template = fs; return template;}
./layout/index.hbs
./layout/home.hbs
{{> head}} {{title}} Hi, {{title}} {{> footer}}
./layout/partial/head.hbs
./layout/partial/footer.hbs
The end!
You have to add in STRUCTURE
...
- gulpfile.js
- hbsRouter.js
- partial.js
- layout/
- index.hbs
- home.hbs
partial/
- head.hbs
- footer.hbs
...