npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

arale-templatable

v1.0.4

Published

处理组件的模板渲染,混入到 Widget 中使用。

Downloads

16

Readme

Templatable


spm package Build Status Coverage Status

处理组件的模板渲染,混入到 Widget 中使用。


使用说明

可混入的功能类,提供 Handlebars 模板支持。

var Templatable = require('templatable');

var MyWidget = Widget.extend({
    Implements: Templatable
});

var myWidget = new MyWidget({
    template: '<div><h3>{{title}}</h3><ol>{{#each list}}<li>{{item}}</li>{{/each}}</div>',
    model: {
        'title': '标题',
        'list': [
            { 'item': '文章一' },
            { 'item': '文章二' }
        ]
    },
    parentNode: '#demo'
});

myWidget.render();

Templatable 在渲染的时候会读取 this.get('model')this.get('template'),这两个是实例化的时候传入的,最终生成 this.element

this.get('template') 支持多种格式:

  1. html 的字符串

  2. id 选择器,最常用而且判断简单

  3. 函数,通过 handlerbars 编译过的模板

renderPartial .renderPartial(selector)

局部渲染,根据传入的 selector 参数,刷新匹配的区域。

默认无需覆盖。需要覆盖时,请使用 return this 来保持该方法的链式约定。

this.set('model', {
  title: '新标题'
});
this.renderPartial('h3');

templateHelpers

可以使用 handlebars 的 helper,由于 handlerbars 是全局注册,所以每次编译都会重新注册。

示例二

templatePartials

可以使用 handlebars 的 partials。