Ahoy
I am trying to add another filter to a diet template so that instead of
:javascript
test();
I want to add something for doing WebGL programming, so my diet template would look like
:shaderfs
test();
I have tried merely replicating the javascript blocks in http.server.d
like
static string filterShaderFS(I)(I text, size_t indent = 0)
{
// added a simple return string here
return "<script id=\"shader-fs\" type=\"x-shader/x-fragment\">" ~ '\t'
~ "precision mediump float;" ~ '\t' ~ "</script>";
}
...
static this()
{
filters["css"] = (input, scope output) { output(filterCss(input)); };
filters["javascript"] = (input, scope output) { output(filterJavascript(input)); };
filters["markdown"] =(input,scope output) { output(filterMarkdown(cast(string)input)); };
filters["htmlescape"] = (input, scope output) { output(filterHtmlescape(input)); };
// added this in
filters["shaderfs"] = (input, scope output) { output(filterShaderFS(input)); };
}
Also in vibe.templ.diet.d
static this()
{
registerDietTextFilter("css", &filterCSS);
registerDietTextFilter("javascript", &filterJavaScript);
registerDietTextFilter("markdown", &filterMarkdown);
registerDietTextFilter("htmlescape", &filterHtmlEscape);
registerDietTextFilter("shaderfs", &filterShaderFS); // added this in
}
...
foreach_reverse( f; filters ){
bool found = true;
switch(f){
default: found = false; break;//break filter_loop;
case "css": content = filterCSS(content, out_indent); break;
case "javascript": content = filterJavaScript(content, out_indent); break;
case "markdown": content = filterMarkdown(content, out_indent); break;
case "htmlescape": content = filterHtmlEscape(content, out_indent); break;
// added this in
case "shaderfs": content = filterShaderFS(content, out_indent); break;
}
if (found) filters.length = filters.length-1;
else break;
...
static string filterShaderFS(string text, size_t indent)
{
return "<script id=\"shader-fs\" type=\"x-shader/x-fragment\">" ~ '\t'
~ "precision mediump float;" ~ '\t' ~ "</script>";
}
I can't see any other locations that javascript
is mentioned that is worth changing.
The code that implements the filters seems to my simple brain to be quite convoluted.
If I create a simple working app, then add in the shaderfs line
doctype 5
html(lang="en")
head
title Uploader
:shaderfs
test();
:css
.test
I get the following
[lots of log stuff]
...
webserver ~master: building configuration "application"...
Compiling Diet HTML template studio.dt...
studio.dt(7,20): Error: function vibe.http.server.staticTemplate!"studio.dt".staticTemplate.__lambda1.filter!(req, DefaultFilters).filter (const(char[]) input, string filte
r, void delegate(const(char[])) nothrow @safe output) is not callable using argument types (string, string, void)
../../../../../.dub/packages/diet-ng-1.1.3/diet-ng/source/diet/html.d(91,7): Error: template instance vibe.http.server.staticTemplate!"studio.dt".staticTemplate.__lambda1.c
ompileHTMLDietFile!("studio.dt", req, DefaultFilters).exec!(StreamOutputRange!(OutputStream)) error instantiating
../../../../../.dub/packages/vibe-d-0.8.0-beta.2/vibe-d/http/vibe/http/server.d(240,63): instantiated from here: compileHTMLDietFile!(StreamOutputRange!(OutputStream
))
../../../../../.dub/packages/vibe-d-0.8.0-beta.2/vibe-d/http/vibe/http/server.d(163,6): instantiated from here: render!("studio.dt", req)
source/webserver.d(25,13): instantiated from here: staticTemplate!"studio.dt"
dmd failed with exit code 1.
Any pointers towards where I could look to get something like this working?
Are there other files I need to be considering?
Thanks in advance.
B