Comments (7)
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.
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 theHandlebarsEngine
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 toHandlebarsEngine
. Features like reload/watch will be available toDirectorySource
only. ThenDirectorySource
manages to add/remove templates toHandlebarsEngine
.With this design, the
DirectorySource
will be optional toHandlebarsEngine
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.
What about moving the whole directory-watching feature into handlebars-rust?
from handlebars-iron.
I prefer to keep handlebars-rust to do parse/render things monolithically. Adding directory scanning and watching makes it heavy.
from handlebars-iron.
I just need some time to implement the new design. Perhaps this weekend if I have time.
from handlebars-iron.
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.
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)
- update serde to 0.7 HOT 4
- 0.14 release HOT 1
- DirectorySource not loading templates in a heirarchy HOT 2
- Handle templates set on IronErrors HOT 4
- Handlebars and Mount and StaticFile HOT 14
- Link to documentation not working HOT 1
- Compilation error with `serde_type` HOT 5
- [Suggestion] Implementing Handler for Templates HOT 10
- Template is not rendered in AfterMiddleware HOT 2
- Ability to access request extensions in Helpers HOT 2
- no method named `register_helper` found HOT 3
- Improve Template errors reporting HOT 2
- Is there way to use DirectorySource as MemorySource? HOT 3
- Add the ability to gzip content before Responding HOT 12
- Porting to serde 1.0 HOT 5
- DirectorySource does not use correct path types HOT 1
- Documentation link seems broken HOT 1
- Calling a function from a template HOT 4
- Examples are outdated HOT 2
- Update to handlebars 1.0 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from handlebars-iron.