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

adamayres/gulp-wrap: A gulp plugin to wrap the stream contents with a lodash tem ...

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

开源软件名称(OpenSource Name):

adamayres/gulp-wrap

开源软件地址(OpenSource Url):

https://github.com/adamayres/gulp-wrap

开源编程语言(OpenSource Language):

JavaScript 100.0%

开源软件介绍(OpenSource Introduction):

gulp-wrap

NPM version Build Status Coverage Status Dependency Status devDependency Status

A gulp plugin to wrap the stream contents with a lodash template.

Usage

First, install gulp-wrap as a development dependency:

npm install --save-dev gulp-wrap

Then, add it to your gulpfile.js:

Wrap the contents with an inline template:

var wrap = require("gulp-wrap");

gulp.src("./src/*.json")
    .pipe(wrap('angular.module(\'text\', []).value(<%= contents %>);', {}, { parse: false /* do not parse the JSON file for template data */ }))
    .pipe(gulp.dest("./dist"));

Wrap the contents with a template from file:

var wrap = require("gulp-wrap");

gulp.src("./src/*.json")
    .pipe(wrap({ src: 'path/to/template.txt'}))
    .pipe(gulp.dest("./dist"));

Use parsed contents within a template (supports JSON and YAML):

var wrap = require("gulp-wrap");

gulp.src("./src/*.json")
    .pipe(wrap('Hello, <%= contents.title %>, have a <%= contents.adjective %> day.'))
    .pipe(gulp.dest("./dist"));

Provide additional data and options for template processing:

var wrap = require("gulp-wrap");

gulp.src("./src/*.json")
    .pipe(wrap('BEFORE <%= data.contents %> <%= data.someVar %> AFTER', { someVar: 'someVal'}, { variable: 'data' }))
    .pipe(gulp.dest("./dist"));

This gulp plugin wraps the stream contents in a template. If you want the stream contents to be the templates use the gulp-template plugin.

Template

The stream contents will be available in the template using the contents key. If the file extension is json, yaml, or yml then the contents will be parsed before being passed to the template. Properties from the vinyl file will be available in the template under the file object and are local to that stream. User supplied data values will always take precedence over namespace clashes with the file properties.

API

wrap(template[,data][,options])

template

Type: String or Object or Function

The template to used. When a String then it will be used as the template. When an Object then the template will be loaded from file. When a Function then the function will be called and should return the template content. This function get the data object as first parameter.

template.src

Type: String

The file location of the template.

data

Type: Object or Function

The data object that is passed on to the lodash template call. When a Function then the function will be called and should return the Object data used in the template.

options

Type: Object or Function

The options object that is passed on to the lodash template call. When a Function then the function will be called and should return the Object used as the options.

options.parse

Type: Boolean

Set to explicit false value to disable automatic JSON and YAML parsing.

options.engine

Type: String

Set the consolidate template engine to use. (default to lodash). Using another engine that lodash may require installation of additional node package.

License

MIT License




鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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