Giter VIP home page Giter VIP logo

weft's Introduction

Weft: composable HTML templating

CircleCI

Why another templating language?

Weft is inspired by the Genshi templating language. And in the grand tradition of awful naming puns in open source, since Genshi means Thread, we're calling this Weft, after the base thread used in weaving.

We have a few other main goals, too.

Composable templates

It should be as easy to compose fragments of template as you do data structures in Rust. For example, many languages use Jinja 2 style template inheritance, however this doesn't really feel all that parsimonious with the way rust manages composition, and and usually means that the only way to verify something using one of these templates is via rendering the entire page.

HTML templating often involves a lot of ad-hoc composition of different languages in different context, such as HTML markup itself, URL parameters, scripts, &c. A lot of engines rely on knowing what escaping to apply in which context in order to avoid content injection attacks. Whilst we can't solve all of these problems at once, we at least aim to ensure that the output markup is correctly formed as much as we can from end to end.

Attribute based

Many markup langauges involve adding an ad-hoc layer of markup on top of a markup language in order to control what and how content gets rendered. XSLT largely manages to avoid this problem by defining the content transformation in terms of the base markup language itself (XML), but but suffers from being far more general than we need for a template language, and thus can be very verbose.

The idea of using attributes to control how markup is rendered comes from Zope's Template Attribute Language (via Genshi). This seems to work well since it's very unobtrusive, and means that templates render naturally when viewed in a browser.

The post In search of a Pythonic, XML-based Templating Language also explains a lot of these ideas very well.

weft's People

Contributors

cstorey avatar dependabot-preview[bot] avatar dependabot[bot] avatar

Stargazers

Mike avatar Jesse Powell avatar  avatar  avatar krircc avatar

Watchers

 avatar James Cloos avatar krircc avatar  avatar

Forkers

krircc

weft's Issues

weft_derive needs updating on crates.io?

Project is really cool! I'm glad I'm not the only one who thinks we can template HTML with attributes.

I was trying to use this with a new project using the 2021 edition, but I'm running into build problems.

Rust version:

stable-x86_64-unknown-linux-gnu unchanged - rustc 1.73.0 (cc66ad468 2023-10-03)

Cargo.toml:

[package]
name = "weft_problem"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
weft = "0.1.0"
weft_derive = "0.1.1"

main.rs:

use weft_derive::WeftRenderable;

#[derive(WeftRenderable)]
#[template(path = "src/interpolatable.html")]
struct Interpolatable<'a> {
    name: &'a str,
}

fn main() {
    println!("Hello, world!");
}

Output:

[mike@mike-um350 weft_problem]$ cargo build
   Compiling weft_problem v0.1.0 (/home/mike/Projects/weft/weft_problem)
error[E0432]: unresolved import `weft`
 --> src/main.rs:3:10
  |
3 | #[derive(WeftRenderable)]
  |          ^^^^^^^^^^^^^^ could not find `prelude` in `weft`
  |
  = note: this error originates in the derive macro `WeftRenderable` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0432`.
error: could not compile `weft_problem` (bin "weft_problem") due to previous error

Upon inspecting the source in lib.rs in this repo and comparing it to that corresponding file on my machine, it looks like mine is an older version. If I download this repo and run each thing, the build works successfully.

Anyways, I think this is a cool project so I'd hate to think its getting skipped over because of a minor update hiccup.

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.