All Projects → wushufen → wutpl

wushufen / wutpl

Licence: other
高性能模板引擎 (js template)

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to wutpl

rottenjs
An all-in-one (2.6kb) Javascript library for web development
Stars: ✭ 15 (-82.35%)
Mutual labels:  dom
tempo
UI framework for the web
Stars: ✭ 15 (-82.35%)
Mutual labels:  dom
capsid
💊 Declarative DOM programming library. Lightweight (1.79 kb).
Stars: ✭ 76 (-10.59%)
Mutual labels:  dom
vanilla-jsx
Vanilla jsx without runtime. HTML Tag return DOM in js, No virtual DOM.
Stars: ✭ 70 (-17.65%)
Mutual labels:  dom
move-into-view
move-into-view is such as sroll-into-view but better
Stars: ✭ 33 (-61.18%)
Mutual labels:  dom
swayer
Schema based frontend framework 👀
Stars: ✭ 40 (-52.94%)
Mutual labels:  dom
react-append-to-body
React Higher order component that allows you to attach components to the DOM outside of the main app.
Stars: ✭ 30 (-64.71%)
Mutual labels:  dom
vue-identify-network
⚡ Identify what kinda internet your users are using!
Stars: ✭ 60 (-29.41%)
Mutual labels:  dom
ngx-event-modifiers
Event Modifiers for Angular Applications https://netbasal.com/implementing-event-modifiers-in-angular-87e1a07969ce
Stars: ✭ 14 (-83.53%)
Mutual labels:  dom
prax
Experimental rendering library geared towards hybrid SSR+SPA apps. Focus on radical simplicity and performance. Tiny and dependency-free.
Stars: ✭ 18 (-78.82%)
Mutual labels:  dom
theBookOfNoah
Everything ive learned developing web applications
Stars: ✭ 22 (-74.12%)
Mutual labels:  dom
zebrajs
A modular, jQuery compatible, ultra light-weight JavaScript micro-library for modern browsers
Stars: ✭ 26 (-69.41%)
Mutual labels:  dom
jsdom-devtools-formatter
Make jsdom elements look like real DOM elements in Chrome Devtools console
Stars: ✭ 40 (-52.94%)
Mutual labels:  dom
zero-drag
Minimal abstraction of DOM drag-and-drop interactions
Stars: ✭ 17 (-80%)
Mutual labels:  dom
JavaScript-Bootcamp
Complete Documentation For JavaScript Bootcamp Course By Osama Elzero.
Stars: ✭ 27 (-68.24%)
Mutual labels:  dom
foliage
🍃 Style your components with performance
Stars: ✭ 29 (-65.88%)
Mutual labels:  dom
go-xmldom
XML DOM processing for Golang, supports xpath query
Stars: ✭ 38 (-55.29%)
Mutual labels:  dom
BabyBrowser
A Small Web Browser Built in Python
Stars: ✭ 21 (-75.29%)
Mutual labels:  dom
JsObjExporter
A little JavaScript plugin to generate PDF, XLS, CSV and DOC from JavaScript Object or DOM element only from the frontend!
Stars: ✭ 58 (-31.76%)
Mutual labels:  dom
MapML
Map Markup Language is hypertext for Web maps, like HTML is hypertext for Web pages https://maps4html.org/MapML/spec/
Stars: ✭ 48 (-43.53%)
Mutual labels:  dom

wutpl.js

极简高性能模板引擎

特点

本模板引擎主要解决以下问题

  • 有的模板引擎语法太复杂或者比较奇怪
  • 有的模板引擎性能性能较差,比如使用了 with
  • 有的模板引擎不能直接使用全局变量(比如 parseInt, Math, JSON 等)
  • 有的模板引擎使用变量需要加前缀,比如 this.value, data.value, it.value

性能测试

点这测试
性能测试

使用方法

<!DOCTYPE html>
<html>

<head>
  <!-- 1: 引入wutpl,支持 es6 requireJS seaJS -->
  <script src="../wutpl.js"></script>
</head>

<body>

  <!-- 2: 编写模板 -->
  <div id="tpl">
    {for list item}
    <span>{item}</span>
    {/for}
  </div>

  <!-- 3: 编译与渲染 -->
  <script>
    var render = wutpl(tpl)
    render({
      list: [1, 2, 3]
    })
  </script>

</body>

</html>

安装

npm i -D wutpl

or

<script src="../wutpl.js"></script>

API

var render = wutpl(tpl)
var html = render(data)
var html = wutpl(tpl, data)
  • tpl: {String|Node} 字符串模板或者dom节点,dom节点使用innerHTML作为模板
  • data: {Object} 模板数据
  • render(data): {Function} 渲染函数,若模板为dom节点,render会自动更新视图
  • html: {String} 渲染后的html字符串

模板语法

  • 超简洁的模板语法
 {for array item index?} {/for}

 {for object value key? index?} {/for}

 {if bool} yes {else} no {/if}

 {text}

 {#html}
  • wutpl-src
<!-- 如果用html节点做为模板,浏览器解析到该节点马上就请求{src},会有一个不必要的404 -->
<img src="{src}">
<!-- 可以这样去掉这个404 -->
<img wutpl-src="{src}">
  • table each
<!-- 如果用html节点做为模板, `<table>` 等标签之间是不允许有文本的,可用注释写法 -->
<table>
  <tbody>
    <!-- {for list item} -->
    <tr>
      <td>{item.name}</td>
    </tr>
    <!-- {/for} -->
  </tbody>
</table>

标签配置

默认

  wutpl.leftTag = '<!-- {|{'
  wutpl.rightTag = '} -->|}'

可以自定义为双花括号

  wutpl.leftTag = '<!-- {{|{{'
  wutpl.rightTag = '}} -->|}}'

实例

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].