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

think-template-art

v2.0.0

Published

art-template template adapter for ThinkJS

Downloads

11

Readme

think-template-art for ThinkJS

Install

  npm install think-template-art

How to use

注册 adapter

添加文件src/common/bootstrap/adapter.js.

import artTemplate from 'think-template-art';
think.adapter('template', 'art', artTemplate);

配置

修改配置文件 src/common/config/view.js:

export default {
  type: 'art',
  content_type: 'text/html',
  file_ext: '.html',
  file_depr: '_',
  root_path: think.ROOT_PATH + '/view',
  helper_path: think.RESOURCE_PATH+'/static/js/template.helper.js',
  adapter: {
    ejs: {},
    art: {
        //这里书写 art-template 配置,如果基础配置存在,将覆盖基础配置
    }
  }
};

helper函数配置

修改 config/view中的 helper_path helper函数的格式为

!(function(){

    let helpers  = {};

    /**
     * 对日期进行格式化,
     * @param date 要格式化的日期
     * @param format 进行格式化的模式字符串
     *     支持的模式字母有:
     *     y:年,
     *     M:年中的月份(1-12),
     *     d:月份中的天(1-31),
     *     h:小时(0-23),
     *     m:分(0-59),
     *     s:秒(0-59),
     *     S:毫秒(0-999),
     *     q:季度(1-4)
     * @return String
     */
    helpers.dateFormat = function (date, format) {
        if( [].toString.call(date) != '[object Date]' ){
            date = new Date(date-0);
        }
        var map = {
            "M": date.getMonth() + 1, //月份
            "d": date.getDate(), //日
            "h": date.getHours(), //小时
            "m": date.getMinutes(), //分
            "s": date.getSeconds(), //秒
            "q": Math.floor((date.getMonth() + 3) / 3), //季度
            "S": date.getMilliseconds() //毫秒
        };

        console.log(map);
        format = format.replace(/([yMdhmsqS])+/g, function(all, t){
            var v = map[t];
            if(v !== undefined){
                if(all.length > 1){
                    v = '0' + v;
                    v = v.substr(v.length-2);
                }
                return v;
            }
            else if(t === 'y'){
                return (date.getFullYear() + '').substr(4 - all.length);
            }
            return all;
        });
        return format;
    };

    // RequireJS && SeaJS
    if (typeof define === 'function') {
        define(function() {
            return helpers;
        });
    // NodeJS
    } else if (typeof exports !== 'undefined') {
        module.exports = helpers;
    } else {
        this.helpers = helpers;
    }
})();

拷贝后放到你需要的位置

如果你需要同构页面务必把文件放到 /www/static

辅助方法的例子 | art-template文档 | ThinkJS文档

LICENSE

MIT