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

troian

v1.1.20

Published

fast epic template engine

Downloads

44

Readme

Troian

Another awesome template engine. It's small and effective to use. It really has a big potential.


Install

for install simply type this command.

npm install troian

Abilities

• Lightweight

Troian is really small. it doesn't need any big dependency.

• Developer Friendly

Developed views has simple comments. This action gives developer hints.

• Autorestart

When any file changed in view folder, troian automaticly re-compiles file.

• Fast

It has special algorithm that makes some thing faster.


Examples

You can find my example project at here

Features

Easy to Start

First you need to require troian. Call it with directory function. This function reads directory and finds recursively troian files. directory function returns object that has all files

var troian = require('troian');
var template = troian.directory(__dirname + '/views/');
template.filename(); // renders "filename.troian" file

Recursive folders

Troian has recursive folder reader. So if you need folders you can simply use access operator.

var troian = require('troian');
var template = troian.directory(__dirname + '/views/');
template.index(); // renders /views/index.troian
template.partials.header(); // renders /views/partials/header.troian
template.a.b.c.d(); // renders /views/a/b/c/d.troian

Template files

Template files designed as down below. troian tag are not required but it's highly recommended. You can give information inside of tag.

<troian>
	Info
</troian>

Code tags

If you want to specify some code, you should put it between <% and %> tags.

<troian>
	Hello this is code tags example
</troian>
<%
	console.log("hello");
%>

if you want to print some thing on screen simply use print function

<troian>
	Hello this is code tags example
</troian>
<%
	var a = 5;
	print(a);
%>

also you can use <%( and )%> tags too.

<troian>
	Hello this is code tags example
</troian>
<%
	var a = 5;
%>
<%(a)%>

they do same job.

Parametric templates

You can give parameters for templates. With parameters you can call views with variables.

var troian = require('troian');
var template = troian.directory(__dirname + '/views/');
template.index(5);
<troian params="count">
	count will be 5 and print 5
</troian>
<%(count)%>

If you want to more params you simply do like down below

<troian params="count, a, b, c">
	count will be 5 and print 5
</troian>
<%(count)%>

Another big thing about parametric template files, you can define statics.

<troian count="5" my_variable="hello">
	count will be 5 and print 5
</troian>
<%(count)%>

Static field

Static field only runs one time. You can use this field for define unchangeable things or global things... It can be really usefull. As you can see down below, we just define count in static field and we simple do count++ every request.

<troian>
	This view just counts.
	<%static
		var count = 0;
	%>
</troian>
<%(count++)%>

Template Including

if we want to include some other template we can simply use <%+( and %)> inside we just give file name and paranthesis. this parathesis needing because all templates in troian are acting like function and has parameters.

index.troian

<troian>
	This view is parent.
</troian>
<%+(child())%>

child.troian

<troian>
	This view is chield.
</troian>
Hi master.

result

Hi master.

another example


index.troian

<troian>
	This view is parent.
</troian>
parent:<%+(child(15))%>

child.troian

<troian params="a">
	This view is chield.
</troian>
child:<%(a)%>

result

parent:child:15

Template Including with Code

you can use template object for render another template.

<troian>
	This view is template including with code
</troian>
<%
	var rendered = template.another(5);
	print(rendered);
%>

Standard HTML codes for use

we developed simply html generator.. You can use them too.

Note: HTML Codes are in beta for now. They can be unstable sometime. Please if you had any trouble, contact to us.

<troian>
	This view is Standard HTML codes for use
</troian>
<%(html.a("/link", "This is a link"))%>

or

<troian>
	This view is Standard HTML codes for use
	<%static
		var link = html.a("/link", "This is a link");
	%>
</troian>
<%
	print(link);
%>

HTML Options

HTML Options can be setted as down below.

<troian>
	This view is HTML Options
	<%static
		var link = html.a("/link", {
		    class: "linkClass", 
		    style: {
		        background_color: "red"
		    }
		},"This is a link");
	%>
</troian>
<%
	print(link);
%>
<troian>
	This view is HTML Options
	<%static
	    var link = html.a("/link", {
            class: "linkClass", 
            style: {
                background_color: "red"
            }
        }, "This is a link");
        	
		var div = html.tag("div", {
		    class: "divClass", 
		    style: {
		        background_color: "black",
		        border: "1px solid red"
		    }
		}, link);
	%>
</troian>
<%
	print(div);
%>