Re: New built-ins (`?whatever` things)... any opinions/ideas?
Denis Bredelet <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.devel |
|---|---|
| Message-ID | <[email protected]> |
"chose" should really be "either" I think. Not sure what's the use of ?char or ?bin_8. I like followed_by and dump Should min and max work on lists instead of single values? -- Denis. On 8 Aug 2012, at 08:18, Daniel Dekany <[email protected]> wrote: > I'm planning to add some new buildins to FreeMarker 2.3.x. I'm not > sure which of these will go to the next release, but certainly not all > of them (lack of time...). I would like to hear some opinions, or > ideas regarding better names and semantics. Also regarding what other > built-ins you miss. > > boolExp?chose(whenTrue, whenFalse) > > This one is instead of Java's ternary operator (exp ? exp : exp), that > FTL can't have due to syntactical reasons. Of course, the operators > are evaluated on demand. It's like #if/#else, but it's an expression. > > n?until(m[, step=1]) > n?to(m[, step=1]) > These would deprecate the ".." operator, which was sadly > mis-designed back then. They create a numerical range, always with > step 1 (not -1) unless `step` was provided. "until" has exclusive end, > "to" has inclusive end. > > s?safe_substring(from[, to]) > > Same as ?substring, but ignores out-of-ranges > > n?char > > Converts UCS codepoint to character. Like 65?char is 'A'. > > n?abs > Absolute value > > n?[bin|[j]hex|oct]_[8|16|32|64] > That is ?bin_8, ?bin_16, ..., hex_8, hex_16. The difference between > "hex" and "jhex" is tat the last prints with a 0x prefix. > > n?is_nan, n?is_infinity > Works only for numbers, tells if the wrapped number is float or > double NaN or Infinitiy (positive or negative). > > exp1?followed_by(exp2) > > This returns exp1 + exp2, but only if both are defined and are > non-0-length strings. This is useful in situations like these: > > <title>Foo bar<#if extraTitle??> - ${extraTitle}</#if></title> > > or > > <#if statement??>${statement};</#if> > > That is, you want to print an optional variable and when it exists, > you also want to print something before or after it. These would > become to: > > <title>Foo bar${' - '?followed_by(extraTitle)}</title> > > ${statement?followed_by(';')} > > min/max: > > I wonder how to add min/max functions. `n?min(m)` looks silly IMO. > It could be `.min(n, m)` instead, where the initial dot is for the > special-variable syntax (used for .data_model, .version and like). > Only it's something most user don't know... > > exp?dump > exp?dump_as_text > > Prints the value for debugging purposes. ?dump would print it as > XHTML, while dump_as_text as text/plain. > > -- > Best regards, > Daniel Dekany > > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > FreeMarker-devel mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/freemarker-devel ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/