Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

BUILD-MARKUP Function

 [1/2] from: oliva::david::seznam::cz at: 5-Aug-2002 9:07


Hello Carl, Saturday, August 3, 2002, 6:08:19 AM, you wrote: CaR> Some of the changes include: CaR> Added BUILD-MARKUP Function Nice function, but what about this small improvement: build-markup: func [ {Return markup text replacing <%tags%> with their evaluated results.} content [string! file! url!] /quiet "Do not show errors in the output." /with {Starting and ending tags - by default it's "<%" and "%>"} mstart [string!] mend [string!] /local out eval value ][ content: either string? content [copy content] [read content] out: make string! 126 if not with [mstart: "<%" mend: "%>"] eval: func [val /local tmp] [ either error? set/any 'tmp try [do val] [ if not quiet [ tmp: disarm :tmp append out reform ["***ERROR" tmp/id "in:" val] ] ] [ if not unset? get/any 'tmp [append out :tmp] ] ] parse/all content [ any [ end break | mstart [copy value to mend 2 skip | copy value to end] (eval value) | copy value [to mstart | to end] (append out value) ] ] out ] so we can choose starting and ending tags:
>> build-markup {now is: <%now%>}
== "now is: 5-Aug-2002/8:47:53+2:00"
>> build-markup/with {now is: <#now#>} "<#" "#>"
== "now is: 5-Aug-2002/8:55:01+2:00" You may think, that it's not usefull, but what if someone want to preprocess some PHP or ASP code where the default tags (<% %>) are used as well? But maybe nobody will need it and if someone will need it, may replace the build-markup function with this one or other:-) --oldes

 [2/2] from: al:bri:xtra at: 6-Aug-2002 16:28


RebOldes wrote:
> Nice function, but what about this small improvement:
build-markup: func [ {Return markup text replacing <%tags%> with their evaluated results.} content [string! file! url!] /quiet "Do not show errors in the output." /with {Starting and ending tags - by default it's "<%" and "%>"} mstart [string!] mend [string!] /local out eval value ][ content: either string? content [copy content] [read content] out: make string! 126 if not with [mstart: "<%" mend: "%>"] eval: func [val /local tmp] [ either error? set/any 'tmp try [do val] [ if not quiet [ tmp: disarm :tmp append out reform ["***ERROR" tmp/id "in:" val] ] ] [ if not unset? get/any 'tmp [append out :tmp] ] ] parse/all content [ any [ end break | mstart [copy value to mend mend | copy value to end] (eval value) | copy value [to mstart | to end] (append out value) ] ] out ] I've made a slight improvement in the 'parse rule, changing the "2 skip" to mend , so as to allow variable length ending tag. Using a fixed length is asking for trouble! :) I've sent it to feedback as well. Andrew Martin ICQ: 26227169 http://valley.150m.com/