add new kind of string literal for templates #9831
Labels
area-language
Dart language related items (some items might be better tracked at github.com/dart-lang/language).
closed-not-planned
Closed as we don't intend to take action on the reported issue
type-enhancement
A request for a change that isn't a bug
This issue was originally filed by @tatumizer
Proposed new type of string literal - ideally, in backquotes (e.g.
foo
).These strings are supposed to be used only in instance methods in a class, and be automatically compiled into invocation of method "handleTemplate" (exact name TBD):
void handleTemplate(String str, String templateStr), e.g.
class Foo {
var sb=new StringBuffer();
void handleTemplate(String str, String templateStr) {
sb.write(str);
}
void example() {
<h1>Customers</h1>
; // calls handleTemplatefor (customer in customers)
<p>${customer.name}</p>
; // calls handleTemplate// etc...
}
}
As a second argument, system should pass original string as is (e.g. r'<p>${customer.name}</p>'), for the purposes of preventing injection of something bad. Example:
void handleTemplate(str, templateStr) {
sb.write(ensureNoHtmlMarkup(str, templateStr));
}
These new literals will greatly simplify generation of all kinds of data: html, css, program code (generators) etc.
The text was updated successfully, but these errors were encountered: