Giter Club home page Giter Club logo

contemplate's Introduction

Contemplate

Further development on this project has stopped!!

Light-weight and flexible template engine for PHP, Python, Node and client-side JavaScript

Contemplate

This started as a a proof-of-concept , yet is fully working and extensible. The inspiration came from an old post by John Resig (http://ejohn.org/blog/javascript-micro-templating/)


Note After creating the repository i became aware of a web framework with similar name here: http://www.arlomedia.com/software/contemplate/assembled/introduction.html

This repository and project are completely unrelated to that framework.

There is an older and quite different template engine for node named also "contemplate" here and here

This repository and project are completely unrelated to this engine.

(it seems the word contemplate is nice for a template engine :) )


Contemplate

###Contents

###Rationale

There are many templating engines out there, which are elegant, fast, multipurpose (eg. smarty mustache twig handlebars jade doT and so on..)

Most of the sophisticated engines use a custom parser (and usually a full-fledged framework) to build the engine.

This is highly versatile:

  1. but can have performance issues sometimes

  2. and / or requires to learn a (completely) new syntax for building a template.

These drawbacks can be compensated if one uses PHP itself as templating engine. PHP already IS a templating language and a very fast at it.

This can create very simple, intuitive and fast templates.

The drawbacks of this approach are:

  1. It works only with PHP, and many times the same template needs to be used also by Javascript

  2. It can be cumbersome to combine or iterate over templates and parts.

Contemplate seeks to find the best balance between these requirements.

The solution is inspired by John Resig's post (see above) and the fact that PHP, Python and JavaScript share a common language subset.

###Features:

  • Contemplate does a minimum parsing (and caching) in order to create dynamic templates and trying to contain the needed functionality inside the common language subset.

  • Most of the time this can be accomplished, the rest functionality is built with custom functions which mostly resemble the PHP syntax, yet work the same in all the engine's implementations.

  • Engine Implementations for PHP , Python , Node and client-side JavaScript

  • Simple and light-weight ( only one (relatively small) class for each implementation, no other dependencies )

  • Fast , can cache templates dynamically (filesystem caching has 3 modes, NONE which uses only in-memory caching, NOUPDATE which caches the templates only once and AUTOUPDATE which re-creates the cached template if original template has changed, useful for debugging)

  • Generated cached template code is formatted and annotated with comments, for easy debugging

  • Syntax close to PHP (there was an effort to keep the engine syntax as close to PHP syntax as possible, to avoid learning another language syntax)

  • Easily extensible , configurable

  • Localization , Date formatting built-in and configurable easily ( simple Data escaping is also supported)

  • Date manipulation similar to PHP format (ie date function). An extended, localized version of php's date function ldate is also implemented in the framework

  • Loops can have optional elsefor() statement when no data, or data is empty (see tests)

  • Templates can include other templates (similar to PHP include directive), these includes wil be compiled into the the template that called them

  • Templates can call another template using template directive, these templates are called as templates subroutines and parsed by themselves

  • Template Inheritance , templates can extend/inherit other templates using extends directive and override blocks using block , endblock directives (see examples)

  • Notes: Literal double quotes should better be used inside templates (see the manual)

###Dependencies

  • Only 3 classes are used (Contemplate.php, Contemplate.js, Contemplate.py), no other dependencies
  • PHP 5.2+ supported
  • Node 0.8+ supported
  • Python 2.x or 3.x supported
  • all major browsers

###Todo

  • allow the engine to be extended by (custom) plugins
  • add Contemplate implementations for Perl, Java, Scala
  • keep-up with php, node, browsers, python updates

###Tests

Use test.php (for php), test.js (for node), test.py (for python) under tests folder, to test the basic functionality

###Screenshots

Sample Template markup Template markup

Data to be used for the template Template data

PHP and Javascript rendering of the template on same page (see test.php) Template output

URL Nikos Web Development
URL WorkingClassCode

contemplate's People

Watchers

James Cloos 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.