Giter Site home page Giter Site logo

jquery-blueprint's Introduction

JQuery Blueprint is an ultra-lightweight, simple, javascript templating framework.

Usage
-----------

The HTML:
<ul id='my_list'></ul>

<div class="blueprint" templateid="list_link">
 <li>
   <a href='@#url#@'>@#link_text#@</a>
 </li>
</div>

First we have a ul (#my_list), into which we want to put our template, the template is wrapped in a div, the class we'll use as a jquery selector, and the templateid is how we'll refer to this template when we want to render it. Variables start with @# and end with #@, so to make a variable called color we would write @#color#@. 

The javascript:

var urls = [
  { url : 'http://www.yahoo.com',   link_text : 'Yahoo' },
  { url : 'http://www.google.com',  link_text : 'Google' },
  { url : 'http://www.bing.com',    link_text : 'Bing' }
];

$(function() {
  $('.blueprint').blueprint();
  
  for (url in urls) {
    $('#my_list').blueprint('render','list_link',urls[url]);
  }
});

First we define our data, in this case just a list of search engines. Then in the jquery ready, we create our blueprints by calling blueprint on any element with the class 'blueprint' then for each url in the list, we render the template called 'list_link' into our ul (#my_list), with the data from our urls.

REVISION HISTORY
----------------
Version 0.3: Added the ability to use compound variables. For example, if you had an object such as: data = { authors: {first_name: 'Ted', last_name: 'Jones'} }; and you wanted to get to the authors names in a template you would write your template with the variable names: @#author.first_name#@ and @#author.last_name#@. When render is passed that data object the template will be rendered with Ted Jones.

Version 0.2: Retooled template parsing engine, rather than using regex when rendering, it now uses a state machine to parse the template upfront, resulting in a 27% decrease in rendering time. (98ms avg for 1000 calls, versus 71ms).

Version 0.1: Initial Release

jquery-blueprint's People

Watchers

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