Yarte stands for Yet Another Rust Template Engine

Overview

Should we start to worry?

bytes-buf feature can produce SIGILL.

avx and sse flags are in almost all cpus of x86 and x86_64 architectures.

More details in https://github.com/botika/v_escape/issues/54.

Satan has been slaughtered and sent to heaven. Should we start to worry?

Disclaimer

All structures and functions in this crate -- even those based on the real crates -- are entirely fictional. All celebrity codes are impersonated...poorly. The following program contains coarse language and due to its content it should not be used by anyone.

Yet Another Rust Template Engine

Yarte Latest version Build Status

Yarte stands for Yet Another Rust Template Engine. Uses a Handlebars-like syntax, well-known and intuitive for most developers. Yarte is an optimized, and easy-to-use rust crate, with which developers can create logic around their HTML templates using conditionals, loops, rust code and template composition.

Features

  • Almost all Rust expressions are valid
  • Meta programming system with almost all Rust expressions, conditionals, loops, modules and partial recursion
  • Low level, SIMD and zero copy runtime
  • A fancy-text debug mode to visualize the code generated by Yarte
  • Emit snipped annotations at error
  • Improved daily and has full coverage (without stupid bugs that take months or years to fix)

Is it really fast?

See it for yourself in the TechEmpower benchmarks with actix and ntex

Documentation

In order to fully understand Yarte's capabilities take a look at the following documentation:

Acknowledgment

Yarte is based on all previous templates engines, syntax as well as its documentation is highly influenced by Handlebars. Logo adapted from Creative Commons images

Contributing

Please, contribute to Yarte! The more the better! Feel free to open an issue and/or contacting directly with the owner for any request or suggestion.

I want to move these yarte, v_escape, v_eval and buf-min to a team with me as a member. If someone wants to participate in this team, open an issue

Code of conduct

This Code of Conduct is adapted from the Contributor Covenant, version 1.4, available at http://contributor-covenant.org/version/1/4

License

This project is distributed under the terms of both the Apache License (Version 2.0) and the MIT license, specified in LICENSE-APACHE and LICENSE-MIT respectively.

