Coder Social home page Coder Social logo

Comments (7)

sunng87 avatar sunng87 commented on June 14, 2024

This has been my concern for a while. I was thinking about decoupling the directory scan from HandlebarsEngine, making the HandlebarsEngine a simple wrapper of handlebars that just doing middleware things well.

And we will introduce a DirectorySource trait (or struct ) that allows you to add a directory of templates to HandlebarsEngine. Features like reload/watch will be available to DirectorySource only. Then DirectorySource manages to add/remove templates to HandlebarsEngine.

With this design, the DirectorySource will be optional to HandlebarsEngine and you will be free to register template string manually.

This will be a breaking change but during 0.x releases we can do it aggressively to archive better design, just like Rust did. WDYT?

from handlebars-iron.

untitaker avatar untitaker commented on June 14, 2024

Your plan sounds sensible. I guess that means that HandlebarsEngine::from will
only take a registry as input (unless new features are added)

On Sun, Nov 01, 2015 at 06:54:01PM -0800, Ning Sun wrote:

This has been my concern for a while. I was thinking about decoupling the directory scan from HandlebarsEngine, making the HandlebarsEngine a simple wrapper of handlebars that just doing middleware things well.

And we will introduce a DirectorySource trait (or struct ) that allows you to add a directory of templates to HandlebarsEngine. Features like reload/watch will be available to DirectorySource only. Then DirectorySource manages to add/remove templates to HandlebarsEngine.

With this design, the DirectorySource will be optional to HandlebarsEngine and you will be free to register template string manually.

This will be a breaking change but during 0.x releases we can do it aggressively to archive better design, just like Rust did. WDYT?


Reply to this email directly or view it on GitHub:
#18 (comment)

from handlebars-iron.

untitaker avatar untitaker commented on June 14, 2024

What about moving the whole directory-watching feature into handlebars-rust?

from handlebars-iron.

sunng87 avatar sunng87 commented on June 14, 2024

I prefer to keep handlebars-rust to do parse/render things monolithically. Adding directory scanning and watching makes it heavy.

from handlebars-iron.

sunng87 avatar sunng87 commented on June 14, 2024

I just need some time to implement the new design. Perhaps this weekend if I have time.

from handlebars-iron.

untitaker avatar untitaker commented on June 14, 2024

Off-topic: What do you think about this line:

And then the idea of loading/parsing/compiling templates at compile-time comes to mind, but I suspect that the necessary APIs aren't stable yet in Rust, and that it's too late for those kind of major feature requests.

In particular, I dream of a template engine where templates are parsed at compile-time, and are translated into Rust code. That almost certainly would bring speedups, but most importantly we wouldn't have to convert everything to JSON before passing it to a template, since it all boils down to Rust.

Example. This:

fn main() {
    let data = BTreeMap::new();
    data.insert("foo".to_owned(), 42);

    println!("{}", mytemplate(data));
}

handlebars!("mytemplate", "{{ foo }}");

compiles into:

fn main() {
    let data = BTreeMap::new();
    data.insert("foo".to_owned(), 42);

    println!("{}", mytemplate(data));
}

fn mytemplate(data: BTreeMap) -> ... {
    data.get("foo").unwrap()
}

maud has this idea implemented but the template language itself is far too simple for my purposes (handlebars fits well). Also I guess one would have to think about how to implement a template registry with this design.

from handlebars-iron.

sunng87 avatar sunng87 commented on June 14, 2024

I haven't look into rust's macro system. If it's like lisp languages that has same capabilities at compile-time, it's fully possible to move template parsing to compile-time. Currently a template is consisted with a vector of TemplateElement in memory, it's possible to inline these elements at compile-time.

However, rendering handlebars template involves some dynamics such as template lookup, we may still have to do it at runtime.

from handlebars-iron.

Related Issues (20)

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.