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

gulp-teddy

v1.6.2

Published

Teddy template compiler gulp plugin

Downloads

22

Readme

Build Status npm version Dependency Status semantic-release Commitizen friendly GitHub license

gulp-teddy

Compiles Teddy templates

Install

$ npm install --save-dev gulp-teddy

Usage

src/html/index.html

<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width">
    <title>Title</title>
</head>

<body>
    <include src='templates/header.html'>
        <arg mainTitle>Main title</arg>
    </include>
</body>

</html>

src/html/templates/header.html

<header>
    <if mainTitle>
        <h1>{mainTitle}</h1>
    </if>
    <else>
        <p>No main title</p>
    </else>
</header>

gulpfile.js

var gulp  = require('gulp'),
    teddy = require('gulp-teddy').settings({
        setTemplateRoot: 'src/html/'
    });

gulp.task('default', () => gulp.src(['src/html/**/*.html','!src/html/templates/**/*.html'])
    .pipe(teddy.compile())
    .pipe(gulp.dest('dist'))
);

dist/index.html

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <meta name="description" content="" />
    <meta name="viewport" content="width=device-width" />
    <title>Title</title>
</head>

<body>
    <header>
        <h1>Main title</h1>
    </header>
</body>

</html>

Passing data

Passing data as an object

src/html/index.html

<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width">
    <title>Title</title>
</head>

<body>
    <loop through='letters' val='letter'>
        <p>{letter}</p>
    </loop>
</body>

</html>

gulpfile.js

var gulp  = require('gulp'),
    teddy = require('gulp-teddy').settings({
        setTemplateRoot: 'src/html/'
    });

gulp.task('default', () => gulp.src(['src/html/**/*.html', '!src/html/templates/**/*.html'])
    .pipe(teddy.compile({
        letters: ['a', 'b', 'c']
    }))
    .pipe(gulp.dest('dist'))
);

dist/index.html

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <meta name="description" content="" />
    <meta name="viewport" content="width=device-width" />
    <title>Title</title>
</head>

<body>
    <p>a</p>
    <p>b</p>
    <p>c</p>
</body>

</html>

Passing data with gulp-data

For example from a json file, you can use it together the above example, your data will be merged (extended)

src/html/index.html

<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width">
    <title>Title</title>
</head>

<body>
    <if subTitle>
        <h2>{subTitle}</h2>
    </if>
    <if subData and subData.level1>
        <ul>
            <loop through='subData.level1' key='name' val='text'>
                <li>
                    <strong>{name}</strong>
                    <br />{text}
                </li>
            </loop>
        </ul>
    </if>
</body>

</html>

src/data/index.json

{
    "subTitle": "Sub title",
    "subData": {
        "level1": {
            "sd1": "sub data 1",
            "sd2": "sub data 2",
            "sd3": "sub data 3"
        }
    }
}

gulpfile.js

var gulp = require('gulp'),
    data = require('gulp-data'),
    path = require('path'),
    teddy = require('gulp-teddy').settings({
        setTemplateRoot: 'src/html/templates/'
    });


gulp.task('default', function() {
    return gulp.src(['src/html/**/*.html', '!src/html/templates/**/*.html'])
        .pipe(data(function(file) {
            return require('./src/data/' + path.basename(file.path, '.html') + '.json');
        }))
        .pipe(teddy.compile({
            letters: ['a', 'b', 'c']
        }))
        .pipe(gulp.dest('dist'));
});

dist/index.html

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <meta name="description" content="" />
    <meta name="viewport" content="width=device-width" />
    <title>Title</title>
</head>

<body>
    <h2>Sub title</h2>
    <ul>
        <li>
            <strong>sd1</strong>
            <br/>sub data 1
        </li>
        <li>
            <strong>sd2</strong>
            <br/>sub data 2
        </li>
        <li>
            <strong>sd3</strong>
            <br/>sub data 3
        </li>
    </ul>
</body>

</html>

API

teddy.settings(options)

options

Type: Object

{
    setTemplateRoot: './',
    setVerbosity: 0,
    strictParser: false,
    enableForeachTag: false,
    compileAtEveryRender: false
}

See the Teddy docs.

teddy.compile(data)

data (optional)

Type: Object

Notes

The compile method executes the original teddy.render() method with a template path and the optional data param.

The original teddy.compile() method is not allowed, this plugin is for generating static html files with the help of the Teddy templating engine functionalities.