-
Notifications
You must be signed in to change notification settings - Fork 284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added string-include #482
added string-include #482
Conversation
added a few functions to templ/diet.d and a hook to it in server.d you can now import a stringTemplate as ALIAS Multiple String-imports per file are now supported. this however involved adding a template form bearophile I think this is now mergeable...
this is the same as #480 |
Okay so to recap, this currently works like this:
It's a nice idea that I didn't think of. However, I'm a little worried that the On that topic I found the idea of @etcimon interesting (if I understood it right) to use a named
A template could then do:
However, it feels a little strange, as this would basically require building a separate type for each Diet template instantiation. I've also never seen something like this used and I'm always a little careful with such neat tricks, because they can quickly make a library totally impossible to decipher if overused. I don't like all the talk about iterating over files in
This has the nice side effect of reducing the computation time and memory usage during CTFE (both grow faster than linear with the size of a Diet template file). So to make this happen, two main changes would be necessary:
I didn't have much time to think this though, so there may be something that I've overlooked, but so far this looks like a promising approach. And BTW, even the named Granted, the |
The compileDietString forces the diet templates to be available during the compilation of the library. Though I was hoping for a lazy import where numerous other projects can add their diet templates inside another, which could have been possible through a views folder scan, but I guess it'll have to be done by using a string delegate-callback event handling array in diet templates or some other workaround. |
Since you can pass things from the application down to the library as template parameters, there is nothing that speaks against inserting application templates into library code. A lot of possible interfaces could be bolted on this approach, you |
I find include #{} is intuitve after all who would wan't to include 3*3 ? |
If the routes are setup by the end application I can't argue about that, but if the library handles it's own router registration, making that information available during registration of the request handlers is a little more complicated than, say, setting up a delegate array. |
@etcimon |
UplinkCoder:
Note etcimon:
Then the library should simply offer a template parameter to pass the required information down to the Diet templates somehow. |
we could of course convert every past variable to an enum ... |
or constrain these values to be string enums I mean noone can expect magic from an include statement ... |
The way I'm currently writing the CMS / Framework, the request handlers in the libraries can't be templated because they're added to a hash map all the way up in the compilation chain, where they can be enabled or disabled through runtime configurations. It's fine if there's no integrated workaround, I'm a little stuck with my own problems on this one heh ;) |
Is this directed at me? If so, my proposal actually supports your proposed syntax, just that it also supports arbitrary expressions and thus opens up a number of additional possibilities. |
every expression past in has to evalute to a valid diet-template sooner or later. |
Can't the templates be instantiated and the resulting handlers then be inserted into the map? |
I'm satisfied with the implementation
I'll put the little hamster in the wheel and come up with an answer to that. I must've tried thinking about that subject alone for 60 hours but it's still not so obvious yet. I've only been reasoning around templates for like 6 months, so my brain spends most of its time "loading..." before I can visualize. =/ |
etcimon, please explain to me exactly what you are trying to do. |
Just as a side-note, before I found vibe.d, I was going to use QxOrm with Qt and startup a webserver on there, or cpp-netlib with boost spirit and SOCI, and 10 other libs. The Qt signals system strictly prevented classes that use signals to use templates, and I was out of my mind trying to make a list of headers that doesn't lose ordering so I needed boost multi index and for that I needed to modify cpp-netlib entirely. But either way I had 30mb of executables with 15 dll, 5mb just for UTF-8 support. What a fucking trainwreck. I'm glad the same is possible here in under 2 mb Anyways, I think I just need to be able to have a |
I don't like workarounds |
@s-ludwig should I start documenting the string-include ? |
I wouldn't deem callback capability like a workaround. I think templating it through chains of libraries could be too complicated, I'd love if we could just add a |
@etcimon well |
just like any other value used in a diet template |
Let's still wait with it until this is all finished.
You hear that very seldom from a developer, most developers just always say they hate writing docs ;) (I'd actually love to finish some parts of the documentation, but there always seem to be more important tasks). How about starting to write something for the include section in the Diet docs (albeit leaving out the |
That's the thing, once the diet template is rendered there's currently no way I can push in some diet templates compiled in adjacent libraries. A delegate array where you can push pointers to compiled templates or such, would be perfect for that, I'd sure love to know if we intend on doing this :) |
@etcimon: Wouldn't you typically need some way to pass arguments to the application defined template includes? If that's the case, you'll need some kind of templated interface anyway. The only other alternative would be to pass the in some some library Diet template:
application code:
|
It should just be in well written English and otherwise just roughly follow the style of the other sections (a brief description and a short example). |
Yes, perfect ! With possibly a predicate as well, taking the name of the calling diet template as a parameter or something of the sorts.
The framework I'm working on has plenty of statically defined collections e.g. |
This commit prepares for support of string templates, originally proposed by Stefan Koch (Uplink_Coder) in #482.
added a few functions to templ/diet.d and a hook to it in server.d
you can now import a stringTemplate as ALIAS
Multiple String-imports per file are now supported.
this however involved adding a template form bearophile
I think this is now mergeable...