在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:codemix/htmling开源软件地址:https://github.com/codemix/htmling开源编程语言:JavaScript 82.5%开源软件介绍:HTMLingPolymer compatible HTML5 based templating syntax for node.js. Render your templates server-side using the same syntax as in the browser, with no virtual DOM trickery required. For a full demonstration, please see htmling-demo-app. Installationvia npm
ExampleTurns this: <!doctype html>
<html>
<head>
<title>{{title}}</title>
<meta name="description" content="{{description}}">
</head>
<body>
<h1>{{title}}</h1>
<ul>
<template repeat="{{user in users}}">
<li>{{user.name}}</li>
</template>
</ul>
</body>
</html> plus this: {
"title": "User List",
"description": "A list of users",
"users": [
{
"name": "Alice"
},
{
"name": "George"
}
]
} into this: <!doctype html>
<html>
<head>
<title>User List</title>
<meta name="description" content="A list of users">
</head>
<body>
<h1>User List</h1>
<ul>
<li>Alice</li>
<li>George</li>
</ul>
</body>
</html> How it worksUnlike similar libraries, HTMLing does not require a virtual DOM such as jsDOM. Instead, HTMLing
parses This compilation process happens only once, and the resulting JavaScript is extremely efficient. UsageHTMLing is easy to integrate with your existing build process, either via the command line or library interfaces. CLIHTMLing ships with a small command line interface: Compile an individual fileThe compiled output will be written to STDOUT
Compile an individual file to a destinationThe compiled output will be written to
Compile a directory hierarchyCompile a nested directory structure to a directory called
Compile a directory hierarchy to a single fileCompile a nested directory structure to a single called
As a LibraryIt's also possible to use HTMLing as a library: Compile a stringvar HTMLing = require('htmling');
var template = HTMLing.string('Hello {{name}}');
console.log(template.render({name: 'Charles'})); // "Hello Charles" Compile a filevar template = HTMLing.file('./index.html');
console.log(template.render()); Compile a directoryvar templates = HTMLing.dir('./pages');
console.log(templates.render('index.html', {})) Using as an express view engineHTMLing has support for express.js. var HTMLing = require('htmling');
app.configure(function(){
app.engine('html', HTMLing.express(__dirname + '/views/'));
app.set('view engine', 'html');
}); In development mode, you'll probably want to enable the var HTMLing = require('htmling');
app.configure(function(){
app.engine('html', HTMLing.express(__dirname + '/views/', {watch: true}));
app.set('view engine', 'html');
}); LicenseMIT, see LICENSE.md. Docker environmentAll you need is Docker with We have a fancy shortcut to get your application up and running, and you also get access to the container terminal: $ make build
$ make run From this point, it's just a matter of starting the application from within the container shell: htmling:~/app(master)$ npm test Other fancy shortcuts we have for Docker fans
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论