GithubHelp home page GithubHelp logo

rgbui / rjs Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 43 KB

Graceful js template engine. Like c# razor.You'll love it.

TypeScript 99.92% JavaScript 0.08%
razor-js js-template-render js-template-engine razor js js-template

rjs's Introduction

RJS

Graceful JavaScript templates.
Do you feel comfortable? Like this

@if(user){
    <h2>@user.name</h2>
}

is it more graceful than ejs?
I just don't like ejs, that's why I designed rjs
I think you'll like it.

Installation

browser

<script src="dist/rjs.js"></script>

nodeJS

 $ npm install rarzor-js-template

Usage

browser

var html = rjs.compile(`<ul>
    @for(var i=0;i<users.length;i++>)
    {
        <li><span>@users[i].name</span></li>
    } 
</ul>`,{ 
   users:[{name:"Donald John Trump"},{name:"Obama"},{name:"George Walker Bush"}]
});

nodejs

var RJS=require('rarzor-js-template');
var rjs=new RJS({
    include(filePath,data)=>{
        var template=require("fs").readFileSync(path.join(__dirname,filePath+".rjs"),"utf8");
        return RJS.compile(template,data);
    }
});
var html=rjs.compile(`<ul>
     @for(var i=0;i<users.length;i++>)
     {
         @{var user=users[i];}
         @include("user/show",user)
     }
</ul>`,
{users:[
    {name:"Donald John Trump",email:"[email protected]"},
    {name:"Obama",email:"[email protected]"}
    ]
});

You can define @include() statement
define @html() for HTML escape
You can do more
It's very easy

It doesn't just support HTML, it supports product code

rjs.compile(`
if(confrim("@message")){
   alert("@yes");
}
else{
   alert("@no");
}
`,{
     message:"Do you confirm to cancel this submission?",
     yes:"Cancel the submission",
     no:"Submit"
})

You need to make sure that () and {} are paired, otherwise you'll get an error

Features

  • @for(){}
  • @while(){}
  • @if(){ }else if(){ } else{ }
  • @{} statement
  • @() express
  • escape character ["@@","@)","@}","@#{","@#("]

    () and {} are normally paired, and the escape character is mainly used to match half

  • @**@ annotation

License

MIT License

rjs's People

Contributors

rgbui avatar

Stargazers

 avatar  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.