Coder Social home page Coder Social logo

foxycart / twig.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from twigjs/twig.js

1.0 12.0 0.0 9 MB

JS implementation of the Twig Templating Language

License: BSD 2-Clause "Simplified" License

Makefile 0.19% JavaScript 96.57% CSS 1.24% HTML 1.97% Shell 0.03%

twig.js's Introduction

Build Status NPM version

About

Twig.js is a pure JavaScript implementation of the Twig PHP templating language (http://twig.sensiolabs.org/)

The goal is to provide a library that is compatible with both browsers and server side JavaScript environments such as node.js.

Twig.js is currently a work in progress and supports a limited subset of the Twig templating language (with more coming).

Docs

Documentation is available in the twig.js wiki on Github.

Feature Support

For a list of supported tags/filters/functions/tests see the Implementation Notes page on the wiki.

Contributing

If you have a change you want to make to twig.js, feel free to fork this repository and submit a pull request on Github. The source files are located in src/*.js. twig.js is built by running make

For more details on getting setup, see the contributing page on the wiki.

Browser Usage

Twig.js can be installed as a bower package with:

bower install twig.js

Include twig.js or twig.min.js in your page, then:

var template = twig({
    data: 'The {{ baked_good }} is a lie.'
});

console.log(
    template.render({baked_good: 'cupcake'})
);
// outputs: "The cupcake is a lie."

Node Usage

Twig.js can be installed with NPM

npm install twig

You can use twig in your app with

var Twig = require('twig'), // Twig module
    twig = Twig.twig;       // Render function

Twig is compatable with express 2 and 3. You can create an express app using the twig.js templating language by setting the view engine to twig.

app.js

Express 3

var Twig = require("twig"),
    express = require('express'),
    app = express();

// This section is optional and used to configure twig.
app.set("twig options", {
    strict_variables: false
});

app.get('/', function(req, res){
  res.render('index.twig', {
    message : "Hello World"
  });
});

app.listen(9999);

views/index.twig

Message of the moment: <b>{{ message }}</b>

An Express 2 Example is available on the wiki.

Tests

The twig.js tests are written in Mocha and can be invoked with make test.

License

Twig.js is available under a BSD 2-Clause License, see the LICENSE file for more information.

Acknowledgments

See the LICENSES.md file for copies of the referenced licenses.

  1. The JavaScript Array fills in src/twig.fills.js are from https://developer.mozilla.org/ and are available under the MIT License or are public domain.

  2. The Date.format function in src/twig.lib.js is from http://jpaq.org/ and used under a MIT license.

  3. The sprintf implementation in src/twig.lib.js used for the format filter is from http://www.diveintojavascript.com/projects/javascript-sprintf and used under a BSD 3-Clause License.

  4. The strip_tags implementation in src/twig.lib.js used for the striptags filter is from http://phpjs.org/functions/strip_tags and used under and MIT License.

twig.js's People

Contributors

justjohn avatar evgenius avatar iapain avatar stremglav avatar ajbdev avatar m-abs avatar jmealo avatar adamdicarlo avatar mauteri avatar egorshar avatar andresteenveld avatar eiriksm avatar mdance avatar khomyakov42 avatar thiefmaster avatar m1kc avatar m0ppers avatar buzzedword avatar ericclemmons avatar cangit avatar henrycatalinismith avatar webberig avatar mattkahl avatar nike-17 avatar superdweebie avatar tristanlins avatar

Stargazers

Jamie Hall avatar

Watchers

 avatar  avatar Adam Judd avatar  avatar  avatar James Cloos avatar Josh Bartolomucci avatar David Hollander avatar Jed Aureus Gonzales avatar Sami avatar kasey hinchman avatar Marija Robinson 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.