• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

paulwib/gulp-hogan-compile

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

paulwib/gulp-hogan-compile

开源软件地址(OpenSource Url):

https://github.com/paulwib/gulp-hogan-compile

开源编程语言(OpenSource Language):

JavaScript 100.0%

开源软件介绍(OpenSource Introduction):

gulp-hogan-compile NPM version Build Status

A gulp plugin to compile mustache HTML templates to JavaScript functions using hogan.

Usage

In templates/test.html:

<p>Hello {{place}}</p>

In your gulpfile:

var compiler = require('gulp-hogan-compile');

gulp.task('templates', function() {
    gulp.src('templates/**/*.html')
        .pipe(compiler('templates.js'))
        .pipe(gulp.dest('js/'));
});

In your code:

    var templates = require('js/templates.js');
    var html = templates.test.render({
        place: 'world';
    })
    console.log(html); // <p>Hello world</p>

This will compile the templates into a JavaScript AMD module using hogan.compile.

It will require('hogan') so that module needs to be available. You can change the name/path of the hogan module at compile time with options.hoganModule.

Alternatively you can pass an object to have it populated with executable templates, which is useful if you need templates as part of a build step, for example:

var compiler = require('gulp-hogan-compile');
var templates = {};

gulp.task('templates', function() {
    gulp.src('templates/**/*.html')
        .pipe(compiler(templates));
});

gulp.task('render', ['templates'], function() {
    // Do something with templates, like passing to a static site generator
});

Parameters

  • dest string|object
    • Either the name of a file or an object - if using an object it will be populated with compiled template code and no file will be outputted (so all string output related options below are ignored)
  • options object
    • Options passed to the hogan task

Options

newLine string

The line delimiter, defaults to your operating system's newline. Ignored if dest is an object.

wrapper string

Either amd, commonjs or false for no wrapper, defaults to amd. If wrapper is false a local var templates will be defined containing the templates. Ignored if dest is an object.

templateOptions object

Options passed through to hogan.compile. The asString option will be set depending on whether output is a file or an object, any passed setting is ignored.

templateName function(file)

A function that will be passed the file and should return a name for the template. By default uses the relative path and basename of the file without an extension.

templatesVariableName 'templates'

Override the variable name used for the templates, default is templates. Useful when not using a wrapper in the browser and don't want it assigned to window.templates.

hoganModule string

The name of the hogan module in your app, defaults to hogan. If you're not using a wrapper then the global Hogan must be available.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
manabuyasuda/gulp-pug-test发布时间:2022-06-21
下一篇:
trygve-lie/gulp-dom: Gulp plugin for generic DOM manipulation发布时间:2022-06-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap