rejetto forum

Software => HFS ~ HTTP File Server => Topic started by: rejetto on November 04, 2007, 11:20:08 PM

Title: macros coming...
Post by: rejetto on November 04, 2007, 11:20:08 PM
symbol %urlvar% is no more.

it is different from other symbols, it requires more power.
it's a new thing, it's a macro, and urlvar is the first of this new generation. wow ::)

the syntax is different.
initially i thought to keep the %old syntax%, but this can be ambiguous for the user and slow for the computer (because % is both beginning and ending).
i introduce a new syntax that should be easy to see and to type.
so it would be {{urlvar|sort}} to read the content of 'sort'.

any suggestion for a different syntax should be adequately justified.
i was uncertain about using {single pairs}, but this way it should be more visbile and hardly collide with other syntaxes. to type twice the same char is fast.

[[double square brackets]] are easier to type, but can easily collide with [section] names in the template.

if this experiment with macros is successful, then user symbols %sym-anything% will be deprecated. they will be subsituted by the macro {{section|name}}.

all this will be since build #139
Title: Re: macros coming...
Post by: rejetto on November 05, 2007, 12:05:38 AM
for those geek who like to know WHY macros. :)

macros are somewhat faster for the template engine. because its value is calculated only when it is met. it is not calculated if it is not there.

macros can be void. if you use %urlvar-thing% but there is no thing parameter in URL instead of a having an empty space you will get %urlvar-thing% printed on your page. this can't be solved with the symbols engine.

with the %sym-thing% you are constrained in calling your section [sym-thing]. you can't just name it [yeah].
with macros you will be able to recall the content of [yeah] with {{section|yeah}}.

macros can have any number of parameters separated by |.
i could eventually create a macro "add" and it would work like {{add|3|5}} and 8 would be the output.
"add" is not very useful, but it's just to show you what it can do more than %symbols%.
Title: Re: macros coming...
Post by: bacter on November 05, 2007, 12:27:41 AM
I'am not sure to have understood the syntax of the macro feature.

When in next build [sym-thing] is deprecated can I do a quick change in the template like this:

Supose y have now [sym-info], [sym-header]... that replace %sym-info%... etc.

Can y simply leave my [sym-thing] sections and change the calls (%sym-info%...) to
{{section|sym-info}}, {{section|sym-header}} ?

Is it correct that we will have initially two macros 'section' and 'urlvar' ?
Title: Re: macros coming...
Post by: rejetto on November 05, 2007, 12:30:33 AM
yes, all correct
Title: Re: macros coming...
Post by: ELEVENNNN on November 05, 2007, 01:33:00 AM
This is great; but even better is that it is coming out before the two major releases, thunderchicken of glory and terayon will be able to implement the new changes before their release, only two or so weeks away!

As usual, good work Massimo.

-Kurt
Title: Re: macros coming...
Post by: Foggy on November 05, 2007, 05:22:54 AM
This is great; but even better is that it is coming out before the two major releases, thunderchicken of glory and terayon will be able to implement the new changes before their release, only two or so weeks away!

If rejetto keeps adding new features we might have to wait even longer for them, but I can live with that because I always like a new feature to play with ;D
Title: Re: macros coming...
Post by: TSG on November 05, 2007, 06:21:36 AM
http://www.rawr-designs.com/tog/todo.php

Now that I have time from university, I have pushed 2 projects to the next build, only 2 more until release of 3.0.0.
Title: Re: macros coming...
Post by: rejetto on November 14, 2007, 06:37:50 PM
i have been working hard on the macros engine.
now it supports macro in macro.
this is an argumen for "experts", so if you truly have no idea of what i'm talking about, it's normal, pass on. :)

in next build i will use this syntax to make the search appear only when the recursive listing is enabled:

{{if| {{get|recursive}} | {{section|search }} /if}}

the final /if is optional, it's only for readability, to avoid confusion with many parenthesis. every macro can have it, it's just ignored by hfs.
to increase readability you can even split the macros over several lines, indenting.
Title: Re: macros coming...
Post by: Mars on November 14, 2007, 10:47:39 PM
Il va falloir sérieusement remettre à jour la version de "tpl.hlp.rtf" dans les sources cher ami rejetto. ;D
Title: Re: macros coming...
Post by: rejetto on November 15, 2007, 03:06:27 AM
I'm documenting all the thing at http://www.rejetto.com/wiki/index.php?title=HFS:_Template_macros
Title: Re: macros coming...
Post by: rejetto on November 15, 2007, 03:44:57 AM
hey templaters, you shall look at the way i'm changing the tpl for build #144
you'll be surprised of what macros can do :)
Title: Re: macros coming...
Post by: TSG on November 15, 2007, 04:04:53 AM
I can't wait for this :)
Title: Re: macros coming...
Post by: Foggy on November 15, 2007, 05:18:50 AM
Imagine the possibilities. :O
Title: Re: macros coming...
Post by: MarkV on November 15, 2007, 08:02:09 AM
Imagine the possibilities. :O

