ptpl

0.0.2 • Public • Published

拷贝html模版文件内容到js文件


  • 简介

读取并转换html模版文件内容为字符串(去掉文件中的换行),替换JS文件里相应引用此文件的地址为转换后的字符串。方便mustache、underscore等模板库解析文件。

  • 安装

npm install ptpl -g

  • 使用

命令行定位到需要转换的目录内,
输入ptpl,或者 ptpl [自定义标记符]

  • 用例(example)

    JS-file:

    // 变量名格式为:标记+文件路径。默认标记“ptpl-text!”
    // 模版文件路径为./xxViewTemp.html
    var tpl = '<!--ptpl-text!./xxViewTemp.html-->'; // 只能为‘单引号’括起来
    var tpl1 = '<!--ptpl-text!../yyViewTemp.html-->';

    // use in mustach or underscore
    // var compiledTemplate = Mustache.compile(tpl);
    // var templateOutput = compiledTemplate(templateData);

    html-file : ( xxViewTemp.html )
    <span>name:{{name}</span>

  • 注意

变量的值必须为单引号,不能为双引号括起来,并且以‘<!--ptpl-...’开头。
要转换html模版文件所在的各级目录名 以及html模版文件的文件名,不能包含.tpl、.htm、.html等“关键字”。
最好用默认标记“ptpl-text!”,标记支持自定义,但需要保证与js文件里其他字符不能重复。

Readme

Keywords

none

Package Sidebar

Install

npm i ptpl

Weekly Downloads

0

Version

0.0.2

License

BSD

Last publish

Collaborators

  • warmhug