eXtensible Template Engine lib for node and the browser

Overview
Comments
  • use faster escapeHtml

    use faster escapeHtml

    实现来自于: https://github.com/component/escape-html ,增加了 xtemplate 里面会转义的字符。

    before:

    no special characters    x 22,928,859 ops/sec ±0.98% (191 runs sampled)
    single special character x  1,926,023 ops/sec ±0.83% (187 runs sampled)
    many special characters  x    687,743 ops/sec ±0.98% (187 runs sampled)
    

    after:

    no special characters    x 22,687,378 ops/sec ±0.79% (192 runs sampled)
    single special character x  6,571,191 ops/sec ±1.33% (190 runs sampled)
    many special characters  x  3,465,183 ops/sec ±1.01% (191 runs sampled)
    
    improved 
    opened by dead-horse 6
  • fix: prefer to resolve from affix

    fix: prefer to resolve from affix

    here is an example:

    data

    {
      ‘startDate': 'Wed Nov 02 2016 14:07:56 GMT+0800 (CST)'
    }
    

    xtpl (pass data as root):

    {{set (startDate = $utils.moment('Wed Nov 02 2016 14:07:56 GMT+0800 (CST)', 'YYYY-MM-DD hh:mm:ss').toDate())}}
    {{startDate.getTime()}}
    

    it will retrieve startDate from origin data, not affix

    opened by denghongcai 4
  • for in

    for in

    现在 each 来做循环,会有一个新的 scope,但是感觉语义上有点纠结,例如:

    {{set (pic = "out side pic")}}
    {{set (array = [{
      "title": "inside title 1",
      "pic": "inside pic 1"
    }, {
      "title": "inside title 2"
    }])}}
    
    {{# each (array) }}
    {{title}}{{pic}}
    {{/ each }}
    

    让人觉得比较晕。

    是否可以考虑加一个类似 for in 的循环:

    {{# for item in array }}
    {{item.title}}{{item.pic}}
    {{/ for }}
    
    question 
    opened by dead-horse 4
  • uglify 后 xxx-render.js  require 错误

    uglify 后 xxx-render.js require 错误

    gulp.task('xtpl', ['clean'], function() {
      gulp.src(paths.xtpl)
        .pipe(gulpXTemplate({
          wrap: 'kissy', // defaults to modulex. set to define compiled to define() or kissy to KISSY.add
          compileConfig: {
            isModule: 1, // defaults to 1. use native template require
            catchError: false // defaults to false. whether to point to line of xtpl when exception occurs(impact performance)
          },
          // runtime:'', defaults to kg/xtemplate/x.y.z/runtime
          suffix: '.xtpl', // defaults to .xtpl. transform xx.tpl -> xx.js
          truncatePrefixLen: 0, //optional, remove the first length string of file path from generate code
          XTemplate: XTemplate // required. xtemplate module
        }))
        // .pipe(uglify()) 
        .pipe(gulp.dest('build'))
    });
    

    使用 CMD 代码组织方式 比如文件 a-render.js 在 config.debug = false 的情况下.

    require 会自动引用 a-render-min.js 经过 uglify 后的代码无法运行了

    opened by noyobo 4
  • 严格模式配置

    严格模式配置

    类似以下的写法,一旦skuProps下不存在skuProps是极容易出问题,定位问题时也较为困难,这也是ES5有严格模式的初衷之一

    {{#with (skuProps)}}
        {{#each (skuProps)}}
    

    同样xtemplate也可考虑支持下严格模式,此时使用with就会报错,提示当前为严格模式,不能使用with:

    xTemplate.strict = true;
    
    opened by yuanyan 4
  • optimize sub template include logic in compiled code

    optimize sub template include logic in compiled code

    current compiled code

    a.xtpl

    {{include('./b')}}{{x}}
    

    a.js

    function(){
      params2.push('./b-xtpl');
      config1.params = params2;
      if(moduleWrap){
         require('./b-xtpl');
      }
    }
    

    optimized compiled code

    a.xtpl

    {{include('./b')}}{{x}}
    

    a.js

    function(){
     var submodule;
     if(moduleWrap){
         submodule = require('./b-xtpl');
     }
     params2.push(submodule  && submodule.TPL_NAME||'./b-xtpl');
     config1.params = params2;
    }
    
    opened by yiminghe 4
  • windows loader路径解析bug

    windows loader路径解析bug

    demo: https://github.com/ngot/xtpl-win-test

    travis:https://travis-ci.org/ngot/xtpl-win-test/builds/210846134

    appveyor: https://ci.appveyor.com/project/ngot/xtpl-win-test

    linux&mac不复现,windows能够复现。

    windows日志:

    pathName: C:\projects\xtpl-win-test\view\home.xtpl
    pathName: header.xtpl
    

    linux日志:

    pathName: /home/travis/build/ngot/xtpl-win-test/view/home.xtpl
    pathName: /home/travis/build/ngot/xtpl-win-test/view/header.xtpl
    
    opened by ngot 3
  • support whitespace control.Fixes #62

    support whitespace control.Fixes #62

    describe('whitespace control', function () {
      it('ltrim works',function(){
        var tpl = [
          ' ',
          '{{~"x"}}',
          ' '
        ].join('');
        var ret = new XTemplate(tpl).render({});
        expect(ret).to.equal('x ');
      });
    
      it('rtrim works',function(){
        var tpl = [
          ' ',
          '{{ "x" ~}}',
          ' '
        ].join('');
        var ret = new XTemplate(tpl).render({});
        expect(ret).to.equal(' x');
      });
    
      describe('block',function(){
        it.only('works inside block',function(){
          var tpl=[
            '{{#each(data)~}}',
            '{{this}}',
            '{{~/each}}'
          ].join('\n');
          var ret = new XTemplate(tpl).render({
            data:[1,2,3]
          });
          expect(ret).to.equal('123');
        });
      });
    });
    
    opened by yiminghe 3
  • Adding *dist* folder by default, for client uses.

    Adding *dist* folder by default, for client uses.

    In our project, we want to download xtemplate via bower ( or npm ) in local.

    Could you please add dist folder by default, so that we can use the download-version without manually build in bower_components (or node_modules) folder.

    opened by threeday0905 3
  • fix: try catch runtime function call error

    fix: try catch runtime function call error

    expect(function () {
          var tpl = '{{obj.error}}\n{{obj.error()}}';
          new XTemplate(tpl).render({
            obj: {
              error: error
            }
          });
        }).to.throwException(function (e) {
        expect(e.message).to.match(/Execute function `obj.error` Error: mock error/);
        expect(e.message).to.match(/line 2/);
      });
    
    opened by dead-horse 3
  • 关于macro与include

    关于macro与include

    新语法需求

    list.xtpl,某一个列表模块作为一个独立模板

    {{#each(list)}}
      <a href="{{url}}">{{title}}</a><br>
    {{/each}}
    

    page.xtpl, 在页面中引用刚刚的模块

    {{set (array = [{
      "url": "",
      "title": ""
    }])}}
    
    {{ includeSection ("list.xtpl", array) }}
    

    希望能增加上面类似includeSection的功能。

    vs macro与include

    1. macro必须要有函数名以及参数,但实际使用时我们往往希望是一个文件即为一个模块,可直接引用文件;
    2. 相对于include, "includeSection"可以传递数据到目标模块,并在内部完成渲染。include返回的是xtpl, "includeSection"返回的是html.

    "includeSection"使用起来比macro更加简单方便。 举个例子,调用一个模块: 使用macro

    {{#macro("list", "array")}}
      {{#each(array)}}
        <a href="{{url}}">{{title}}</a><br>
      {{/each}}
    {{/macro}}
    
    {{include ("../shared/list")}}
    {{macro("list", array)}}
    

    使用"includeSection"

     {{#each(array)}}
       <a href="{{url}}">{{title}}</a><br>
     {{/each}}
    
    {{includeSection ("../shared/list", array)}}
    
    opened by oklai 3
  • set 方法报错

    set 方法报错

    {{ set (metaPageData = {"backgroundImg":{"url":"222","name":"1.png"}}) }}
    

    以上模板会报错

    VM119 seed-min.js:31 Uncaught Error: XTemplate error in file: xtemplate1 syntax error at line 1:
    ....png","name":"1.png"}}) }}
    -----------------------^
    expect reduce:R_BRACE, reduce:COMMA
    
    opened by shenmao1989 1
  • 希望增加模板渲染前的回调

    希望增加模板渲染前的回调

    使得可以在模板渲染前增加统一的模板处理,可以放在config配置项内

      if (tplType === 'string') {
    
        /*------------------------------------------------------------*/
        /* 增加beforeCompile回调 */
        if(typeof config.beforeCompile === 'function'){
          tpl = config.beforeCompile(tpl);
        }
        /*------------------------------------------------------------*/
    
        try {
          tpl = this.compile(tpl, config.name);
        } catch (err) {
          this.compileError = err;
        }
      }
    
    opened by Joker-Jelly 0
Owner
xtemplate
eXtensible Template Engine lib for node and the browser
xtemplate
Semi-embedded JS template engine that supports helpers, filters, partials, and template inheritance. 4KB minzipped, written in TypeScript ⛺

squirrelly Documentation - Chat - RunKit Demo - Playground Summary Squirrelly is a modern, configurable, and blazing fast template engine implemented

Squirrelly 451 Jan 2, 2023
Pug – robust, elegant, feature rich template engine for Node.js

Pug Full documentation is at pugjs.org Pug is a high-performance template engine heavily influenced by Haml and implemented with JavaScript for Node.j

Pug 21.1k Dec 30, 2022
Variation-template - Variation is a PSD template that is covered into a web template using HTML5, CSS3, Bootstrapv4.6, JavaScript.

Variation Template Design Variation is a PSD website template. In this project this template is designed with HTML. Deployment This site is deployed a

Bipronath Saha 1 Jan 1, 2022
The fastest + concise javascript template engine for nodejs and browsers. Partials, custom delimiters and more.

doT Created in search of the fastest and concise JavaScript templating function with emphasis on performance under V8 and nodejs. It shows great perfo

Laura Doktorova 4.9k Dec 31, 2022
Take a swig of the best template engine for JavaScript.

NOT MAINTAINED Fork and use at your own risk. Swig Swig is an awesome, Django/Jinja-like template engine for node.js. Features Available for node.js a

Paul Armstrong 3.1k Jan 4, 2023
1KB lightweight, fast & powerful JavaScript templating engine with zero dependencies. Compatible with server-side environments like node.js, module loaders like RequireJS and all web browsers.

JavaScript Templates Contents Demo Description Usage Client-side Server-side Requirements API tmpl() function Templates cache Output encoding Local he

Sebastian Tschan 1.7k Jan 3, 2023
Browser In The Browser (BITB) Templates

BITB Browser templates for Browser In The Browser (BITB) attack. More information: https://mrd0x.com/browser-in-the-browser-phishing-attack/ Usage Eac

mrd0x 2.5k Jan 5, 2023
A powerful templating engine with inheritance, asynchronous control, and more (jinja2 inspired)

Nunjucks Nunjucks is a full featured templating engine for javascript. It is heavily inspired by jinja2. View the docs here. Installation npm install

Mozilla 8k Dec 30, 2022
Highly opinionated project template for Serverless Framework that follows and applies hexagonal architecture principle to serverless world. Prepared with easy testing in mind.

serverless-hexagonal-template Highly opinionated project template for Serverless Framework that applies hexagonal architecture principles to the serve

Paweł Zubkiewicz 126 Dec 26, 2022
Examples of how to re-create the WordPress Template Hierarchy using headless clients and WPGraphQL

WPGraphQL Template Hierarchy Debugger This is a project to demonstrate how to re-create the WordPress template hierarchy with Headless WordPress using

Jason Bahl 17 Oct 29, 2022
A template to be used for creating js/scss projects and deploy them to github pages

A template to be used for creating js/scss projects and deploy them to github pages

Cariera în IT 15 Oct 30, 2022
Script Template Fivem in Type Script

fivem-ts ?? A Typescript Template for FiveM ?? This is a basic template for creating a FiveM resource using Typescript. It includes webpack config fil

Vinícius Pereira 3 Jun 11, 2021
A K6 Multi Scenario template applying some best practices along some examples

K6-Multi-Scenario-Template It is a performance testing template that shows how to use K6 to implement a Multi Scenario template applying some best pra

Swiss Life OSS 33 Nov 27, 2022
Tailwind & Next Mentorship Template

This is a Next.js project bootstrapped with create-next-app. Getting Started First, run the development server: npm run dev # or yarn dev Open http://

Nauval 21 May 22, 2022
Template to create reactjs component library which will help you to create your dream library.

reactjs-library-template Template to create reactjs component library which will help you to create your dream library. How to use Commands to setup e

Nishant Tomar 1 Dec 25, 2021
Low tech template for a reduced carbon impact :seedling:

Enverse minimalist front-end template ?? ?? For all else, use Astro.build ?? Recomended package manager: pnpm Preact + Typescript + Vite How to use: F

null 2 Jan 10, 2022
Obsidian To HTML, A template for building obsidian style notes to a static site

oth (Obsidian To HTML) This is a template for publishing obsidian notes as a static site. The goal of the project is to stay minimal, since this is a

Ulisse mini 11 Nov 4, 2022
My discord.js bot template

My discord.js Bot Template This repository is an ongoing project to extract core pieces of the discord.js bots and ecosystems I run into a reusable te

Ian Mitchell 8 Mar 3, 2022
Asynchronous Javascript templating for the browser and server

Dust.js Asynchronous Javascript templating for the browser and server. This fork is maintained by LinkedIn. Install NPM Important: We recommend that y

LinkedIn 2.9k Dec 31, 2022