Code Monkey home page Code Monkey logo

regular's Introduction

![regularjs](http://regularjs.github.io/image/regular-icon-100.png)

After version 0.3.0: in Regularjs, the default TAG is changed from {{}} to the cleaner{}. However you can use Regular.config({BEGIN:'{{', END: '}}'}) if the old syntax is needed.

Regularjs

Build Status

Regularjs is a living template engine that helps us to create data-driven components.

Features

  • String-based templates make it flexible to build your component;
  • data-binding based on dirty-check: the Angular-like experience also makes sense to regularjs;
  • self-contained and well-defined encapsulation makes it more easily integrated with other frameworks;
  • composite components: components can be used as "custom elements";
  • directive, filter, event and animation... all you need is provided out of box with concise API.

Quirk Start

Example 1: define a simple Note Component

var Note = Regular.extend({
template: 
  "<input {#if !disabled} r-model='hello' {#else} disabled {/if} > {hello} \
<button on-click={disabled = !disabled}>{disabled? 'active': 'disable'} it</button>"
})

// inject component into #app , you can also inject at 'before' , 'after', 'top'.
var note = new Note().$inject("#app"); 

Example1 on codepen.io

the Example is dead simple, but you can find the directive and attribute is easily switched by statement 'if'. which is difficult with other mvvm frameworks.

Example 2: define a List Component

var NoteList = Regular.extend({
template: 
  "<ul>{#list notes as nt}" +
    "<li class={nt.done? 'done': ''} on-click={nt.done= !nt.done}>{{nt.content}}</li>" + 
  "{/list}</ul>"
});

var list = new NoteList({
  data: {notes: [{content: 'playgame'}, {content: 'homework'}]}
}).$inject("#app");

In this Example, we create a ListView by the statement list.

Example2 on codepen.io

Example 3: combine Note with NoteList

we need to refactor Note to make it composable.

var Note = Regular.extend({
  name: 'note',  // register component during the definition of Component
  template: 
   "<input r-model={draft}> <button  on-click={this.post()}> post</button>", 
  post: function(){
    var data = this.data;
    this.$emit('post', data.draft);
    data.draft = ""; //clear the draft
  }

});

Regular.component('list', NoteList);  // manual register a component

When 'Enter' is pressed, we emit a 'post' event with the draft as the $event object.

The keyword this in the template points to the component itself.

Then, define the core component: NoteApp.

var NoteApp = Regular.extend({
  template: 
    "<note on-post={notes.push({ content: $event} )}/>"+ 
    "<list notes ={notes}></list>"
})

var noteapp = new NoteApp({
    data: {notes:[] }
});

noteapp.$inject('#app');

you can register a component (via attribute name or method Component.component) to make it composable in other components.

Example3 on codepen.io

See more on Guide: Quirk Start

Resources

Browser Compatibility

IE7+ and other modern browsers.

installation

###bower

bower install regularjs

dist/regular.js has been packaged as a standard UMD, and therefore you can use it in AMD, commonjs and global.

npm (browserify or other based on commonjs)

npm install regularjs

use

var Regular = require('regularjs');

component

component install regularjs/regular

use

var Regular = require('regularjs/regular');

Direct download

  1. regular.js
  2. regular.min.js

Who are using?

  1. NetEase: the operator of the famous website www.163.com.

Community

Contribute

regularjs is still in heavily development, and please help us with feedback. Contributing to this project is also recommended.

  • Please open an issue before sending pull request,
  • if needed, add your testcase at test/specs folder. always make sure the gulp test is passed, and the test/runner/index.html is passed in every target browser (if a certain browser is not installed, list that in gulpfile's karmaConfig)

LICENSE

MIT.

regular's People

Contributors

infinnie avatar jabez128 avatar leeluolee avatar mekto avatar rainfore avatar

Watchers

 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.