Slogan for HFS maybe?  ;)
Title: Re: macros coming...
Post by: TSG on November 15, 2007, 04:15:41 PM
Imagine the possibilities. :O

Slogan for HFS maybe?  ;)

I like it. :)

Imagine the possibilities... :o
Title: Re: macros coming...
Post by: Mars on November 15, 2007, 04:53:14 PM
do you like having a macro like

{{ CASE | {{macrotest}} | {{ident1}},{{ident2}}:{{result1}} | {{ident3}},..,{{identN}}:{{result12}} |........| ELSE:{{ElseResult}} }}

all {{ident}} are type of strings
{{macrotest}} is type of string
all {{result}} are what you want

the use of this? it is by example

{{CASE | %lang% | en , us :{{section|english}} | fr , be: :{{section|french}} |...| ru : :{{section|russian}} |ELSE :{{section|english}} }}

Title: Re: macros coming...
Post by: rejetto on November 15, 2007, 05:22:12 PM
ok for 'case'
but you are using commas as separator.
commas may be part of ident1.
we need a smarter solution.
making the second parameter specify the separator would solve, it's just a bit ugly.
Title: Re: macros coming...
Post by: Mars on November 15, 2007, 06:06:50 PM
To avoid the problem here is a new syntax with
 'en'||'us' 
 'en';'us'   
 'en'&'us'         
 'en'!'us'
  [en][us] 
'en'='us'


{{CASE | '%lang%' | 'en' & ..& 'us' :{{section|english}} | 'fr' & 'be': :{{section|french}} |...| 'ru' :{{section|russian}} |/ELSE :{{section|english}} |/CASE}}

or

{{CASE | '%lang%' | 'en' / ../ 'us' :{{section|english}} | 'fr' / 'be': :{{section|french}} |...| 'ru' :{{section|russian}} |/ELSE :{{section|english}} |/CASE}}

I put / before ELSE to not to confuse with %test%=ELSE
if you don't want comma, you can use another separator a none dos name character in ( \ / : * ? " < >)

Title: Re: macros coming...
Post by: rejetto on November 15, 2007, 06:13:26 PM
mars, your suggestions don't solve the problem at all.
changing the character is not a solution.
Title: Re: macros coming...
Post by: Mars on November 15, 2007, 06:43:48 PM
rejetto change what you want, result must be same like (case of else end) in delphi code and syntax similar
Title: Re: macros coming...
Post by: Giant Eagle on November 15, 2007, 07:11:51 PM
Quote from: rejetto
hey templaters, you shall look at the way i'm changing the tpl for build #144
you'll be surprised of what macros can do :)

OMGWTFBBQ  :o imagine the possibilities!! [/quote]

really! this is amazing.


Who needs php now!?
Title: Re: macros coming...
Post by: rejetto on November 28, 2007, 09:48:04 PM
Since i didn't found a better solution for the switch statement, i adopted the one i cited above.
{{switch}} is coming in #147 and is already documented.
Title: Re: macros coming...
Post by: Mars on November 28, 2007, 09:56:12 PM
And what think of of this:

Quote
if pars.Count < 1 then exit; // from here, only macros with parameters

if name = 'length' then                               
  try result:=Length(result) except end;         

if name = 'uppercase' then                                   
  try result:= AnsiUpperCase(result) except end;

if name = 'lowercase' then
  try result:= AnsiLowerCase(result) except end;

if name = 'trim' then
  try result:= Trim(result) except end;

if name = 'trimleft' then
  try result:= TrimLeft(result) except end;

if name = 'trimright' then
  try result:= TrimRight(result) except end;

if name = 'contains' then
  try result:=AnsiContainsStr(result) except end;

if pars.count < 2 then exit; // from here, only macros with at least 2 parameters



That can serve in certain cases  ......  the others are for the study. ;D

to be followed...
Title: Re: macros coming...
Post by: rejetto on November 29, 2007, 02:07:03 AM
ok for trim, upper, lower, length, is substring