Giter VIP home page Giter VIP logo

dojang's Introduction

Dojang

Test and Coverage

Dojang is a Html template engine, as a drop in replacement for EJS. Though it does not supports 100% of the javascript syntax, it supports enough to cover the basic usages.

Features

  • Supports basic javascript. (if, for, while, etc.)
  • Supports script and output tags. (<%, <%-, <%=)
  • Supports calling external functions.

How to use?

use dojang::Dojang;
use serde_json::Value;

// Create a template engine Dojang.
let mut dojang = Dojang::new();

// Load template file under '/my/template/files'
assert!(dojang.load("/my/template/files").is_ok());

// Render a template. "some_template" is the one of the template file under /my/template/files. 
// Note that the context should be provided as a serde_json value.
assert_eq!(
    dojang
        .render(
            "some_template",
            serde_json::from_str(r#"{ "a" : 1 }"#).unwrap()
        )
        .unwrap(),
    " Hi "
    );

assert_eq!(
    dojang
        .render(
            "some_template",
            serde_json::from_str(r#"{ "a" : 2 }"#).unwrap()
        )
        .unwrap(),
    "2"
    );

Features coming soon.

  • Support for file includes (<%- .. >)
  • Optimization.

dojang's People

Contributors

kev0960 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

dojang's Issues

Something incorrect to my dojang implementation. After adding it, the app panicks!

Hello kev0960, I like that this repo exists, but my knowledge lacks and could not implement it correctly.
Here the code i added:

println!("1111111111111111");
  let mut dj = Dojang::new();
  println!("22222222222222222222");

  // Load files as template under /template/files/path.
  dj.load("src/emails").unwrap();
  println!("333333333333333");

  // dj.add("src/emails/order_email.ejs".to_string()).unwrap();
  dj.render("order_email.ejs", serde_json::json!({"data" : email_order})).unwrap();
  println!("4444444444444444444");

  let order_email_content = fs::read_to_string(&"src/emails/order_email.ejs")?;

This prints this:

1111111111111111
22222222222222222222
thread 'actix-rt|system:0|arbiter:0' panicked at 'Cannot add op to End; op ParenClose', /home/klala/.cargo/registry/src/github.com-1ecc6299db9ec823/dojang-0.1.6/src/expr.rs:86:18

The Error originates to dojang, but no idea why?
The Error is not clear.

Notes: After adding dojang this error is there, my suspicion is a have made a mistake on how to use dojang.
Another Question: How could i use the template as a string after using dojang, there is no documentation clear to this.
Thanks, i am newbie to Rust.

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.