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

tasap

v1.1.1

Published

Barebones Template Engine for static HTML files

Downloads

288

Readme

tasap.js

tasap.js is a HTML-Template-Engine meant to build modular HTML-Templates as ~soon~ fast as possible. Its syntax is compatible with, and falls back to basic HTML. tasap.js allows no conditional templates and only provides minor options for interpolation. tasap.js allows reusable and nested Modules/Components with an extremely low learning curve, resulting in faster prototyping, efficient preparations and seamless integration.

Example

Defining a module

Reusable Modules get defined with the <Module name="ModuleName"> Tag. The tags-attributes get loaded into the Modules local state and can recieve data on module initialisation. -> ./modules/offer.html

<Module name="Offer" title="no title set" description="no description" link="#no-link">
	<article class="offer">
		<h3>{{ state.title }}</h3>
		<p>
			{{ state.description }}
		</p>
		<a href="{{ state.link }}">Buy now!</a>
	</article>
</Module>

Passing children to a module

A Module can have unlimited children of any type (tags, text or modules). These are automatically loaded into the local state and can be rendered by invoking Block() or state.Block(). -> ./modules/row.html

<Module name="Row">
	<div class="row">
		{{ Block() }}
	</div>
</Module>

Expressions

tasap.js offers two ways to interact with data. {{ }} evaluates the expression and renders its value into the html (see above). {{# }} on the other end, does not get rendered into the html. -> ./modules/column.html

<Module name="Column" sizes>
	{{# state.sizes = utils.prefixArray(utils.toArray(state.sizes), 'size-') }}
	<div class="column {{ state.sizes.join(' ') }}">
		{{ Block() }}
	</div>
</Module>

Loading Modules

Modules can be defined anywhere inside the HTML-File. If you move the modules to individual files like I did in this example. You can use {{@ }} to load files or directories dynamically. Individual modules get invoked by using their name as the html-tag. -> ./index.html

{{@ ./modules/*.html }}
<Row>
	<Column sizes="small-12 medium-3 large-7">
		<Offer title="Car 1" description="This car is amazing" link="/link-to-car1.html"></Offer>
	</Column>
	<Column sizes="small-12 medium-3 large-7">
		<Offer title="Car 2" description="This car is amazing too" link="/link-to-car2.html"></Offer>
	</Column>
</Row>

Compiles into:

The above example renders into the following HTML Content.

<div class="row">
    <div class="column size-small-12 size-medium-3 size-large-7">
        <article class="offer">
            <h3>Car 1</h3>
            <p> This car is amazing </p>
            <a href="/link-to-car1.html">Buy now!</a>
        </article>
    </div>
    <div class="column size-small-12 size-medium-3 size-large-7">
        <article class="offer">
            <h3>Car 2</h3>
            <p> This car is amazing too </p>
            <a href="/link-to-car2.html">Buy now!</a>
        </article>
    </div>
</div>

Dynamic Tags

tasap.js uses a special attribute identifier prefixed with @. Currently the only use for these attributes are dynamic changing of html tagnames. All attributes starting with @ will not get rendered in the finished html.

Using the @tag attribute replaces its tagname with the attribute value if it is not empty or undefined.

<Module name="MyModule" tag>
	<div @tag="{{ state.tag }}"></div>
</Module>

<MyModule></MyModule>
<MyModule tag="article"></MyModule>
<MyModule tag="section"></MyModule>

Compiles into:

<div></div>
<article></article>
<section></section>

Utility Methods

tasap.js comes with a small utils API of utility functions helping processing and modifying state.

// Transform a string to an array
utils.toArray(string, 'delimiter')

// Prefix every string in an array
utils.prefixArray(array, 'prefix')

// Suffix every string in an array
utils.suffixArray(array, 'suffix')

This utils API gets exposed outside of the internal tasap-workflow. This allows you to use these methods outside of tasap.js and mainly extend the utility class with custom static variables and methods.

const tasap = require('tasap');
tasap.utils.myFunction = function(){
    return 'Hello World';
}
tasap.utils.myVariables = 123;

and in the tasap html-files

<Module name="MyModule">
    <p> Function: {{ utils.myFunction() }} </p>
    <p> Variable: {{ utils.myVariables }} </p>
</Module>

<MyModule></MyModule>

Compiles into:

<p> Function: Hello World </p>
<p> Variable: 123 </p>

Usage

const tasap = require('tasap');

// Compiling single fiels or content
tasap.get(['header.html', 'index.html', 'footer.html']); // Compiles all files into one files and returns the result
tasap.get('<div></div>'); // Compiles the given Content

// Compiling multiple files
tasap.getAll(['header.html', 'index.html', 'footer.html']); // Compiles all files into sepearte fiels and returns the array

// Compile and write file
tasap.writeFile(['index.html'], 'dist/index.html'); // Writes the compiled file to the target directory
tasap.writeFile('<div></div>', 'dist/index.html'); // Compiles the given Content and writes it to the target directory
tasap.writeAll('templates/*.html', 'dist/'); // Compiles all matching files to the target directory