rejetto forum

Macros

Mars · 231 · 83938

0 Members and 1 Guest are viewing this topic.

Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 1994
    • View Profile
{{ define | {{left | string | count } | {{ cut {{ 0 | count |string }}}}}} is to long, you duplicate the expressions and this code is not good

by using   'define' or 'set macro'

{{set macro| left | {{ cut| 0|$2|$1}}  }}

it is more simple to rejetto to evaluate the expression   
{{left|mystring|count}}

if you look at code delphi

left is  the variable(delphi) 'name'
mystring is pars[0] alias $1
count is pars[1] alias $2
....
and in template you see that $1 is the first param of {{left|($1)|($2)}}

Quote
This macro is a real macro for the macro-'language', it must never be evaluated!

when you use %user% in template he is replaced by the login

when you use {{left|string|count}} , he is replaced in the template by  {{ cut| 0|$2|$1}}
and all expressions as $1 $2  are replaced by the value string , count

and the template take the following aspect  {{ cut| 0|count|string}}

simple mais efficace et c'est pareil pour les 'alias', chaque macro est remplacée par son équivalent

tout comme quand on utilise  {{load|file}}, hfs remplace la macro par le texte qui lui correspond; rien de plus.

« Last Edit: December 13, 2007, 12:59:46 AM by mars »


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13304
    • View Profile
Hold on guys.
(1)
At the moment the macros engine doesn't allow to macros to decide to execute the code LATER.
All macros are executed from inner to outer, and from left to right.
This is not good, but it's easier. I will work to see if i can get something better, but that's not trivial.

In the while the only method to get a text not executed is to quote it.
Till #161 quoting is done by {{quote yo! /quote}} and it was meant to be used rarely.
From next build i will change this into {{\ yo! /}}.
So, i'm the only way to get {{set}} to execute the body later is to do something like

{{set| shout at | {{\ HEY YOU, {{upper|$1}}! /}} }}

then use it via {{^shout at|rejetto}}
this would expand to HEY YOU, REJETTO!

this for sure delays the suffered decision about the name of 'set later'. ;)
we'll have just {{set}} and you'll decide execution by using the quoting markers.

(2)
Let me specify that you won't always need the quoting markers.
{{set| salute | Hi $1!}}
Since we don't use macros inside, we don't need extra markers.
And we'll call it as usual by {{^salute|rejetto}}

(3)
I want to keep it simple.
Not simple for the user, simple for me!
To create a FULL programming language is pointless. I could just invoke an external php, and at least php programmers wouldn't need to learn a new syntax.
This thing makes sense while we keep it low. That's one of the reason i'm not sure about point (1).


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 1994
    • View Profile
Quote
Since we don't use macros inside, we don't need extra markers.

Quote
when you use {{left|string|count}} , he is replaced in the template by  {{ cut| 0|$2|$1}}
and all expressions as $1 $2  are replaced by the value string , count

and the template take the following aspect  {{ cut| 0|count|string}}

we don't need extra markers to do this, simplement une zone de stockage pour l'échange des parametres

{{set macro|left| {{ cut| 0|$2|$1}} {{length|$1} {{load|taratata.txt}} }}
 name='set macro'
 pars[0]='left'
pars[1]='{{cut| 0|$2|$1}} {{length|$1} {{load|taratata.txt}}'

stockage de 'left' et  '{{cut| 0|$2|$1}} {{length|$1} {{load|taratata.txt}}'

quand on trouve {{left| ....}} on remplace les $x par les paramètres  de {{left}} et on transfère dans le template , c'est ca que j'appellerai le 'set later'
Quote
{{set| shout at | {{\ HEY YOU, {{upper|$1}}! /}} }}

why not we can use
]{{set| shout at | {{quote| HEY YOU, {{upper|$1}} !}} }}

{{command| parameters}}   au moins ça se retient facillement, sinon on n'arrive plus à se souvenir quel caractère il faut mettre et quand ?, entre {{$name}} pour les sections, {{!name}} pour les {{set var|..}} se souvenir de {{\ en lieu et place de {{" ou de {{'
et que sais je encore ??? ??? ???

multiplier les noms de macros OUI , mais utiliser des symboles praticuliers, là on va flirter avec le linux
« Last Edit: December 13, 2007, 01:32:09 AM by mars »


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13304
    • View Profile
we don't need extra markers to do this, simplement une zone de stockage pour l'échange des parametres

you are not understanding the problem mars.
the current parser is not able to do what you are asking.
you have to use the extra markers.
is it clearer now?


Offline bacter

  • Operator
  • Tireless poster
  • *****
    • Posts: 681
    • View Profile
Rejetto
I understand you want the macro thing be something simple, you are right.

