Giter Club home page Giter Club logo

starplate's Introduction

Starplate

Starplate is a lightning fast template and view engine built on top of incremental-dom and Babel. Think ES6 Templates + Incremental DOM working together. DOM travseral is made possible with parse5.

Status

This is still new and lacks heavy testing. As this project matures its documentation and test will as well.

Installation

Install starplate with NPM:

$ npm install starplate --save

Usage

Starplate is written in ES6 and intended for use in browser environments. If you intend to use it with build systems like duo then consider using a plugin like duo-babel. You can grab the latest standalone build from the dist/ directory.

Examples

Template

The most basic example is the usage of the Template class. A Template instance represents a partial that may interpolate with data.

import { Template } from 'starplate'
const template = new Template('Hello ${name}')
const output = template.render({name: 'kinkajou'})
console.log(output) // Hello kinkajou

View

Consider the following subclass of the View. We define a clock that has an update() method that renders a new time. We call the .update() method every second.

import { Template, View } from 'starplate'

function getTime (date = new Date()) {
  const h = date.getHours(), m = date.getMinutes(), s = date.getSeconds()
  return `${h}:${m}:${s}`
}

class Clock extends View {
  constructor () {
    super(new Template(
      '<section>Time <span class="time">#{time}</span></section>'
    ), {time: getTime()})
  }

  update (date = new Date()) {
    return super.update({time: getTime(date)})
  }
}

const clock = new Clock()
clock.render(document.body)
setInterval(_ => clock.update(), 1000)

License

MIT

starplate's People

Contributors

jwerle avatar markdalgleish avatar

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.