rejetto forum

Macros

Mars · 231 · 142592

0 Members and 1 Guest are viewing this topic.

Offline TSG

  • Operator
  • Tireless poster
  • *****
    • Posts: 1935
    • View Profile
    • RAWR-Designs
{{if|{{file|exist|url}}|then|else}}

I like it.  :D
« Last Edit: December 12, 2007, 03:39:05 PM by That_Stevens_Guy »


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13523
    • View Profile
The requested URL {{header | GET}} was not found on this server.

the command line (the first line) of the header is not handled.
what you need it for?


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2063
    • View Profile
Quote
user created macros aka user created functions. The possibility to write a complex macro and place it in a user created function with custom parameters would be useful.
to call it {{call function | function-name | $A$ | $B$ |...}} A and B are the custom parameters.

to create {{function | function-name | $A$ | $B$ |...}}{{the macros to execute}} A and B define the parameters just like in javascript function (A,B,C){}...

eg {{call function | addition | 1 | 3 | 5}} 9 would be returned.

{{function | addition | $A$ | $B$ | $C$}}{{{{add | $A$ | $B$ | $C$}}}}

or you could even have the commands to execute as the last parameter, so the example above would be

{{function | addition | $A$ | $B$ | $C$ | {{add | $A$ | $B$ | $C$}}}}