Comments
  • My English is terrible and the documentation I wrote must have many typo errors

    My English is terrible and the documentation I wrote must have many typo errors

    When I wrote the documentation I did most of it with the translator so it must have a lot of errors. The book should be revised and rewritten correctly.

    documentation help wanted good first issue 
    opened by botika 11
  • yarte and actix - example

    yarte and actix - example

    Hi, could you give any example how to use with actix. This code:

    use actix_web::{web, App, HttpResponse, HttpServer, Responder};
    use yarte::*;
    
    #[derive(Template)]
    #[template(path = "hello.hbs")]
    struct SimpleName<'a> {
        name: &'a str
    }
    
    
    
    async fn manual_hello() -> impl Responder {
        SimpleName {name:"Greogor"}
        .call()
        // HttpResponse::Ok().body("Hey there!")
    }
    
    #[actix_web::main]
    async fn main() -> std::io::Result<()> {
        HttpServer::new(|| {
            App::new()
                .route("/", web::get().to(manual_hello))
        })
        .bind(("127.0.0.1", 8080))?
        .run()
        .await
    }
    

    gives error:

    error[E0277]: the trait bound `yarte::Error: ResponseError` is not satisfied
      --> src/main.rs:12:28
       |
    12 | async fn manual_hello() -> impl Responder {
       |                            ^^^^^^^^^^^^^^ the trait `ResponseError` is not implemented for `yarte::Error`
       |
       = note: required because of the requirements on the impl of `std::convert::From<yarte::Error>` for `actix_web::Error`
       = note: required because of the requirements on the impl of `Into<actix_web::Error>` for `yarte::Error`
       = note: required because of the requirements on the impl of `Responder` for `Result<String, yarte::Error>`
    
    For more information about this error, try `rustc --explain E0277`.
    warning: `actix_yarte` (bin "actix_yarte") generated 1 warning
    error: could not compile `actix_yarte` due to previous error; 1 warning emitted
    
    opened by nicraMarcin 7
  • Warning: unused borrow must be used

    Warning: unused borrow must be used

    As of recently, each time I compile my CLI app that uses Yarte i get a bunch of these:

    warning: unused borrow that must be used
     --> src/report/generate_html.rs:5:10
      |
    5 | #[derive(Template)]
      |          ^^^^^^^^ the borrow produces a value
      |
      = note: this warning originates in the derive macro `Template` (in Nightly builds, run with -Z macro-backtrace for more info)
    

    Looking into it with cargo expand I see generated code like this:

    &(self.surface_type).__renders_it(_fmt)?;
    

    Which, as far as I understand, calls __renders_it(), and grabs the reference of the returned Result instead of grabbing the reference of self.surface_type, hence the warnings.

    opened by nsabovic 6
  • Runtime-provided templates

    Runtime-provided templates

    I currently have a use-case where users should be able to provide the template and I just fill it in during runtime and generate the resulting text. Is this possible with yarte? All examples show that you have to specify the path to the template, but in my case this is not possible.

    opened by mainrs 6
  • Inconsistent name transformation of pattern matched variables eg: `if let Err(...) = ...`

    Inconsistent name transformation of pattern matched variables eg: `if let Err(...) = ...`

    Hello,

    I can work around this issue, but a fix may improve UX for new users.

    When attempting to pattern match a Result<>, the compiler complains about the declared variable not existing.

    error[E0425]: cannot find value `e` in this scope
       --> src/bin/x.rs:y:z
        |
    123 |         .body(auto!(ywrite_min!(String, "{{> pages/query }}"))))
        |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        |               |
        |               not found in this scope
        |               in this macro invocation
        | 
       ::: /home/xyz/.cargo/registry/src/github.com-1ecc6299db9ec823/yarte_derive-0.15.4/src/lib.rs:464:1
        |
    464 | pub fn ywrite_min(i: TokenStream) -> TokenStream {
        | ------------------------------------------------ in this expansion of procedural macro `ywrite_min!`
    
    

    Eg:

    --------------v
    {{#if let Err(e) = feedback }}
        <div class="error-message">{{ format!("{}", e) }}</div>
    {{/if}}
    ------------------------------------------------^
    

    When looking at the output using cargo-expand (cargo install cargo-expand && cargo expand), the declaration has a suffix but the use does not : image

    Putting the generated suffix in the source template does fix the error.

    System versions:

    yarte 0.15.4
    rustc 1.53.0 (53cb7b09b 2021-06-17)
    binary: rustc
    commit-hash: 53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b
    commit-date: 2021-06-17
    host: x86_64-unknown-linux-gnu
    release: 1.53.0
    LLVM version: 12.0.1
    

    Best,

    opened by gxtaillon 5
  • Possible partial parser bug

    Possible partial parser bug

    Hello,

    I can work around this issue but it would be very convenient to be able to declare styles to put the <head> in the same hbs file where they are used.

    I'm getting a macro panick when the character '}' is present in a partial's attribute value[0]:

    error: proc macro panicked
       --> src/bin/x.rs:y:z
        |
    127 |         .body(auto!(ywrite_min!(String, "{{> pages/query }}"))))
        |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        |
        = help: message: called `Option::unwrap()` on a `None` value
        = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
    

    Eg:

    {{#> root/base style = "form textarea { box-sizing: border-box; width: 100%; max-width:1024px; }" }}
    -----------------------------------------------------------------------------------------------^
    

    Also fails with

    }}
    }}}
    \}
    \\}
    

    System versions:

    yarte 0.15.4
    rustc 1.53.0 (53cb7b09b 2021-06-17)
    binary: rustc
    commit-hash: 53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b
    commit-date: 2021-06-17
    host: x86_64-unknown-linux-gnu
    release: 1.53.0
    LLVM version: 12.0.1
    

    Best,

    [0] https://yarte.netlify.app/templating/partial.html

    opened by gxtaillon 5
  • Email templates

    Email templates

    Hi, it's possible to get random render with yarte?.

    I mean, i have a template with HTML and inline styles into it (it's for the email body), when I send the email on my development (debug) there is not problem with the email body (all is as expect it), when I build to production (release), sometimes the email body is printing some HTML code as text (not all code but some pieces), or sometimes, (with a new build) loses the inline styles with all body text as expect it (without some HTML code as text)

    opened by shiftrtech 4
  • Code print can alloc too big

    Code print can alloc too big

    When compile example with code logger activated, returns:

    not memory allocation of 8391155392347897856 bytes failed
    

    Some components of logger have a bug. Not use in 0.11.0 and previous and rustc 1.46.0-nightly (6bb3dbfc6 2020-06-22) previous. In nightly works well.

    bug help wanted 
    opened by botika 4
  • Fix #233.

    Fix #233.

    This fixes #233 for my project. Disclaimers:

    1. There may be other places where similarly wrong codegen is used but I wouldn't know how to go about searching for them.
    2. I know absolutely nothing about how Yarte works and I have written maybe two macros in my life so this PR needs adult supervision.
    opened by nsabovic 3
  • Add Render support for uuid::Uuid (alloc::string::ToString)

    Add Render support for uuid::Uuid (alloc::string::ToString)

    Hey! Thank you for maintaining and building this awesome templating library. I've recently started migrating to it from askama and really enjoyed the thorough documentation and the clean and concise reference.

    But the project I'm working on relies on the popular uuid crate for user IDs (specifically uuid::Uuid). Though I haven't been able to find a way to either implement yarte::Render for Uuid since both are external items. My current mitigation involves a variant of my data that has std::string::String instead. This is possible due to the implementation of alloc::string::ToString for uuid::Uuid.

    My request is then to either get support the uuid crate (as a feature) or ideally a blanket implementation of Render for all structs that implement alloc::string::ToString. A blanket implementation would not only solve my problem, but also possible resolve the problem for other crates that provide custom data types that support the widely used alloc::string::ToString.

    I'm sorry if I wrote too much. Just noticed how long this has got.

    opened by Chaostheorie 3
  • Update v_jsonescape requirement from ~0.5.1 to ~0.6.1

    Update v_jsonescape requirement from ~0.5.1 to ~0.6.1

    Updates the requirements on v_jsonescape to permit the latest version.

    Commits

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies 
    opened by dependabot[bot] 2
  • Remove syn in favor of own rust parser

    Remove syn in favor of own rust parser

    There are problems with syn spans, I don't need to parse all of rust and I want to be able to get it in or out of a wasm module gracefully.

    Assigned @tizgafa

    bug 1.0.0 
    opened by botika 0
  • Dependency Dashboard

    Dependency Dashboard

    This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

    This repository currently has no open or pending branches.

    Detected dependencies

    cargo
    benches/Cargo.toml
    • v_htmlescape 0.15
    • criterion 0.4
    yarte/Cargo.toml
    • buf-min 0.7
    • trybuild 1.0
    • serde_json 1.0
    • serde 1.0
    yarte_codegen/Cargo.toml
    • proc-macro2 1.0
    • quote 1.0
    • syn 1.0
    • heck 0.4.0
    • mime_guess 2.0
    • indexmap 1.9
    yarte_derive/Cargo.toml
    • v_jsonescape 0.7
    • proc-macro2 1.0
    • quote 1.0
    • syn 1.0
    yarte_dom/Cargo.toml
    • markup5ever 0.11
    • quote 1.0
    • syn 1.0
    yarte_helpers/Cargo.toml
    • v_htmlescape 0.15
    • v_jsonescape 0.7
    • itoa 1.0
    • dtoa 1.0
    • ryu 1.0
    • chrono 0.4
    • prettyplease 0.1
    • syn 1.0
    • serde 1.0
    • toml 0.5
    • serde_json 1.0
    • buf-min 0.7
    • uuid 1.2
    • serde_json 1.0
    • random-fast-rng 0.1
    yarte_hir/Cargo.toml
    • v_eval 0.6
    • v_htmlescape 0.15
    • proc-macro2 1.0
    • quote 1.0
    • syn 1.0
    • derive_more 0.99
    • serde ~1.0.152
    yarte_html/Cargo.toml
    • mac 0.1
    • log 0.4
    • markup5ever 0.11
    • quote 1.0
    • syn 1.0
    • proc-macro2 1.0
    yarte_lexer/Cargo.toml
    • quote 1.0
    • syn 1.0
    • proc-macro2 1.0
    • annotate-snippets 0.9
    • derive_more 0.99
    • memchr 2.5
    • serde 1.0
    • ron 0.8
    • glob 0.3
    yarte_parser/Cargo.toml
    • quote 1.0
    • syn 1.0
    • proc-macro2 1.0
    • annotate-snippets 0.9
    • derive_more 0.99
    • unicode-xid 0.2
    • serde 1.0
    • ron 0.8
    • glob 0.3
    yarte_strnom/Cargo.toml
    • quote 1.0
    • syn 1.0
    • proc-macro2 1.0
    • annotate-snippets 0.9
    • derive_more 0.99
    • memchr 2.5
    • parking_lot 0.12
    • serde 1.0
    • ron 0.8
    • glob 0.3
    github-actions
    .github/workflows/bench.yml
    • actions-rs/toolchain v1
    • actions-rs/cargo v1
    • actions/cache v3
    • actions/cache v3
    .github/workflows/checks.yml
    • actions/checkout v3
    • actions-rs/toolchain v1
    • actions-rs/clippy-check v1
    • actions/checkout v3
    • actions-rs/toolchain v1
    • actions-rs/cargo v1
    .github/workflows/linux.yml
    • actions-rs/toolchain v1
    • actions-rs/cargo v1
    • actions/cache v3
    • actions/cache v3
    • actions-rs/cargo v1
    .github/workflows/osx.yml
    • actions-rs/toolchain v1
    • actions-rs/cargo v1
    • actions/cache v3
    • actions/cache v3
    • actions-rs/cargo v1

    • [ ] Check this box to trigger a request for Renovate to run again on this repository
    opened by renovate[bot] 0
  • "Port" Elm lang

    For intercompatibility and packaging, the best solution is to implement my own programming language and Elm lang seems to me a great starting point that also fits the messaging design.

    Draft.

    1.0.0 
    opened by botika 0
  • External dev/build tools

    External dev/build tools

    The idea is to separate the compilation of templates and rustc. For this purpose I want to use a tool based on typescript and wasm that offers easy compatibility with existing tools (webpack, postcss, ...). From here generate the rust code with this tool to include it later in the application. With this tool I could think of extending the language, such as vuejs or others. And other features, static sites, integration with tailwindcss or similar, optimizations, etc.

    opened by botika 0
Owner
Juan Aguilar
Free Pablo Hásel https://www.youtube.com/channel/UCwjnx_LtwvRZQnhqaOc-Ggg
Juan Aguilar
A flexible template engine for Rust

Rustache Rustache is a Rust implementation of the Mustache spec. Documentation The different Mustache tags are documented at the mustache(5) man page.

rustache 208 May 10, 2022
MiniJinja is a powerful but minimal dependency template engine for Rust

MiniJinja: a powerful template engine for Rust with minimal dependencies MiniJinja is a powerful but minimal dependency template engine for Rust which

Armin Ronacher 686 Jan 5, 2023
finch - a super fast and efficient template rendering engine for node.js

finch A super fast and efficient template rendering engine for node.js, inspired by Handlebars. Usage Finch is very simple to use: Register a template

null 1 Nov 2, 2021
Balsa is a delightfully simple HTML template engine

?? balsa Balsa is a delightfully simple HTML template engine. It is designed to be used in user interfaces such as a CMS where a user needs to be able

Tyler Lafayette 1 Jan 19, 2022
A minimalist Rust WebAssembly project template

MiniWASM - A minimalist Rust WebAssembly project template This is a minimal Rust-powered WebAssembly application template. It was designed to showcase

Emil Loer 160 Jul 26, 2022
A template for a Rust-powered static-page Try Online interface

rust-tio-template A template for a Rust-powered static-page Try Online interface What is included This is an example setup that enables all of the fol

null 2 Dec 13, 2021
A "Hello, world!" template of a Rust binary crate for the ESP-IDF framework.

Rust on ESP-IDF "Hello, World" template A "Hello, world!" template of a Rust binary crate for the ESP-IDF framework. This is the crate you get when ru

Ivan Markov 140 Jan 4, 2023
A template for creating services in Rust using Axum and Prisma.

A template for creating services in Rust using Axum and Prisma. This uses the super cool Prisma Rust Client.

Aaron Leopold 6 Oct 19, 2022
✨ A perfect template for a binary rust project.

Rust Template A project template for Rust, helping to structure your projects blazingly fast ⚡ . Features ?? Code-ready for binary projects. Add amazi

bwtecode 3 Aug 21, 2022
Compiler for Jade-like template language to cito.js-based virtual dom

Marafet A very experimental DSL for creating (mostly) single page applications in HTML. It's mostly a Jade-like (or Haml-like) templating language wit

Paul Colomiets 11 Jun 25, 2020
A nice template for NEAR repos

Template for a NEAR project If you're looking for a no-std version of this template, go here. Contains: a setup script Cargo.toml setup with simulatio

Thor 12 Dec 28, 2021
Yew Tauri Desktop App Template

Yew Tauri Desktop App Template This is Template App for Desktop App. Run Develop $ cargo tauri dev Build App $ cargo tauri build Setup yew setup Using

usa 16 Oct 16, 2022
Template for Cargo based SysY compiler projects.

基于 Cargo 的 SysY 编译器项目模板 该仓库中存放了一个基于 Cargo 的 SysY 编译器项目的模板, 你可以在该模板的基础上进行进一步的开发. 该仓库中的 Rust 代码实现仅作为演示, 不代表你的编译器必须以此方式实现. 如你需要使用该模板, 建议你删掉所有 Rust 源文件, 仅

PKU Compiler Course 1 Nov 1, 2021
Bevy GitHub CI Template

Bevy GitHub CI Template This repo show how to setup CI on a github project for Bevy. It creates two workflows: CI Release CI Definition: .github/workf

MiniaczQ 2 Feb 7, 2022
This is a template repo for eframe, a framework for writing apps using egui.

eframe template This is a template repo for eframe, a framework for writing apps using egui. The goal is for this to be the simplest way to get starte

Viet Dinh 0 Feb 5, 2022
Rust templating with Handlebars

handlebars-rust Handlebars templating language implemented in Rust and for Rust. Handlebars-rust is the template engine that renders the official Rust

Ning Sun 922 Dec 27, 2022
:pencil: Compile-time HTML templates for Rust

maud Documentation (source) • API reference • Change log Maud is an HTML template engine for Rust. It's implemented as a macro, html!, which compiles

Chris Wong 1.4k Jan 1, 2023
A macro-based html builder for rust

Horrorshow A macro-based html templating library, compatible with stable rust (currently requires rust >= 1.37). Features This crate will degrade grac

Steven Allen 267 Dec 11, 2022
Rust Compiled Templates with static-file handling

Rust Compiled Templates — ructe This is my attempt at writing a HTML template system for Rust. Some inspiration comes from the scala template system u

Rasmus Kaj 337 Jan 8, 2023