So, many of us on IRC agree that the syntax for sourcecode filters is a bit ugly; I've taken it upon myself to come up with a sort of proposal for how syntax filtering might be made a bit prettier, feedback is welcome (and encouraged). Please submit your ideas for how it could look/work as well
Edit: Updated with Araq's feedback.. although it's starting to look like valid nimrod code anyway and could probably be implemented with just a library and some syntax highlighter support
############PROPOSED##################
import strutils
template layoutTemplate(title: string, body: expr): stmt {.immediate.} =
#Note: Automatically ignores (optional) indents
#used to indicate filter scope
filter(standard): """
<html>
<link href=style.css rel=stylesheet>
<h1>My Site - $title</h1>
$body
</html>
"""
proc view(model: string): string =
const title = "hello world" #Normal nimrod code above filter:
filter: """
$*Server-side comment, preface code w/ dollar sign *$
$layoutTemplate(title):
<div>$model</div>
"""
echo view("this is some content")
############COMPILED TO##################
proc view(model: string): string =
const title = "hello world" #Normal nimrod code above filter:
result = ""
result.add("<html>\n <link href=style.css rel=stylesheet>\n <h1>My Site - ")
result.add(title)
result.add("</h1>\n")
#Server-side comment, preface code w/ dollar sign
result.add(" <div>")
result.add(model)
result.add("</div>\n")
result.add("</html>")
############OUTPUT##################
<html>
<link href=style.css rel=stylesheet>
<h1>My Site - hello world</h1>
<div>this is some content</div>
</html>