So perhaps it would be a good idea to take some rest before implementing more and more things that will be difficult to use, as most 'set' 'alias' or 'define' have workarounds with sections. When the ideas are are more matured and depending on the needs of the users, perhaps the macromachine could be made more powerfull finding a better way to satisfy programmers and users need. Creating with to much hurry perhaps leads to macros and sintax that later must be changed to be usefull.
your computer has no brain - use your own !


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 1994
    • View Profile
where is the real problem? I see how you make the code. problem is it to detect all $x and the last }},  je ne pense pas que la substitution de chaines soit un probleme.
le principe s'appuie sur
Quote
procedure applyMacro(macroname :string;len:integer);
  const
   var
    PATTERN:STRING;
    p: integer;
 
  begin
  idx:=0;
  PATTERN:= '{{'+macroname;
    repeat
    p:=pos(PATTERN, result);
    if p = 0 then exit;   
    delete(result, p, len));
    move(macroname.tpl[1], result[p], length(macroname.tpl));
    until false;
  end; // applyMacro


si on respecte la notation

{{command | parametre1 | parametre2 | parametre3 | ...}}

il n'y a aucun probleme lors de l'utilisation de

{{substring|rejetto|mars|{{$comprehension}} }}


[comprehension]

{{quote rejetto n'est pas pret de convaincre mars sur ce sujet /quote}}

result is n'est pas pret de convaincre
« Last Edit: December 13, 2007, 02:36:15 AM by mars »


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13304
    • View Profile
where is the real problem? I see how you make the code. problem is it to detect all $x and the last }}

No, of course.
The problem is described the execution order.
http://www.rejetto.com/wiki/index.php?title=HFS:_Template_macros#Execution_order


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13304
    • View Profile
from #162 this already works

{{set|x|5}}
{{^x}}
{{inc|x|-3}}
{{^x}}

it will print
5
2


Offline TSG

  • Operator
  • Tireless poster
  • *****
    • Posts: 1934
    • View Profile
    • RAWR-Designs
 filesize | A
    tells you the size in bytes of the file A. At the moment URL are not supported, only local filenames.

this would be much handier we had %item-resource% that told the local file path, cause then all i have to do is add the sub folder previews_and_thumbnails/thumb-%item-name%.jpg and it will work perfectly :) i can probably be more specific and target the preview image with this feature previews_and_thumbnails/preview-%item-name%.jpg


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 1994
    • View Profile
ok TSG  but if you want to see size of a file  myfavico.ico  to make an include you can't detect him with %item-...%
sample
{{if| {{filesize|myfav.ico}} | <link rel="shortcut icon" href="template/myfavico.ico" />  |<link rel="shortcut icon" href="favicon.ico" />}}

all %item-...% works only in section %list% that is a problem

but you can use {{filezise|%item-url%}} for your ask


Offline TSG

  • Operator
  • Tireless poster
  • *****
    • Posts: 1934
    • View Profile
    • RAWR-Designs
I have spoken to rejetto about this, %item-resource% is the best method we have come up with, the filesize macro does not work with URL's atm, just local directory like C:\something\something\ which is why it is not working currently, %item-resource% will give more power to this macro. Until it can use URL



On another note, shouldn't {{if|{{get|can archive}}| work in place of %item-archive% ? atm i can only make a check using {{if|%item-archive%| with [item-archive] containing some text. I think that can archive should work in place of %item-archive% when it comes to the macro.

And maybe another macro {{if|{{get|can access}}| in place of %protected%?
« Last Edit: December 13, 2007, 12:48:44 PM by That_Stevens_Guy »


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13304
    • View Profile
i guess "can archive" at the moment works only on the folder itself, not on items of the folder.


Offline TSG

  • Operator
  • Tireless poster
  • *****
    • Posts: 1934
    • View Profile
    • RAWR-Designs
Yes that is the case.

Is it possible to stop the line break after a {{$}} its very annoying and causes many bugs with js and some html related tasks...
« Last Edit: December 13, 2007, 06:15:13 PM by That_Stevens_Guy »


Offline Foggy

  • Tireless poster
  • ****
    • Posts: 806
    • View Profile
I was testing out the set macro and couldn't figure out why it wasn't working for me and then realized set and call have to be in the same template section, shouldn't you be able to call a user macro from anywhere in the template otherwise it defeats the purpose because you have to place the code for the macro in each section anyway.


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13304
    • View Profile
Is it possible to stop the line break after a {{$}} its very annoying and causes many bugs with js and some html related tasks...

i will remove the last line break from sections

I was testing out the set macro and couldn't figure out why it wasn't working for me and then realized set and call have to be in the same template section, shouldn't you be able to call a user macro from anywhere in the template otherwise it defeats the purpose because you have to place the code for the macro in each section anyway.

it's not a matter of sections.
SET must be before CALL in the way the final html is built.
if you place SET in [file], then it will be issued several times, not just one.
i guess that if you replace your SET and CALL with A and B you will see the B before the A.