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

grunt-tms

v0.1.3

Published

Grunt plugin for juicer2tms

Downloads

5

Readme

grunt-tms

Grunt plugin for juicer2tms

Getting Started

本插件用来将符合Juicer语法的html文件转为符合tms语法的html文件

插件安装:

npm install grunt-tms --save-dev

The "tms" task

Overview

插件安装之后,在Gruntfile.js中开启:

grunt.initConfig({

	...
	
        tms: {
            options: {
                DEFAULT_TITLE: '新默认标题',
                DEFAULT_GROUP: '新默认组',
                DEFAULT_ROW: 2,             // 对列表数据,默认行数,对应"defaultRow"属性
                DEFAULT_MAXROW: 6,          // 对列表数据,默认最大行数,对应"row"属性
                THRESHOLD_MULTISTRING: 2    // 判断为多行文本的阈值:字符串中包含2个以上的标点符号
            },
            main:{
                files: [
                    {
                        expand: true,
                        cwd:'build',
                        // 对'*.tms.html'文件进行juicer2tms转换
                        src: ['**/*.tms.html'],
                        dest: 'build/',
                        ext: '.tms.html'
                    }
                ]
            }
        },
    ...
    
    // 默认构建任务
	grunt.registerTask('build', '默认构建任务', function() {
		task.run([..., 'tms', ...]);
	});
	
	...

});

grunt.loadNpmTasks('grunt-tms');

配置就完成了,执行grunt build就会将src目录下**/*.tms.html文件转为符合tms语法的文件。

注意:为了避免.tms.html被grunt-combohtml再次生成一个.html后缀的文件,建议combohtml任务的配置中main->files->ext属性不指定

Options

options.DEFAULT_TITLE

  • Type: String
  • Default value: 默认标题
  • 生成的<cms:custom title="XXXX">中XXXX的默认值

options.DEFAULT_GROUP

  • Type: String
  • Default value: 默认分组
  • 生成的<cms:custom group="XXXX">中XXXX的默认值

options.DEFAULT_ROW

  • Type: Number
  • Default value: 2
  • 对列表数据,默认行数,对应"defaultRow"属性;生成的<cms:custom defaultRow="XXXX">中XXXX的默认值

options.DEFAULT_MAXROW

  • Type: Number
  • Default value: 6
  • 对列表数据,默认最大行数,对应"row"属性;生成的<cms:custom row="XXXX">中XXXX的默认值

options.THRESHOLD_MULTISTRING

  • Type: Number
  • Default value: 2
  • 判断为多行文本的阈值:字符串中包含2个以上的标点符号

模板书写

数据格式

直接使用mock数据解析生成对应tms标签配置。

由于cms标签中只有cms:repeat可以嵌套其他标签,目前支持的数据格式:

  • http://gtms01.alicdn.com/tps/i1/T11wQaFm4hXXbmaLDS-374-222.png
    • 普通键值对,值为基本类型,用 cms:custom即可解决
  • http://gtms01.alicdn.com/tps/i1/T1wrFzFA8tXXbIsb_B-468-482.png
    • 普通数组,数组项值为上面的普通键值对,用 cms:custom + defaultRow + row要求只有单一key
  • 对于 <cms:repeat> 的支持,采用juicer中的each语法:{@each name in range(min,max)},自动嵌套一层repeat标签,其中nameminmax分别配置到 <cms:repeat> 标签的titledefaultRowrow属性

考虑开发成本和复杂性以及大多数使用场景,beta版暂时不提供复杂数据格式的支持,对于repeat数据对各个字段分别独立定义mock数据

约定及默认配置

  1. 生成的tms标签只用到了 <cms:custom><cms:repeat>,暂不支持其他定制标签
  2. mock数据以 <!--#def --> 包围的区块定义,要求为标准的JSON格式数据,其作用域为 --> 紧跟的html节点的区间
  3. mock数据包含两个可配置属性 cmsTitlecmsGroup,如果不想用自动生成的 titlegroup 属性,可以明确指定
  4. 依赖mock数据的值对其字段类型进行自动解析,大多通过正则完成:
    • url、date、email根据正则
    • boolean根据类型检测
    • 默认为string,包含的标点符号超过2个判定为multiString
    • 建议对于字符串值直接mock数据中写上要生成的fields中的描述,如{"province":"省份"} =><cms..fields="province:省份:string"..>,而不要写成真实的mock值如{"province":"浙江"},对于数组的情况,直接取数组中第一项进行类型解析
  5. 对列表数据,defaultRow 默认值为2,row默认值为6,如果mock数据(即数组)长度超过6则将 row 设为mock数据长度
  6. <cms:repeat> 的支持实际上是拆解为循环中第一项,对第一项各个字段再分别用第2条来完成

Release History

0.1.0

[!]基本完成功能

TODO: cms:repeat用到了juicer中的range语法,但flex-combo暂不支持range语法的预览