Edit: Simple addition and subtraction, etc would be useful. Im working on something now that I must subtract one number from another so i know how many times to repeat itself.
Quote
{{ define | left{{#str|#len}} | {{cut | 0 | #len |#str }} }}


After a lot of reflection, I think of having found the solution:

To overload a macro or define a macro instead of the other one, we can use this macro

{{yourmacro|A|B|C|D|.....}}  to use it

parameters  A,B,C,D,.... are passed in this order  $1,$2,$3,$4,..... to the overloaded macro

to define your macro you must use

{{define| yourmacro| {{one_macro|$1|$2|$3|$4}} }}

you can invert some parameters as ...

{{define| yourmacro| {{one_macro|$4|$2|$1|$3}} }}

...to accommodate the order of your parameters in agreement with the macro overloaded

by sample     {{ define | left | {{cut|0|$1|$2}} }}      usage  {{left|($1)|$2}}


It will be possible to extend to more macros as

{{define| yourmacro | {{firstmacro|$3|$4}} {{secondmacro|$1|$2|$3}} {if|$4| then|else}} {{$5}} }}

but is is important  that $5 must be passed as '$name' with the $ before name, otherwise the call of macro {{$name}} will not work, the risk is that you obtain {{name}} on the place.

« Last Edit: December 12, 2007, 11:21:45 PM by mars »


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13523
    • View Profile
{{ if filexist | filepath | dosomething | elsedothat }}

ok, in next build you'll find {{file size|PATH}}
so you will be able to do it with {{if| {{file size ...
it will return 0 for non existant files, and zero is "false" in macros.
99% we won't need a {{file exists}} because we are normally not interested in empty files.


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13523
    • View Profile
if the order of evaluation is ok, something like this may work ...

at the moment there's a problem with evaluation order: ALL is evalutade.
in {{if|test|then|else}} both then and else are executed, but else is discarded.
this was ok till now, but it's not good for some useful macros to come, so i will work on it.


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13523
    • View Profile
{{define| yourmacro| {{one_macro|$1|$2|$3|$4}} }}

yes, this is good. I would call it {{set}}
to avoid name collision with existing and future macro names, a starting character will be required. I propose {{!mymacro}}

Is there something i missed to understand or could you explain what would be the behaviour of alias with expression?

i think we need just 2 different types of macros: one that will be evaluated immediately, and one that will be evaluated when called.
maybe {{set}} will evaluate, while {{set later}} will do it later.
i think they should share the same namespace, then you would call always by {{!the-name-i-want}}
of course parameters $1 $2 will make sense only for {{set later}}. {{set}} will handle things like they would be "variables".


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2063
    • View Profile
rejetto
 That do you ask SET is I ask ALIAS
 That do you ask SET LATER is I ask DEFINE 

'set' is good instead 'alias' but 'set later' can make confuse, you must choice another word like 'set macro' because their syntax are differents

{{set | name | text or macro}}  call by {{$name}}
{{set var| varname | text or macro immediatly evaluated}}  call by {{!varname}}
{{set macro| macroname | {{M1|...}}{{M2|....}}....}}  call by {{macroname}}

*****************
{{set |.....}}

{{set | you  | %user%}}   it is a fixed string value you can redefine
{{$you}} is replaced by %user%  (working like{{$section}})

works as you use

[you]                                call by           {$you}
%user%


*****************
{{set var|.......}}

can be use as a variable you increase or decrease
{{set var| varname | num value }}  call by {{!varname}}
{{set var|x | 5}}     {{inc | x |2}}  and then {{!x}} give 7
 {{inc | name | value }}    same as     {{set var| x | {{!x}} +2 }}
 {{dec | name | value }}    same as     {{set var| x | {{!x}} -2 }}

result must be stored by hsf to can to work later with  {{inc|..}} and {{dec|..}}


*****************
{{set macro|....}}

{{set macro | yourmacro | {{macro1|$1|$2|$4|$3...}} {{macro2|$5|$6}} {{..}}....}}

call as a normal macro {{yourmacro}} and by {{yourmacro|parameters}} there is no confusion, IT IS A MACRO

The substitute macro 'yourmacro' is in an array of 'section', every 'item-string' contains the text to be substituted ( as a DIFF Template)  when the macro {{yourmacro|parameters}} is found then we substitute it in the template  by the 'item-string' and replacing every $x by the correct parameter of 'yourmacro'

one example with no parameters as section [file] in your template

{{set macro|item-file|<tr><td>%new% %protected% <a href="%item-url%"><img src="/~img_file" /> %item-name%</a>%comment%<td align=right>%item-size%<td align=right>%item-modified%<td align=right>%item-dl-count%}}


and use

[file]
{{item-file}}                   no parameters here but it is an 'alias'

[folder]
{{item-folder}}


{{$file}} is converted to {{item-file}} Which is converted in his turn there 'alias'

See you  the difference now?
« Last Edit: December 12, 2007, 11:03:55 PM by mars »


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13523
    • View Profile
'set' is good instead 'alias' but 'set later' can make confuse, you must choice another word like 'set macro' because the syntax are differents

names are not the main problem and can even be chosen later

Quote
{{set macro | yourmacro | {{onemacro|$1|$2|$4|$3...}} /macro}} is more representative than
{{set later| yourmacro | {{macro1|$1|$2|$4|$3...}} {{macro2| $5|$6}} {{..}}..../set}}

i don't understand why you are making different examples for set macro and set later.

Quote
and call as a normal macro not with {{!mymacro}} but by {{$yourmacro|parameters}} there is no confusion

using $ both for sections and things defined by "set" may lead to colliding names.
you reading a new template see $xx, and may search for section [xx] in the template, but you don't find because it's a variable. I don't like this scenario.

Quote
The substitute macro 'yourmacro' is in an array of section,

it's just a string (the name) paired with a content (the body). why you call it array.

Quote
See you  the difference now?

between set and set macro/later? yes
between set macro and set later? no


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2063
    • View Profile
Quote
using $ both for sections and things defined by "set" may lead to colliding names.

j'ai modifié mon post précédent pendant que tu écrivais

Quote
between set macro and set later? no


We see at first glance that the functioning is the one of a macro. It seems to me more significant, with ' later ', one do not know when it will take place.


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13523
    • View Profile
yes, i see it's like a macro. and that's exactly what i thought "set later" would be.
i told you i don't understand the difference of behaviour, not the difference in the name. later/macro.


Offline Foggy

  • Tireless poster
  • ****
    • Posts: 806
    • View Profile
The requested URL {{header | GET}} was not found on this server.

the command line (the first line) of the header is not handled.
what you need it for?

I was trying to display what was requested on a 404 error page.


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13523
    • View Profile


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13523
    • View Profile
till now i proposed and made examples by {{!name}} but ! is already used for localization.
so, i propose {{^name}} instead.


Offline bacter

  • Operator
  • Tireless poster
  • *****
    • Posts: 681
    • View Profile
Thanks for your work, rejetto and mars !

before entering to concrete macros, some general points to think about:
1. Security of execution: As the number of macros  grow and their use will be growing, the possibility of hard to find errors increases. This means that the implementation in the delphi source should do some error checking, allowing a message where or what kind of error ocurred. For this, y suggest to include in the generated page some <p style="display:none" >{{ macro error and/or expanded macro }}</p> This could probably be switched on or off with a pseudomacro: {{debug | 1 }} . Not present: Search error by beating your head against the monitor. debug 1: see errormessage or offending expression. debug 2: see full expanded macro

2. Probably it would make reading more clear if macro names would not contain spaces:
: if not --> ifnot
: is substring -> issubstring
: file size --> filesize,
this makes reading of foreign template more simple, nobody would look for macrodefinitions like is,if,file,size,substring(this one already has confusion implementated, as macro substring exists!)

Macro 'define':
This macro is a real macro for the macro-'language', it must never be evaluated!
but i think it should not be overloaded and its definition should contain the exact number of parameters, that could be instead $n any meaningfull combination of caracteres to make it more understandable. This would also allow to check for errors if the numbers of parameters is not correct, when the definition should be applied.
{{ define | {{left | string | count } | {{ cut {{ 0 | count |string }}}}}}
then when parsing the tpl '{{ left ' is found it should be substituted  by the second expression of define, applying by the way the substitution of the named parameters. When this is done, evaluation can begin.

by the way: it would be nice (because simpler to understand) to use in the wiki instead of A B C ... meaningful things:
issubstring | sample | string
cut | start | count | string .....

Namespace to use by macros:
I think there is no need to use another special caracter. But the namespace could hold an atribute-flag: 1-intrinsic macro definition 2-user definition of macro (define) 3-user set-alias macro.
If we establish some rules (all intrinsic functions are lowercase) the templatewriter can use a naming-scheme or use uppercase to distinguish intrinsic an userdefinded functions/macros.

I would propose set(preferable) or alias for inmediate execution
an define as definition, with no execution, only used to be substituted with executable macros.
« Last Edit: December 13, 2007, 12:29:20 AM by bacter »
your computer has no brain - use your own !