RejectedSoftware Forums

Sign up

Pages: 1 2 3

Re: creating a diet-template at compile time

Update It's now possible to include multiple stringTemplates per file!

Re: creating a diet-template at compile time

On 2014-01-25 15:11, Uplink_Coder wrote:

Until I have fixed my code and multiple string-includes are possible
you can get away with

string genIncludeString(string[] filenames)
{ Appender!string res;
   foreach(filename;filenames)
     res ~= "include "~filename;

   return res; }



If .dt file includes with wildcard works within a diet template, the
next step would be to append to the -J path of a project's dependencies,
every views folder in a project's dependencies.

e.g.

users/views/sidebarlogin.dt
users/views/login
page.dt
blog/views/template.dt
blog/views/article.dt
someblogwebsite/views/homepage.dt
someblogwebsite/views/sidebar_about.dt

blog/views/template contains:

!!! 5
body
...
div#sidebar

 include #{sidebar_*}

... etc

So when someblogwebsite is compiled, it wants the sidebarabout and
sidebar
login to be included in this template. The only way I can
imagine this is by having dub automatically extend the -J./path
parameter of the users/ project dependency so that it contains all the
views folders available to the project.

So, this question may be more about dub's internals as well... and then
about the possibility of including a .dt file inside another.

Re: creating a diet-template at compile time

I think I know how to do that with stringIncludeTemplates.
please wait abit for a proof-of-concept.
I won't be pretty but should be pretty do-able, though with
abit of manual labor ...

Re: creating a diet-template at compile time

Solved it :D

http://www.dpaste.dzfl.pl/4805d7da

Re: creating a diet-template at compile time

Is the order in wich those templates are includeded not a concern ?
or should it be strictly alphabetical ?

Re: creating a diet-template at compile time

On 2014-01-26 10:06, Stefan Koch wrote:> Is the order in wich those templates are includeded not a concern ?

or should it be strictly alphabetical ?

I'm a little inspired by the joomla module positions

http://docs.joomla.org/Module_positions

You can see plenty of templates at http://www.joomlart.com/ or extensions in http://extensions.joomla.org/ and I'd be so happy if this were possible in vibe.d with dub as the install manager

For ordering, the positioning would have to be defined in the filename e.g. top1search, top2menu.

I feel like the views folder of different dub packages should be freely modifiable (including the names of files for ordering), but their source code should never be touched. Changing the source code of any dub package should always be strictly through a configuration file. And these dub packages can be made to work together if this "include" structure can work properly.

Additional restrictions could be defined as inline D code in the included diet templates assuming they're built into a framework that evaluates some variables lazily from cache or config. e.g.

- if (This.config["modulename"]["is_enabled_for_route"]){
	diet code...
- }

That's what I'm working on with my framework btw but I need some adjustments to make it possible :P

So, of course, the main content of a page is still pushed into the template.dt block through a block/extends. This really just solves adding multiple modules from separate libraries regardless of the build order.

Re: creating a diet-template at compile time

On Sun, 26 Jan 2014 09:48:17 GMT, Uplink_Coder wrote:

Solved it :D

http://www.dpaste.dzfl.pl/4805d7da

That wouldn't be convenient, the directory paths would have to be entered manually for each dependency, no plug & play here. This needs to be in dub, each dependency would have to be compiled with a -J path that combines the "views" folders of every dependency down to the main project.

Re: creating a diet-template at compile time

there is a function to list dirEntrys it can be made to work at compile time ...

Re: creating a diet-template at compile time

On Sun, 26 Jan 2014 17:27:28 GMT, Etienne Cimon wrote:

On Sun, 26 Jan 2014 09:48:17 GMT, Uplink_Coder wrote:

Solved it :D

http://www.dpaste.dzfl.pl/4805d7da

That wouldn't be convenient, the directory paths would have to be entered manually for each dependency, no plug & play here. This needs to be in dub, each dependency would have to be compiled with a -J path that combines the "views" folders of every dependency down to the main project.

In this dpaste http://www.dpaste.dzfl.pl/4805d7da
is a way to see the views folders of all supprojects
from there a clever RegEx gives you a nice AA and you can
just pass the include-lines per string into your template.
you can event load them during initialisation and stringTemplate them into your .dt :D

Re: creating a diet-template at compile time

In this dpaste http://www.dpaste.dzfl.pl/4805d7da
is a way to see the views folders of all supprojects
from there a clever RegEx gives you a nice AA and you can
just pass the include-lines per string into your template.
you can event load them during initialisation and stringTemplate them into your .dt :D

You mean this: dirEntries("..\\..\\","[views].dt" ...

The concept is more than ideal. A small hiccup is, the subprojects aren't always found in ..\\..\\ - they could be anywhere on a hard drive. This would also have a risk of including more views than what's necessary. I think this could do as a workaround though until dub guarantees that they're included directly in -Jpath

This has the potential to work perfectly in the meantime as a matter of fact. I'll have to test it out :)

I'm still brainstorming about cache setter delegates using std.events and so on, this would allow lazy evaluation of functions found in subprojects for use in the included modules.

So, I hope you can get a working prototype up :P

Pages: 1 2 3