google-code-export / asp-ajaxed

Automatically exported from code.google.com/p/asp-ajaxed
1 stars 0 forks source link

Default value to TextTemplate placeholder #11

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
An improvement of the TextTemplate rendering system.

With this code, we can use placeholders with default values:

e.g. <<< USERNAME | anonymous user >>>
If the placeholder "USERNAME" is not set, or if it is an empty string, the 
template write "anonymous user" (without quotes).
I choose the pipe | to be the separator because it is very common to us the 
use of | or || to represent an OR statement. The example's placeholder can 
be read like "USERNAME or 'anonymous user'".

I didn't wrote tests to this feature yet.
It didn't works with blocks, because the sintax is very strange: <<< BLOCK 
name >>> <<< ENDBLOCK name | default value >>> or <<< BLOCK name | default 
value >>> <<< ENDBLOCK name >>>. The way to do it is not so different of my 
code.

public placeHolderSeparator ''[string] If you want to use your own 
placeholder characters. this is the separator. e.g. <em>|</em>

In class_Initialize, add:
placeHolderSeparator = " \| " ' the \ is necessary because the placeholders 
are used with regexp

Replace the replacePlaceHolders function to this function:
private function replacePlaceHolders(input, varName, varValue)
    regex.pattern = placeHolderBegin & varName & "(" & placeHolderSeparator 
& "(.+))?" & placeHolderEnd
    replacePlaceHolders = regex.replace(input & "", str.Parse(varValue, 
"$2") & "")
end function

Original issue reported on code.google.com by iurisil...@gmail.com on 5 May 2009 at 2:50

GoogleCodeExporter commented 9 years ago
This issue was closed by r61.

Original comment by mga...@gmail.com on 24 May 2009 at 12:13

GoogleCodeExporter commented 9 years ago
This issue was closed by revision b449d4f2b12b.

Original comment by mbussel...@gmail.com on 14 Jun 2013 at 6:31