Code Monkey home page Code Monkey logo

node-jadeite's Introduction

jadeite

Jadeite is a Jade-like template language, and it's actually valid JavaScript.

Feedbacks are welcome!

Features

  • Variable substitution
  • Compiled template (fast!)
  • Conditionals

Why?

  • Because it's fun!

Install

Unstable, use at your own risk

This package uses the (old) Proxy API, so you need v0.11 node (and --harmony flags) or a harmony enabled browser..

With npm do

$ npm install jadeite

Usage

Write your template function:

function myTemplate(magic) {
  with(magic) { // `with` is needed if you want to omit property access
    return html
      (head
        (title
          ('Welcome on my Awesome site!')
        )
        (script(type = 'text/javascript', src = '/bundle.js') //very named arguments :o
        )
      )
      (body
        (h1
          (a(href = link) // wow, so dynamic attributes!
            (linkText) // such dynamic content
          )
          (input()) // empty tag, function call needed, or it will be substituted with the `input` variable
          (iff(cond)
            ('true!')
          )
        )
      );
  }
}

Compile it, and it's ready to use:

var jadeite = require('jadeite');
var template = jadeite(myTemplate);

console.log(template({
  link: '/home',
  linkText: 'Hello world!'
}));
// <html><head><title>Welcome on my Awesome site!</title><script type="text/javascript" src="/bundle.js" /></head><body><h1><a href="/home">Hello world!</a><input /></h1></body></html>

API

jadeite(fn)

fn is a template function that accepts one parameter, like in the example. It return the compiled template, the example (myTemplate) will compile to this:

function(data) {
  var a = [];
  a.push('<html><head><title>Welcome on my Awesome site!</title><script type="text/javascript" src="/bundle.js" /></head><body><h1><a href="');
  a.push(data.link);
  a.push('">');
  a.push(data.linkText);
  a.push('</a><input />');
  if(data.cond) {
    a.push('true!');
  }
  a.push('</h1></body></html>');
  return a.join('');
}

Plans

  • Loops: each(item in items)(li(item))
  • jadeite < input.js command
  • Less parens :)))
  • Unicorns

License

MIT

node-jadeite's People

Contributors

madbence avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

node-jadeite's Issues

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.