Coder Social home page Coder Social logo

thunf / swiger Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 0.0 1.65 MB

Make swig(the best template engine for JavaScript) work better.

Home Page: https://thunf.github.io/swiger

License: MIT License

Makefile 2.39% JavaScript 94.62% HTML 2.28% Shell 0.72%

swiger's Introduction

Swiger Build Status Dependency Status NPM version NPM Downloads

Swiger is an awesome, Django/Jinja-like template engine for node.js.

Thanks

Thank Paul and previous swig collabs for their hard and excellent work!

Paul Armstrong has stepped down as the primary swig maintainer.

Documentation

All documentation can be viewed online on the Swiger Website.

Features

  • Available for node.js and major web browsers!
  • Express compatible.
  • Object-Oriented template inheritance.
  • Apply filters and transformations to output in your templates.
  • Automatically escapes all output for safe HTML rendering.
  • Lots of iteration and conditionals supported.
  • Robust without the bloat.
  • Extendable and customizable. See Swig-Extras for some examples.
  • Great code coverage.

Installation

npm install swiger

Basic Example

Template code

<h1>{{ pagename|title }}</h1>
<ul>
{% for author in authors %}
    <li{% if loop.first %} class="first"{% endif %}>{{ author }}</li>
{% endfor %}
</ul>

node.js code

var swig  = require('swig');
var template = swig.compileFile('/absolute/path/to/template.html');
var output = template({
    pagename: 'awesome people',
    authors: ['Paul', 'Jim', 'Jane']
});

Output

<h1>Awesome People</h1>
<ul>
    <li class="first">Paul</li>
    <li>Jim</li>
    <li>Jane</li>
</ul>

For working example see examples/basic

Need Help? Have Questions? Comments?

How it works

Swig reads template files and translates them into cached javascript functions. When we later render a template we call the evaluated function, passing a context object as an argument.

License

MIT

swiger's People

Contributors

airandfingers avatar almad avatar asabhaney avatar bohnman avatar cyberwombat avatar d42f avatar djebbz avatar ecaron avatar elliotf avatar fbardelli-shutterstock avatar fzaninotto avatar greelgorke avatar hogart avatar imbcmdth avatar janka102 avatar jinze avatar logie17 avatar maratfm avatar nilya avatar nka11 avatar nsaun avatar p-baleine avatar paularmstrong avatar skid avatar stanfeldman avatar stayradiated avatar sufianrhazi avatar thunf avatar wilsaj avatar zmetcalf avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.