1.0.0 • Published 7 years ago
@hyron/viewer v1.0.0
used to render views using popular view engines. include
- pug
- ejs
- hbs
Usage
1. Install plugins
@hyron/viewer is normal plugins. so you need to declared like another hyron plugins to used
app.json
{
"base_url" : "http://localhost:3000",
"plugins" : {
"viewer": "@hyron/viewer"
}
}after that run build file to install plugins. Using @hyron/cli
hyron startyou also install using npm or yarn engine
2. create view file
By default, @hyron/viewer will read file inside ./views dir from root to parser view file
you also custom this path used appcfg using root properties
appcfg.yaml
# 'viewer' that name was declared above
viewer:
root: '/public'Example
<!DOCTYPE html>
html(lang="en")
head
meta(charset="UTF-8")
meta(name="viewport", content="width=device-width, initial-scale=1.0")
meta(http-equiv="X-UA-Compatible", content="ie=edge")
title hello world
body
h1 hello, this is @hyron/viewer demo3. declare for view router
To allow a router render a view, you need to declare it in requestConfig. and using $render( string | object ) properties to pass data to render view
/services/ViewDemo.js
module.exports = class ViewDemo {
static requestConfig(){
return {
$all : {
plugins: ["viewer"]
},
getView : "get"
}
}
getView(){
return {
$render : {
path : "/demo.pug"
}
}
}
}1.0.0
7 years ago