rejetto forum

Software => HFS ~ HTTP File Server => HTML & templates => Topic started by: Mars on December 08, 2007, 06:21:58 PM

Title: Macros
Post by: Mars on December 08, 2007, 06:21:58 PM
Some ideas of macro for the continuation


Quote
%symbols%  : Text   HFS symbols
%mysection%   : HTML Text  for compatibility with old templates

//  Boolean must be TRUE or FALSE  ,   nothing else

{{ not | Boolean | /not }} : Boolean                                 result= not(Boolean)
{{ and | Boolean1 | Boolean2 | ... | BooleanN | /and }} : Boolean    result= Boolean1 AND .... AND BooleanN
{{ or | Boolean1 | Boolean2 | /or }} : Boolean                       result= Boolean1 OR .... OR BooleanN
{{ xor | Boolean1 | Boolean2 | /xor }}  : Boolean                    result= Boolean1 XOR Boolean2



{{ is == | Num1 | Num2 | /is }} : Boolean   To be NEW
{{ is >= | Num1 | Num2 | /is }} : Boolean   To be NEW
{{ is <= | num1 | Num2 | /is }} : Boolean   To be NEW            
{{ is <> | Num1 | Num2 | /is }} : Boolean   To be NEW             
{{ is >> | Num1 | Num2 | /is }} : Boolean   To be NEW             
{{ is << | Num1 | Num2 | /is }} : Boolean   To be NEW             


{{ is def | urlvar| /is }} : Boolean  return TRUE if URLVAR is defined in url     To be NEW             


{{ is equal | Text1 | Text2 | /is }} : Boolean
{{ is empty | Text | /is} : Boolean                           To be NEW             
{{ is substring | subText | Text | /is} : Boolean


{{file|name|url}}   '' or a name   To be NEW
{{file|size|url}}     '' or >=0       To be NEW
{{file|date|url}}    '' or a date     To be NEW
{{file|empty|url}}  true or false   To be NEW
{{file|exist|url}}    true or false   To be NEW


{{if | Boolean | then | else | /if }} : Text
{{ if not | Boolean | then | else | /if }} : Text
{{ switch | What | Text1 | Result1 | Text2 | Result2 | .... | TextN | ResultN_ as_Default | /switch }} : Text


{{ pos | subText | Text }} : Num                       To be NEW             
{{ length | Text }} : Num

{{abs| value}}                                   Abs  Returns the absolute value of a signed number
{{max| value1 | value2 |...| valueN }}   Max  Gives the maximum of some integer values       
{{max| value1 | value2 |...| valueN }}   Min  Gives the minimum of some integer values
 

{{calc | numerical expression to be evaluated }}
syntax:
{{calc | num1 | + | num2 | - | ( | num3 | / | num4 | ) | * | -num5 }} or
{{calc |num1+num2-(num3/num4)*(-num5) }}

{{ left | Text | Num }} : Text                                   To be NEW             
{{ right | Text | Num }} : Text                                 To be NEW             
{{ mid  | Text | Num-From | Num-Upto }} : Text       To be NEW             
{{ upper | Text }} : Text
{{ lower | Text }} : Text
{{ trim | Text }} :Text


{{ repeat | Num | Text }} : Text

{{ substring | From-After-Text | To-Before-Text | Text-Source }} : Text

{{ cut | Num-From(begin) | Num-Upto(end) | Text  }} :Text

{{ replace | Text-Old | Text-New | Text-Source }}

{{ chopline | Num | Text-Source}} : HTML Text                       To be NEW             

{{ section | mysection }} : HTML Text             load section from active template
                                                                   (included "diff template" and  hfs.diff.tpl) idem as %[mysection]%
{{ section | mysection | external_file}} : HTML Text            load mysection from external template


{{load | external_file}} : HTML Text

{{load | external_file | from-line | Upto-line }} : HTML Text       To be NEW              
 
{{translate|text}}    translate any text to UTF-8     To be NEW             

{{alias| name | html-text}}  call by {{$name}}     To be NEW             
       return html-text  can be use as variable
{{inc | $name | value }}      To be NEW             
{{dec| $name | value }}      To be NEW             
     at the place of  {{alias|name|{{calc|{{$name}}+ value}} }}

{{define | newmacro | {{macro|$1|$2|$3|....}}  }}   To be NEW             
       call by {{newmacro| param1|param2|.....}}






http://www.rejetto.com/wiki/index.php?title=HFS:_Template_macros
Title: temp
Post by: bacter on December 08, 2007, 07:55:41 PM
Mars:
I'am far from trying to discourage you from proposing new macros, but we should care not to increase the number of macro-functions without increasing funcitionality.
Code: [Select]
{{ left | Text | Num }} : Text
{{ right | Text | Num }} : Text
{{ mid  | Text | Num-From | Num-Upto }} : Text

for example can already be done wit cut.

Also it would be very nice if you could explain what the macros that are not already en the wiki should do, like 'chopline' and 'replace'.
Title: temp
Post by: Mars on December 08, 2007, 10:08:04 PM
 
Quote
cut | A | B | C
cut C from position A, for B characters. The difference with macro substring is that here you specify where to cut by numeric positions. Example: with A=2 and B=3 and C=abcdef you will get bcd because it is from character 2 and for a length of 3.

The name of this macro seems to me misleading, the "copy" word would been more adequate

How many programmers uses exclusively the  function 'copy(string, from, to) ??

Mainly in the programs, we find rather its by-products which are left, mid, right.

To return to the macro 'cut' there, she executes what makes the function 'copy',  excepted for the negative values where it makes  exception for the rule.

On this question I would rather have seen the macro cut under this aspect

cut | A | B | C
Example: with C=ABCDEFGHIJ A=3 and B=4 and  ,you will get  ABGHIJ


It was everything made possible to make the difference enter

{{substring| AB | GHIJ | ABCDEFGHIJ }}
and
{{substring| 3 | 4 | ABCDEFGHIJ }}

without passing by the macro CUT, because few chances to meet itself in the indecision with
{{substring| 3 | 4 | 428635710]4598 }}

Rejetto I have nothing against the command CUT it is simply to argue against bacter ;),I excuse him for it. I shall put that at the account of the difference of age, the other time(period), the other philosophy. ;D ;D ;D ;D ::)

At least this debate has to make nothing in this topic.!!!
Title: Re: Macros
Post by: rejetto on December 09, 2007, 05:52:52 PM
The name of this macro seems to me misleading, the "copy" word would been more adequate

I guess you are proposing the word "copy" because you are used to Delphi. This is not what i call "a good reason", and people are not required to know Delphi.
The name copy in Delphi is due to the fact the function does a copy of a piece of the string.
If you use {{cut}}, you are not storing the original string, that is, you didn't copied.

Quote
On this question I would rather have seen the macro cut under this aspect

yes, i guess not everyone will agree with the meaning.

Quote
At least this debate has to make nothing in this topic.!!!

indeed, i moved it
Title: Re: Macros
Post by: Mars on December 09, 2007, 07:04:56 PM
 ;)
C++
size_t copy ( char* s, size_t n, size_t pos = 0) const;
http://www.cplusplus.com/reference/string/string/copy.html


*************************************************************
autre chose:

{{TRANSLATE | récursif ou linéaire, où à n'être rien  }} 

     result = r&eacute;cursif ou lin&eacute;aire, o&ugrave; &agrave; n'&ecirc;tre rien 

{{TRANSLATE |
<PRE>
 L'accent en italien est écrit uniquement sur la dernière syllabe.
ex: città, virtù, libertà, lunedì, Nicolò, cioè
Dans ce cas, ces mots sont invariables au pluriel.
</PRE>
}}

result= .....

la macro convertirait les codes accentués en leur equivalent html unifié.

usage {{translate | {{load|texte_accentué.txt}} ]]

Title: Re: Macros
Post by: rejetto on December 09, 2007, 07:44:15 PM
if your template is UTF-8 you don't need to convert characters.
also external .txt files can be saved as UTF-8, even with notepad.
if for any reason you have external ANSI files that you need to include, i will create a macro to convert in UTF8, because it would be easier to do.
Title: Re: Macros
Post by: Foggy on December 10, 2007, 05:17:47 AM
Quote
{{ is == | Num1 | Num2 | /is }} : Boolean   To be NEW
{{ is >= | Num1 | Num2 | /is }} : Boolean   To be NEW
{{ is <= | num1 | Num2 | /is }} : Boolean   To be NEW             
{{ is <> | Num1 | Num2 | /is }} : Boolean   To be NEW             
{{ is >> | Num1 | Num2 | /is }} : Boolean   To be NEW             
{{ is << | Num1 | Num2 | /is }} : Boolean   To be NEW             


{{ is def | urlvar| /is }} : Boolean  return TRUE if URLVAR is defined in url     To be NEW             
 

These would be very useful.
Posted on: December 10, 2007, 03:15:44 PM
to save creating a new topic im posting my sugestion here

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.
Title: Re: Macros
Post by: TSG on December 10, 2007, 06:41:13 AM
is it possible to check the user agent, cause i have some macro's that are just IE fixes... be nice to turn em off for IE.
Title: Re: Macros
Post by: Mars on December 10, 2007, 06:02:07 PM
 
Quote
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.

A macro is a function to her alone, it uses parameters and returns a result as string, actualy only one macro give a numeric value :{{length|string}

For your demand I propose a macro one specialized in the calculation, of the genre:

{{calc | num1 | + | num2 | - | ( | num3 | / | num4 | ) | * | -num5 }}


identical to
num1 + num2 - ( num3 / num4 )*(-num5)

it will be posible to have

{{calc|num1+num2-(num3/num4)*(-num5)}} to reduce length

then simply functions as A+B, A-B, A*B are possible

A/B is more complicate if result is not an integer, he can be truncated or rounded to the nearest integer. result of A/B can be the quotient and result of  (A%B) give the rest of the division (modulo)

Or result can be a real, rejetto has the choice



I will search code to this macro
Title: Re: Macros
Post by: Mars on December 10, 2007, 09:30:55 PM
 another 3 macros to add

 Abs  Returns the absolute value of a signed number  {{abs| value}}
 Max  Gives the maximum of some integer values       {{max| value1 | value2 |...| valueN }}
 Min  Gives the minimum of some integer values         {{max| value1 | value2 |...| valueN }}

Quote a macro and give your opinion for or against (  If possible, only favorable notices; ;) to bacter)
Title: Re: Macros
Post by: Mars on December 10, 2007, 09:56:48 PM
Still I

Instead of writing several times the same macro in a template, we could use alias

{{ alias | alias-name | {{macro defined to be an alias}} }}

Working on the same principle as the call to sections {{$section}}

{{ alias | myalias | {{ my macro}} }}   talking by {{$myalias}}

Replaceable also by

Quote
{{$myalias}}

[myalias]
{{my macro}}
it is possible to put any alias in an external file and load it by {load|alias.tpl}

{{alias|...}} don't appear into user's browser and is considered by hfs as  macro {{comment ...}} , but who works as a [section].

NOTE: It will be possible to use {{alias| name | some text}} and call it by {{$name}} and then we have a string var 

Quote
{{alias| rejetto | The person without whom we would not be on this forum there}}

{{$rejetto}}  --->  The person without whom we would not be on this forum there


{{alias | minval | -2 }}                 {{$minval}}  --->  -2

{{alias | maxval | 255 }}               {{$maxval}}  --->  256

I hope to have been rather precise so that everybody understands

Title: Re: Macros
Post by: bacter on December 11, 2007, 12:18:23 AM
Now we are getting more close to what macros can be!

The idea of 'alias' and rejettos idea of (pound or &)name in a [special] section -->http://www.rejetto.com/forum/index.php?topic=5349.msg1030874#msg1030874 (http://www.rejetto.com/forum/index.php?topic=5349.msg1030874#msg1030874).

First we have to pay attention: a {{comment  ...}} will just be ignores when building the page, but when parsing the tpl, it's different if there appears a 'normal' macro that will be evaluated and applied, or if there appears a 'special' ,as i would like to say, definitions macro: there is nothing to evaluate, only to 'learn or remember' the new definition for future use.

Both things, the alias proposed by mars and rejettos idea of [special ...] could be done the same way. You could think about it in the style of #define in C-preprocessor.. if we could enhance de macrodefinition with parameter replacing, the need for 'hardwired' functions would be less and users could write definitions of their preference:
Look at this (alias or define, may be the same) in a headerfile or section:

{{ define | left{{#str|#len}} | {{cut | 0 | #len |#str }} }}
.. and in the same style mid, right etc.











Title: Re: Macros
Post by: Mars on December 11, 2007, 12:53:08 AM
Look at this (alias or define, may be the same)

NO they are different

define use parameters over parameters like

define function left(str,len);
    {
      result:=copy(str,0,len);
    };

ALIAS do not work in the same way

ALIAS is transparent as the macro COMMENT,

{{alias|name|text you want}}

 but what you define is accessible simply by {{$name}}

bacter, you must read all line from begin to end  in my posts ??? here I repeat twice same things

Quote
{{$myalias}}

[myalias]
{{my macro}}

or

Quote
{{$myalias}}

[myalias]
my text

with this sample {{$myalias}} is fixed

but with {{alias|myalias|text you want}} you can redefine it
Quote
<HTML>
<HEAD>
{{alias|myalias| my alias is in head}}

</HEAD>
<body>
here,
{{$myalias}}   

{{alias|myalias|-->now he is in body}}
<br>
{{$myalias}}
</BODY>
</HTML>

here, my alias is in head
-->now he is in body



but {{define| ....} is not a bad thing,
Title: Re: Macros
Post by: rejetto on December 11, 2007, 01:01:18 AM
These would be very useful.

ok, in next build

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.

i will look if that's possible

Quote
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.

in next build
Title: Re: Macros
Post by: rejetto on December 11, 2007, 01:18:51 AM
is it possible to check the user agent, cause i have some macro's that are just IE fixes... be nice to turn em off for IE.

you long wondered what the {{header}} was for
{{header|user-agent}}
but also have a look at http://www.quirksmode.org/css/condcom.html
Posted on: 11 December 2007, 02:03:44
{{calc|num1+num2-(num3/num4)*(-num5)}} to reduce length

i will work onto this, and maybe tha alias/define story
Title: Re: Macros
Post by: TSG on December 11, 2007, 03:21:51 AM
lol, yes i am already doing that. But i noticed the {{header}} macro and was wondering if i can turn all off all IE js events, they fix IE6's lack of support for the css param :hover on objects other than a:, in firefox and opera i just have 2 fake functions so it doesn't fire off errors. But i would rather not have them at all. I will play with {{header|user-agent}}


EDIT: It seems i need a macro with indexOf... or match... in javascript you say, if(navigator.userAgent.indexOf("MSIE")!=-1)

{{if|{{header|user-agent}}|indexOf|{{string|MSIE 6.0}}|{{$DO THAT}}|{{$DO THIS}}/if}}

i don't know the exact syntax but ye... something like that.

scrap that {{if|{{is substring|MSIE 6|{{header|user-agent}}/is}}|CONTENT/if}}
Posted on: December 11, 2007, 10:55:59 AM
Ok another idea, im trying to do my entire filelist in the single [file] by looking at %item-ext%.

I need the ability to go either, if else if else if else or

if value = this or this or this, print this,  else print this.

possible?  ;) this new template of ours i want to be the cutting edge of template technology  :) and im bored.

reason for this is easy editing, if i can have it all in one section it'll be so much easier than copy/pasting to 5 or 6 sections, which i believe is one of the purposes of the macro :P
Title: Re: Macros
Post by: Foggy on December 11, 2007, 05:56:34 AM
I'm trying to use this for the not found error page but I'm not getting anything returned where the header macro is. I think I have done the syntax for it right, so am I doing something wrong?

The requested URL {{header | GET}} was not found on this server.
Title: Re: Macros
Post by: bacter on December 11, 2007, 05:13:09 PM
alias  mars:

you can be sure i read your post from start to end, sometimes even several times, when i'm not sure that i have understood what you mean.

What i understand with redefining an alias, is that you want to use this thing in some way like a variable, that could be very useful.
On the other hand you use it in some way as a section, then its used like %section%, being able to call different section by the same name.

What i do not see now, is if you assign to the alias name the expression or the value of the expression!

Example (to see what i mean i dont use {{}}macro syntax):
Somebody wants to show what file of the list was most downloaded and how many times.
So in the files section he inicializes:  {{alias | fname | noname }} {{alias | maxhit | 0}}
in the file section then he compares and assigns :
// as 'ifgreater | val1 |val2 | dosometing | elsedosomething' or {{ is >> | Num1 | Num2 | /is }} are not already impelemented, i use borrowed sintax:
{{ifgreater | %item-hit% | maxhit | {{alias | maxhit | %item-hit%}}{{ alias | fname | %item-name% }} | }}

if the order of evaluation is ok, something like this may work ... but supose you have 10 files, and file number 6 had most hits.
at he end of the list {{maxhit}} will show 22 (numer of hits of file number 6) or 3 (number of hits of the last file, as %item-hit% holds value of the last item or will it be undefined as outside [file] %item-hit% does not exist? (same problem for fname!)


Title: Re: Macros
Post by: Mars on December 11, 2007, 06:23:22 PM
template to your sample (when all macros are ok to rejetto)

Quote
[files]
{!--
{{alias|fname|}}                                            fname=''
{{alias|maxhits|0}}                                        maxhits=0
--}
....
%list%
....
{{if|{{$fname}}|Best hits to {{$fname}} with {{$maxhits}} downloads}}
....
[folder]
....
[link]
....
[file]
{!--
{{if |{{is >>| %item-hit% | maxhit}} | {{alias | maxhit | %item-hit%}}{{ alias | fname | %item-name% }}  }}
--}
...
that all

initiate  values
%list%
see the result

in this order to what you hope to do

Title: Re: Macros
Post by: bacter on December 11, 2007, 10:33:30 PM

Mars:
You have expanded a little the code i put as example, but you didn't answer to the important point of the question ! I wonder if i should use in the same way
Quote
bacter mars, you must read all line from begin to end  in my posts Huh? here I repeat twice same things
  :D :D :D

So, if you are saying that your example code works, this means that with alias the expression is evaluated when the macro is defined, e.g the macro will hold the value of the expression.

{{ alias | name | expression } :
so if expression is %item-dl-count% , name will hold the value of %item-dl-count%

So far, that's very good. That implies ve have variables!

But here arises the big problem:

Quote
{{ alias | alias-name | {{macro defined to be an alias}} }}

example:
if i define this alias in the files section before list:
{{ alias | isimage | {{ if |=|{{cut(-3|3|%item-name%}}||img | This is a disk image|}}}}
and then try tu use it in the file section:
Quote
[file]
<tr><td>%new% <a href="%item-url%"><img src="/~img_file" /> %item-name%</a>%comment%{{isimage}}<td align=right>%item-size%<td align=right>%item-modified%<td align=right>%item-dl-count%
what would happen?

If your first example (the maxhit code) works because the value of expression is evaluated ad assigned to the alias, i think the second example can't work, because when the expession is evaluated, %item-name% is not already defined and evaluation should produce an error!

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

alias assigns expression or value of expression to alias-name?

Thanks

Title: Re: Macros
Post by: Mars on December 11, 2007, 11:22:02 PM
Quote
>%comment%{{$isimage}}<td

Quote
this means that with alias the expression is evaluated when the macro is defined,

yes it is 
Quote
{{ alias | isimage | {{ if |=|{{cut(-3|3|%item-name%}}||img | This is a disk image|}}}}
{{ if |=|{{cut(-3|3|%item-name%}}||img | This is a disk image|}} is evualuted, and isimage get the result

Quote
if i define this alias in the files section before list:
{{ alias | isimage | {{ if |=|{{cut(-3|3|%item-name%}}||img | This is a disk image|}}}}
{{ alias | isimage | {{ if |{{=|{{cut|-3|3|%item-name%}}|img}} | This is a disk image /if}} }}  is more correct
Quote
Symbols available in section [files]
%list%
%item-archivable%
%item-ext%

Symbols available in sections [file], [folder] and [link]
%new%
%comment%
%item-url%
%item-name%
%item-folder%
%item-added%



Quote
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.

i will look if that's possible

http://www.rejetto.com/forum/index.php?topic=5353.msg1030947#msg1030947

to have what you will there is new feature {{define|user-function|rejetto-function}}

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

you can use
{{alias|hfsini|{{load|/hfs.ini}} }}
and then alias='
HFS 2.3 beta - Build #161
active=yes
.....
folders-before=yes
'

{{alias|my alias|<body>........</body>}}

whats you put after myalias| must be a string as result

{{alias|len|{{length|%user%}} }}

ce ne sont pas le possibilités qui manquent....

if you will a not evaluated then you must use sections instead alias

[isimage]
{{ if |{{=|{{cut|-3|3|%item-name%}}|img}} | This is a disk image /if}}

and talk it by {{$isimage}} in the section [file] (because you use %item-name%)
 
Title: Re: Macros
Post by: TSG on December 12, 2007, 05:35:37 AM
It would be nice to detect if a file is not available. Atm for our image gallery we use javascript, and it can be quite a load on cpu with big galleries.

The ability to server side with a simple if, will reduce this dramatically :) and have a more professional finish.

What we need, is the ability to say, {{If|The file At This Directory Is Unavailable|DO THIS|DO THIS}}, another reason is that onError="" is very unreliable, and we rely on it :P

I tried the below but as you would think, doesn't work :P

{{if|{{load|previews_and_thumbnails/thumb-%item-name%.jpg}}|DO THIS|DO THAT}}
Title: Re: Macros
Post by: Mars on December 12, 2007, 08:49:35 AM
Eh TSG! What do you think of that?

{{if|{{length|{{load|/rien.txt}}}}|file exist|file is empty or not exist}}

{{if|{{length|{{load|/hfs.ini}}}}|file exist|file is empty or not exist}}




Title: Re: Macros
Post by: TSG on December 12, 2007, 10:41:09 AM
I need to detect jpg images though?

Sorry that was vague..

I need to detect if a file exists, but i don't think load will work cause it only supports text files, or code, etc.
Title: Re: Macros
Post by: Mars on December 12, 2007, 11:53:09 AM
I am anxious to remind a very important thing:

ALL THE MACROS ARE EXECUTED AT THE LEVEL OF THE SERVER
ALL THE JAVASCRIPT IS EXECUTED AT THE LEVEL OF THE BROWSER


***********************************************************************


Everything depends on how much file are to be detected and also of the size, because every file is read in its entirety to determine its size. If you make this for all the items, it will be longer than for one ?ecursive, and hfs risks to make an out of memeory (file-size >100Mo by sample)

The ideal would be to have complements to macro for the load function without loading all the file in memory


{{load|url}}
{{file|name|url}}
{{file|size|url}}
{{file|date|url}}
...
sample (it is only a sample):

{{file|size|c:\.....\file.ext}}  will rerturn the exact size

but {{file|size|http://server/......./file.ext}} has no sense then you can by-pass the problem by using
{{length|{{load|http://server/......./file.ext}} }}

Title: Re: Macros
Post by: TSG on December 12, 2007, 12:06:36 PM
I don't want to detect the file size, just IF its there, if there is actually an object available to download or not. If its a dead link, do this else do that. And i agree, i don't want to increase the cpu on the server side too much.
Title: Re: Macros
Post by: Mars on December 12, 2007, 02:32:28 PM
- If the file is in a real folder, even as virtual file, if it is not available on your hard drive, he does not appear in the list  (by  [file]   %item-name% ) hfs exclud possibility to see this file)



- If the file is stored at an external address to the server and accessible only by http or ftp
you can just use in template {{length|{{load|http://server/......./file.ext}} }} to detect if file is accessible. if you use a [link] as http://...../file.ext  then file is in hfs list, even if the link is void.

(virtual link with set url  file:///c:/..../file.ext seem not working but appear in hfs list)

in [link] and [file] sections you can test {{if|{{length|{{load|%item-url%}}}}| file exist|file not exist }}.   you receive the same result as at the first possibility.     

I can certenly help you TSG, but it would be necessary to be more precise to allow me to see the reach of your wait  by a little example in tpl.
Title: Re: Macros
Post by: TSG on December 12, 2007, 03:04:56 PM
ehmm... it is hard for me to give as an example... but i can give pieces.

This determines if the filetype is a compatible image file with our generator, and prints out the correct overlay image.
{{switch|%item-ext%|,|jpg,png,bmp|
<div style="background:url('previews_and_thumbnails/thumb-%item-name%.jpg') center center no-repeat"></div>|}}

Now, for our preview button, if there is no thumbnail available, it is assumed that there is no preview available, so in the ToG and Terayon we use <img blah onError="DO THIS"> but with large galleries, this can be harsh on the client cpu usage. What i am suggesting is the ability to say, if the file does not exist, disable the preview button. We have to disable the button, it prevents js errors.

This file is located at... 'previews_and_thumbnails/thumb-%item-name%.jpg' in the image gallery or folder. I really hate the way onError works and i hope this can be achieved with a little server side scripting. :) macro

Note the image without a thumbnail.
Title: Re: Macros
Post by: bacter on December 12, 2007, 03:10:29 PM
Suggestion for new macro:

{{ if filexist | filepath | dosomething | elsedothat }}

in the case of TSG this could mean:
filepath : thumbnailfilepath,
dosomething : <img src={{$thumbnailpath}} / >,
elsedothat: <img src="%itemurl%" width=160 height=140  >

other possible uses could be:
- sidebarinfo: if a file with additional information for a folder exists, when this folder is opened, show content of this file in sidebar (something like a huge foldercomment, that is only read when folder is open)
- look for personal messagefile for a user and display it on homepage when he logs in.
- if displaymode is slideshow, if musicfile for this folder exists , playit.
Title: Re: Macros
Post by: Mars on December 12, 2007, 03:28:39 PM
It increases the number of macros  IF and reduct the field of application
It is easier to have a macro which returns a result and to include him in a IF THEN ELSE

{{file|name|url}}   '' or a name
{{file|size|url}}     '' or >=0
{{file|date|url}}    '' or a date

{{file|empty|url}}  true or false

{{file|exist|url}}    true or false


*************
{{ not | Boolean | /not }} true or false                       
{{ and | Boolean1 | Boolean2 | ... | BooleanN | /and }}  true or false
{{ or | Boolean1 | Boolean2 | /or }}   true or false
{{ xor | Boolean1 | Boolean2 | /xor }} true or false

you dont having

{{if and|.....|then|else}}
{{if or|.....|then|else}}
{{if xor|.....|then|else}}

{{if not |.....|then|else}}   is an exeption

then

{if|{{file|exist|url}}|then|else}}
Title: Re: Macros
Post by: TSG on December 12, 2007, 03:36:19 PM
{{if|{{file|exist|url}}|then|else}}

I like it.  :D
Title: Re: Macros
Post by: rejetto on December 12, 2007, 05:04:48 PM
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?
Title: Re: Macros
Post by: Mars on December 12, 2007, 06:55:48 PM
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.

Title: Re: Macros
Post by: rejetto on December 12, 2007, 07:52:56 PM
{{ 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.
Title: Re: Macros
Post by: rejetto on December 12, 2007, 08:05:12 PM
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.
Title: Re: Macros
Post by: rejetto on December 12, 2007, 08:18:27 PM
{{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".
Title: Re: Macros
Post by: Mars on December 12, 2007, 10:02:46 PM
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?
Title: Re: Macros
Post by: rejetto on December 12, 2007, 11:07:49 PM
'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
Title: Re: Macros
Post by: Mars on December 12, 2007, 11:17:58 PM
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.
Title: Re: Macros
Post by: rejetto on December 12, 2007, 11:44:56 PM
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.
Title: Re: Macros
Post by: Foggy on December 12, 2007, 11:50:34 PM
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.
Title: Re: Macros
Post by: rejetto on December 12, 2007, 11:54:18 PM
you can use %url% since next build
Title: Re: Macros
Post by: Foggy on December 13, 2007, 12:04:55 AM
Thanks :D
Title: Re: Macros
Post by: rejetto on December 13, 2007, 12:21:12 AM
till now i proposed and made examples by {{!name}} but ! is already used for localization.
so, i propose {{^name}} instead.
Title: Re: Macros
Post by: bacter on December 13, 2007, 12:25:32 AM
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.
Title: Re: Macros
Post by: Mars on December 13, 2007, 12:49:13 AM
{{ 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.

Title: Re: Macros
Post by: rejetto on December 13, 2007, 01:06:55 AM
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).
Title: Re: Macros
Post by: Mars on December 13, 2007, 01:22:16 AM
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
Title: Re: Macros
Post by: rejetto on December 13, 2007, 01:30:18 AM
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?
Title: Re: Macros
Post by: bacter on December 13, 2007, 01:46:20 AM
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.
Title: Re: Macros
Post by: Mars on December 13, 2007, 02:01:31 AM
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
Title: Re: Macros
Post by: rejetto on December 13, 2007, 03:03:17 AM
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
Title: Re: Macros
Post by: rejetto on December 13, 2007, 03:21:45 AM
from #162 this already works

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

it will print
5
2
Title: Re: Macros
Post by: TSG on December 13, 2007, 05:36:32 AM
 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
Title: Re: Macros
Post by: Mars on December 13, 2007, 09:46:03 AM
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
Title: Re: Macros
Post by: TSG on December 13, 2007, 12:12:16 PM
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%?
Title: Re: Macros
Post by: rejetto on December 13, 2007, 02:35:01 PM
i guess "can archive" at the moment works only on the folder itself, not on items of the folder.
Title: Re: Macros
Post by: TSG on December 13, 2007, 03:15:02 PM
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...
Title: Re: Macros
Post by: Foggy on December 15, 2007, 03:56:12 AM
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.
Title: Re: Macros
Post by: rejetto on December 16, 2007, 04:11:32 PM
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.
Title: Re: Macros
Post by: Mars on December 16, 2007, 08:57:37 PM
a request

{{?urlvar}}  return the last url value from ?urlvar=x

when we want test the value we use  {{ {{?urlvar}} = x }}  true(1) or false(0)

i know it will be easy to concatenate it to obtain  {{?urlvar=x}} will return 0 if urlvar<>x,  and   '1' if true

{{?urlvar=}}  can give same result as  {{not|{{!urlvar}}}}

then by example

{{!sort=}} return true(1)  if sort is not in url else we must use  {{not|{{!sort}}}}
{{!sort=n}} return true(1) if sort is defined in url as  ?sort=n  , else false(0)
Title: Re: Macros
Post by: Foggy on December 16, 2007, 11:06:05 PM
it's not a matter of sections.
SET must be before CALL in the way the final html is built.

Thats what I thought to start with, but I'm not getting anything returned when SET is in the main section or in [files] and CALL is in [folder] and [file].
Title: Re: Macros
Post by: Mars on December 16, 2007, 11:14:09 PM
It is always necessary to present a part of your template to obtain a maximum of help(assistant),otherwise our understanding of your problem remains too vague
Title: Re: Macros
Post by: rejetto on December 17, 2007, 12:40:36 PM
Thats what I thought to start with, but I'm not getting anything returned when SET is in the main section or in [files] and CALL is in [folder] and [file].

ah, that's because the main section is parsed after the file list is built.
from next beta you can move your macros to the [special:begin] section.
this should solve your problem.
Title: Re: Macros
Post by: rejetto on December 17, 2007, 12:49:57 PM
i know it will be easy to concatenate it to obtain  {{?urlvar=x}} will return 0 if urlvar<>x,  and   '1' if true

it will work from next beta
Title: Re: Macros
Post by: Foggy on December 18, 2007, 03:10:59 AM
ah, that's because the main section is parsed after the file list is built.
from next beta you can move your macros to the [special:begin] section.
this should solve your problem.
Thanks rejetto. Always presumed the main section was parsed first.

When CALL and SET are documented in the wiki, it would probably be a good idea to mention that SET should be placed in [special:begin].
Title: Re: Macros
Post by: Mars on December 18, 2007, 10:10:25 PM
 ??? or ;D on behalf of  rejetto

is it POSSIBLE two create four macro

{{begin  | {{onemacro}}  }}     before main

{{before | {{onemacro}}  }}     before %list%

{{after   | {{onemacro}}  }}     after  %list%

{{end    | {{onemacro}}  }}      after  main


BEGIN work as section [special:begin] : before main

BEFORE is evaluated  at the begining of %list%

AFTER  is evaluated  at the end of %list%

END  is evaluated  when all macro and symbol  above are evaluated


Application:

somewhere in template we want to set a variable

{{begin | {{set| items | 0 }}  }}


we have section folder like

[folder]
{{inc|items|1}} ......

then to reproduce the last value at begining of main page, we must  use some javascript
else we can use

{{after| {{^items}} }} and no more  %list% {{^items}}  in this order to have the correct result
 
Title: Re: Macros
Post by: rejetto on December 19, 2007, 12:51:05 AM
you can do such job with just by using [special:begin]

try the attachment and you'll see it working
Title: Re: Macros
Post by: Mars on December 19, 2007, 01:03:52 AM
Already some hours ago that works

  look at the attachment
Title: Re: Macros
Post by: TSG on December 19, 2007, 03:25:26 AM
Can we get a macro for %new% {{if| {{is new|NEW!}} }} or something, if anyone has a better idea... Cause other than [item-archive]  and [protected], [newfile] is the only other section which only contains text for no real purpose. And also, the section name is incorrect cause %new% - [newfile] works on folders and links also...
Title: Re: Macros
Post by: Foggy on December 19, 2007, 03:57:07 AM
To try and stay the same as the other macros, I suggest {{get|is new}}

Edit, also an option to highlight "|" in the template editor would help readability and split the macro's up into smaller segments.
Another thought, The macro engine performs the macro's from the inside outwards, so at some point it would have to pair the braces"{{}}", would it be possible to have the braces paired in the template editor, where as if you clicked on a brace it would highlight all of its contents. That would help debugging your macro's greatly.
Title: Re: Macros
Post by: Foggy on December 19, 2007, 04:53:07 AM
A couple more macro suggestions :P
{{encodeURI}}
{{decodeURI}}
{{escape}}
{{unescape}}
These four would be useful to encode special characters and may help in language support.

and

{{round}}
Why have all the other math operators if you cant round your result's to X decimal places.
Title: Re: Macros
Post by: TSG on December 19, 2007, 09:32:26 AM
Pretty print is something i've wanted for a long time, but it is too hard apparently.
Title: Re: Macros
Post by: rejetto on December 19, 2007, 11:22:27 AM
every decent text editor has customizable highlighting.
i know you use notepad++ (i use pspad).
start building your syntax definition for template macros, cause it won't take long till we have support for the external editor. ;)
Title: Re: Macros
Post by: TSG on December 19, 2007, 12:09:55 PM
Oh u mean the template will be read from the external file finally? If that is the case, I might make a user defined one for notepad++ and post it on the forum... one that shows sections, symbols, and macro's.
Title: Re: Macros
Post by: rejetto on December 19, 2007, 12:17:05 PM
Oh u mean the template will be read from the external file finally?

something like that

Quote
If that is the case, I might make a user defined one for notepad++ and post it on the forum... one that shows sections, symbols, and macro's.

it would be great
Title: Re: Macros
Post by: jack_2000 on December 19, 2007, 01:21:07 PM
Once we solidify the syntax i may make one for Edit++ too.
But, i'm gonna need the full syntax reference in a list.
Title: Re: Macros
Post by: Foggy on December 19, 2007, 01:53:56 PM
Just look in the wiki, they should all be there.
Title: Re: Macros
Post by: Unknown8063 on December 19, 2007, 03:54:37 PM
Oh u mean the template will be read from the external file finally? If that is the case, I might make a user defined one for notepad++ and post it on the forum... one that shows sections, symbols, and macro's.

I would really enjoy this, Notepad++ is my editor of choice :)
Title: Re: Macros
Post by: rejetto on December 19, 2007, 05:03:15 PM
The syntax is easy
macros: {{macroname|parameter|parameter}}
macro quoting: {{\ any macro /}}
and %symbols%

nothing else
Title: Re: Macros
Post by: Unknown8063 on December 19, 2007, 05:06:13 PM
The syntax is easy
macros: {{macroname|parameter|parameter}}
macro quoting: {{\ any macro /}}
and %symbols%

nothing else

and [section]
Title: Re: Macros
Post by: rejetto on December 19, 2007, 05:11:53 PM
right! but only if [section] is at the very beginning of the line
Title: Re: Macros
Post by: Foggy on December 23, 2007, 07:57:53 AM
I noticed that a FOR macro has been documented in the wiki, is this coming the the next build? And could an example for it please be posted because I don't understand how we include the condition for it to keep looping.



I think I figured the syntax out but it isnt working correctly, The variable defined in parameter A only returns the number of loops that are going to be executed.
eg, the following loop created the output in the screenshot.

Code: [Select]
{{for|A|1|8|<input name="poll" type="radio" value="{{^A}}" /><label>{{!Option {{^A}}}}</label><br />}}
I had a look in the whats new list for the beta's and didnt see the FOR macro mentioned, is it still being coded/bugs being fixed before announcing it?
Title: Re: Macros
Post by: rejetto on December 23, 2007, 08:07:14 PM
it's in the what's new of #164.
it doesn't work because you are not using the macro quoting.
I put a reminder in the wiki.
Title: Re: Macros
Post by: Foggy on December 24, 2007, 12:16:19 AM
oh ok, I'll try it with the quoting. I went and had another look and didn't see it mentioned in the whats new for build 164. ???
Title: Re: Macros
Post by: rejetto on December 24, 2007, 12:40:10 AM
Quote from: what's new
+ new template macro: <> != for time filename
Title: Re: Macros
Post by: Foggy on December 24, 2007, 12:46:25 AM
lol, I misread it  ;D
Title: Re: Macros
Post by: Foggy on December 24, 2007, 05:21:52 AM
When you use append where does the file get saved when you only specify a name? eg {{append|file.txt|text}}

can you use server relative paths? eg {{append|/folder/file.txt|text}}

etc
Title: Re: Macros
Post by: rejetto on December 24, 2007, 02:38:20 PM
the hfs.exe folder is used as default.
/folder is not very relative.... it's absolute in the same drive unit.
folder/ is relative, or ../folder/
Title: Re: Macros
Post by: Foggy on December 26, 2007, 12:13:46 PM
the hfs.exe folder is used as default.
/folder is not very relative.... it's absolute in the same drive unit.
folder/ is relative, or ../folder/

Thankyou, it might  be a good idea to add that the hfs.exe directory is used as default.
Title: Re: Macros
Post by: Mars on December 27, 2007, 04:41:30 PM
The new template by default is arrived,
Mode page by page is effective  
Sorting by name and extension: novelties
Title: Re: Macros
Post by: TCube on December 27, 2007, 06:17:35 PM
Merci mars ! je vais essayer de transposer ton code dans une autre template, mais le process est bon : faire une recherche initiale puis un affichage du résultat en mode page/page ... excellent ! Million Thanks Mars !
TCube
Title: Re: Macros
Post by: SilentPliz on December 27, 2007, 06:57:55 PM
The new template by default arrived,
Mode page by page is effective 
Sorting by name and extension: novelties


Ajout à l'instant de ce "Marsellous" template (qui marche aussi bien sous FF qu' IE6) à une VF.

Mille bravos

SilentPliz
Title: Re: Macros
Post by: maverick on December 28, 2007, 07:34:53 PM
mars

You might want to make the following change to keep the text file out of the viewable file listing...

{{if| %user |{{\ {{append| %folder-resource%\hfs.comments.txt |{{filename|%item-resource%}}=uploaded by %user%
Title: Re: Macros: new template with mode page from mars 29-12-2007 1h24
Post by: Mars on December 28, 2007, 09:57:49 PM
After correction of some bugs, here is a not definitive but functional version

Quote
Merci mars ! je vais essayer de transposer ton code dans une autre template, mais le process est bon : faire une recherche initiale puis un affichage du résultat en mode page/page ... excellent ! Million Thanks Mars !

la transcription risque d'etre ardue , mais je m'efforce de simplifier au max sans utiliser de java

dans cette nouvelle mouture j'utilise un max de {{set...}} dans la section [special:begin]

j'ai introduit des regroupements par extension et aussi par nom mais en mode page/page j'ai encore un petit travail à terminer, mais la présentation actuelle devrait plaire à quelques un . ;D

Note to rejetto:
Quote
You might want to make the following change to keep the text file out of the viewable file listing...
Corrected, but error is in default template build 165
Title: Re: Macros nouvelle demande
Post by: Mars on December 29, 2007, 11:34:32 PM
1)
[special:begin]  existe déjà

[special:end]  en cours de fabrication

2) une nécessité pour moi
deux macros dans le même ordre d'idée
{{special begin| ........}}  évaluée immediatement après la section [special:begin]

{{special end|.........}}  évaluée juste avant ou après l'appel à la section [special:end] (de préférence juste avant)

3)
une macro qui retourne certaines valeurs d'options en "true or false" ou une valeur correspondante
{{get option| A}}   retourne la valeur correspondante à A dans HFS.INI
et plus précisément
{{get | folders-before}}  1|0
{{get | links-before}}      1|0
{{get | default-sorting}}   n|e|t|d|h
{{get | recursive-listing}}  = {{get |can recur}}
c'est plus simple que de charger hfs.ini dans le template et de recupérer la valeur que l'on souhaite tester

Un petit bug :  defaults-sorting =ext n'est pas correctement affiché dans le menu au redémarrage de hfs (name par défaut) déjà signalé dans un autre post si ma mémoire est bonne.

Manque une ligne dans main.pas

name1.Checked:= TRUE;
time1.Checked:= defSorting='time';
size1.checked:= defSorting='size';
hits1.Checked:= defSorting='hits';
Extension1.Checked:= defSorting='ext';
Title: Re: Macros
Post by: rejetto on December 30, 2007, 01:36:44 AM
1)
[special:begin]  existe déjà
[special:end]  en cours de fabrication

i changed my mind, and decided to make no [special:end].
i found it's easy to make the nbcount you need.
see this example:
after [file] put {{comment| {{count|ext.%item-ext%}} }}
Then, after the list you can put something like I saw {{count|ext.mp3}} mp3 files
Or you can store the value using {{set}}, as you wish.

Quote
2) une nécessité pour moi
deux macros dans le même ordre d'idée
{{special begin| ........}}  évaluée immediatement après la section [special:begin]
{{special end|.........}}  évaluée juste avant ou après l'appel à la section [special:end] (de préférence juste avant)

no, it's not possible to make it.

Quote
3)
une macro qui retourne certaines valeurs d'options en "true or false" ou une valeur correspondante
{{get option| A}}   retourne la valeur correspondante à A dans HFS.INI

ok

Quote
Manque une ligne dans main.pas

fixed thanks
Title: Re: Macros
Post by: FRENCH CAN CAN on December 30, 2007, 05:50:20 AM
Okay, I made some small correction.  :) ;)
Title: Re: Macros
Post by: Mars on December 31, 2007, 01:51:43 AM
Quote
see this example:
after [file] put {{comment| {{count|ext.%item-ext%}} }}
Then, after the list  you can put something like I saw {{count|ext.mp3}} mp3 files
Or you can store the value using {{set}}, as you wish.

after the list  mon problème est ici, je dois pouvoir utiliser la valeur finale de chaque {{count|ext.%item-ext%}} n'importe où dans le template, et spécialement dans la liste à un endroit quelconque
Title: Re: Macros
Post by: Foggy on January 02, 2008, 07:49:56 AM
I'm trying to append a SET macro to a file which will be called and executed later but it isn't working, I am using quote macros and it is being saved to the file but the quotes are being added too, so I can't then load the file into the template and execute the macro's in it.

eg
{{append|test.txt|{{\{{set|Title|Test Title}}/}}}}

Quote from: test.txt
{{\{{set|Title|Test Title}}/}}


I thought hfs stripped the quoting brace's and just left the text inside.
Title: Re: Macros
Post by: rejetto on January 02, 2008, 02:15:52 PM
ok mars, now it is clear what you want to do.

I see no way to create the macro you want, but you can just change algorithm.
Code: [Select]
For every file
  if lastFile has different first letter
    ^endsection
  inc counter
  add html to buffer

at the end of the list
  ^endsection

function endsection
  output buffer
  clear buffer
  reset counter

you can do all these things with existing macros.
For now "add html to buffer" can be done this way {{set|buffer|{{^buffer}}your html here}}

But in next build i will add a new macro to speed up, and it will be {{set append|buffer|your html here}}
Title: Re: Macros
Post by: rejetto on January 02, 2008, 02:21:22 PM
I thought hfs stripped the quoting brace's and just left the text inside.

there's no reason for HFS to strip such braces.
if it would be done everytime, it be like quoting never exists.
It is done in special cases.
Now, i could add {{append}} to such special cases, but maybe we can do in another way.
I will add a {{dequote}} macro, so when you want to execute your file, you can just
{{dequote|{{load|myfile.txt}} }}
Ok?
Title: Re: Macros
Post by: Foggy on January 03, 2008, 12:16:13 AM
{{dequote|{{load|myfile.txt}} }}
Ok?

That would work great,  ;)
Title: Re: Macros
Post by: Mars on January 03, 2008, 06:37:27 PM
Quote
I see no way to create the macro you want, but you can just change algorithm.

my solution: attached file

Il ne reste plus qu'à tester...


Title: Re: Macros
Post by: rejetto on January 03, 2008, 08:44:21 PM
ok mars, your solution is good. i created a macro "after the list". you are supposed to quote the body, to avoid its premature execution.
i'm not sure this macro will solve your problem. try and see. if it doesn't, there's my other solution.

In the while i wrote this little macro to create the header for every letter.
it is supposed to be placed after [item start]

{{set|first|{{upper|{{cut||1|%item-name%}}/upper}}/set}}
{{if| {{ {{^first}} != {{^last}} }} |
  {{\ {{set|last|{{^first}}}} <tr><td>{{^first}} /}}
/if}}
Title: Re: Macros
Post by: Mars on January 03, 2008, 09:51:04 PM
une autre idée me trotte dans la tête

can you update function inc() as this:

Quote
  procedure inc(v:integer=+1);
  begin
  if not satisfied(md.cd) then exit;
  try
  if not(md.cd.params.indexOf(p) >= 0) then md.cd.vars.values[p]:='0';
      result:='';
    with md.cd.vars do values[p]:=intToStr(strToInt(values[p])+v*parI(1,1))
  except end;
  end; // inc

Ainsi on pourra définir une variable à 0 par défaut (sans connaitre son nom à l'avance) simplement par un appel à INC ou DEC comme par exemple  {{inc|file.%item-ext%}}, car je ne peux prédire à l'avance quelles EXT seront utilisées dans %files%
et éviter d'utiliser   la combinaison {{set|count|{{count|file.%item-ext%}} /set}}  {{^count}}

mais plutôt  {{inc|file.%item-ext%}} et {{^file.%item-ext%}}

tout comme avec %sequential% il n'y a pas %number-sequential%
ainsi avec {{count|....}} il manque l'équivalent de {{special end|{{^count|....}}}}

donc au lieu d'avoir

{{set |myvar|0}}    .....   {{inc/dec|myvar|n}} ...  {{^myvar}} = n

alors
 {{inc|myvar|n}} ...  {{^myvar}} = n

serait équivalent et suffisant.



Title: Re: Macros
Post by: Foggy on January 04, 2008, 05:17:22 AM
DIV only works when dividing a number that has 9 or less digit's.

eg
{{div|999999999|1024}} returns 976562

but

{{div|9999999999|1024}} returns 0
Title: Re: Macros
Post by: Mars on January 04, 2008, 08:04:57 AM
limit is {{div|2147483647|1024}}

 
Quote
Min longint value = -2147483648
 Max longint value = 2147483647

rejetto must change storage to

Quote
Min int64  value = -9223372036854775808
 Max int64 value = 9223372036854775807

Quote
function parI(idx:int64; def:int64=0):int64;
  begin result:=strToIntDef(par(idx), def) end;

and more if necessary 




Title: Re: Macros
Post by: rejetto on January 04, 2008, 12:39:23 PM
64bit integers supported

inc now works with non-numeric vars. they will be considered zero.
Title: Re: Macros
Post by: Foggy on January 04, 2008, 01:31:47 PM
Quote from: Wiki
All macros, except quoted ones, are expanded. Even if you use the macro if|A|B|C, independently by the value of A, both B and C are expanded. If A is true, C is discarded, and vice versa. This is an important point, because if you was using append inside C, the file will be written anyway.

After reading this I thought, why not have the if macro automatically apply quotes and then unquote the correct parameter.
Title: Re: Macros
Post by: rejetto on January 04, 2008, 01:42:42 PM
Because execution of macros is done when the parser already finished its work.
The parser have no knowledge of the macros, just handles parenthesis.

Another point is: you do {{append|file|{{another macro}} }}
How can HFS know that you want to execute another macro now or later ?
Think it works with url parameters. You may want to work with current parameters, or the parameters of the time you will load the file. Only you know.
And you will choose between behaviour 1 or 2 by quoting or not.
Title: Re: Macros
Post by: Mars on January 04, 2008, 02:01:45 PM
It is the same difference when you define

{{set|myvar|{{cut|1|8|It is the same difference}} /set}}

and

{{set|mymacro| {{\ {{cut|1|$1|$2}}  /}}  /set}}

if you use

{{append|file|{{another macro}} }}

{{another macro}} is immediatly evaluated and result is stored in file

but with

{{append|file| {{\ {{another macro}} /}}  }}

it is  {{another macro}} who is stored in file

and when you include this file in your template {{load|file}}, it is here that the macro {{another macro}} is evaluated.
Title: Re: Macros
Post by: Foggy on January 04, 2008, 02:23:54 PM
{{append|file| {{\ {{another macro}} /}}  }}

it is  {{another macro}} who is stored in file

and when you include this file in your template {{load|file}}, it is here that the macro {{another macro}} is evaluated.


When I tested this the quotes were added to the file as well, so in this case it would be {{\{{another macro}}/}}.
Title: Re: Macros
Post by: Mars on January 04, 2008, 02:42:44 PM
foggy i make test with


{{set|myvar|{{\{{\{{another macro}}/}}/}}}}
{{append| c:\file.txt|{{^myvar}}}}


see result on your template ;D ;D ;D
Title: Re: Macros
Post by: Foggy on January 04, 2008, 02:50:44 PM
Im about to goto bed so I'll test in the morning, but that looks like it will work :P

I'll use that in the mean time but I think It would be more simpler in the long run to just use dequote as rejetto suggested.
Title: Re: Macros
Post by: Foggy on January 05, 2008, 01:19:41 AM
It works, but the problem is I'm trying to include a urlvar in the macro that is being written to file, so to create some dynamic content.

This is what I get in the file
{{set|Title|{{?title}}}}

I need to be able to evaluate the urlvar before it is written to file.
Title: Re: Macros
Post by: Mars on January 05, 2008, 01:30:23 AM
missing more code to evaluate where is your pb

by sample
{{set|myvar|{{\{{\{{another macro}}/}}/}}}}
{{append| c:\file.txt|{{^myvar}}}}

is full to work
Title: Re: Macros
Post by: Foggy on January 05, 2008, 02:44:29 AM
where is your pb

pb ???

this is the code I tried, it works but the urlvar isn't evaluated before being written to file but I don't think there is a way around that.

{{set|data|{{\{{\{{set|Title|{{?title}}}}/}}/}}}}
{{append|{{?name}}.txt|{{^data}}}}

I think I'll have to go back to my first idea of creating a strings table and loading that instead.
Title: Re: Macros
Post by: rejetto on January 05, 2008, 04:33:19 PM
does this work?

{{set|data|{{replace|$1|{{?title}}|{{\{{\{{set|Title|$1}}/}}/}}/replace}}}}
{{append|{{?name}}.txt|{{^data}}}}
Title: Re: Macros
Post by: Mars on January 05, 2008, 04:37:20 PM
note pour rejetto

{{\ ..... /}}  ok

{{\{{\ ..... /}}/}}  can be replaced by an alias as  {{\\..... //}}
{{\{{\{{\ ..... /}}/}}/}}  can be replaced by an alias as  {{\\\..... ///}}

update to do this
Quote
function dequote(s:string):string;
  begin
  if ansiStartsStr(MARKER_QUOTE+'\', s) and ansiEndsStr('/'+MARKER_UNQUOTE, s) then
     begin
        delete(s,length(s)-length(MARKER_UNQUOTE),1);
        delete(s,length(MARKER_QUOTE)+1,1);
        result:=s;
     end
  else if ansiStartsStr(MARKER_QUOTE, s) and ansiEndsStr(MARKER_UNQUOTE, s) then
    result:=copy(s, length(MARKER_QUOTE)+1, length(s)-length(MARKER_QUOTE)-length(MARKER_UNQUOTE) )
  else
    result:=s
  end; // dequote

 chaque  {{\\\ ..... ///}} est remplacé par {{\\..... //}} qui est de nouveau remplacé par {{\ ..... /}} à chaque appel de dequote()
Title: Re: Macros
Post by: rejetto on January 05, 2008, 04:42:07 PM
I think this won't happen often, and it will be max 2 nested quotings.
We'll see...
Title: Re: Macros
Post by: Mars on January 06, 2008, 12:47:17 AM
serious problem with macro order

un bien singulier template:

Quote
<head>
</head>
<body>
{{set |counter|hello}}
<p>
First: {{^counter}}
{{set |counter|Youpi}}
<p>
{{set|itemmax| -25}}
Macro After the list:  {{^itemmax}} ** {{after the list| {{^counter}}  ** {{^itemmax}} }}

    %list%
<p>
End of list: {{^counter}} ** {{^itemmax}}

</body>
</html>

[file=folder=link]
{{set|counter| {{count}} }}
{{set|itemmax| {{^counter}} }}
<p>item {{^counter}}

Html result
Quote
<head>
</head>
<body>
<p>
First: hello
<p>
Macro After the list:  -25 ** Youpi  ** -25
<p>item 0
<p>item 1
<p>item 2
<p>item 3
<p>item 4
<p>item 5
<p>item 6
<p>item 7
<p>item 8
<p>
End of list: Youpi ** -25
</body>
</html>

quelque part, l'ordre d'évaluation n'est pas respecté
Title: Re: Macros
Post by: Foggy on January 06, 2008, 01:58:04 AM
does this work?

{{set|data|{{replace|$1|{{?title}}|{{\{{\{{set|Title|$1}}/}}/}}/replace}}}}
{{append|{{?name}}.txt|{{^data}}}}

no :(
It was a good idea but the text file was empty, is it possible that the replace macro is dropping the quoted text?

edit:The way you suggested rejetto gave me an idea to try using set with parameters instead of replace, and it worked even better then I was hoping by outputing the macro with any quotes at all.

{{set|data|{{\{{\{{set|Title|$1}}/}}/}}}}
{{append|{{?name}}.txt|{{^data|{{?title}}}}}}

returned

{{set|Title|food}}
Title: Re: Macros
Post by: Foggy on January 06, 2008, 12:39:12 PM
we have the append macro but to accompany it, is it possible to have a macro that could remove text from a file?

or have a macro to delete a file?

or one to overwrite the file, and then you could use replace to replace what you don't want with nothing.
Title: Re: Macros
Post by: rejetto on January 06, 2008, 03:15:27 PM
serious problem with macro order

{{after the list}} needs macro quoting.

or one to overwrite the file, and then you could use replace to replace what you don't want with nothing.

ok, {{save}}
Title: Re: Macros
Post by: rejetto on January 06, 2008, 03:37:38 PM
It was a good idea but the text file was empty, is it possible that the replace macro is dropping the quoted text?

to solve dramas such this, i created a log for the macros, so we'll be able to see how they are executed.
This option won't be saved. It is meant that you use it rarely and for a short time.
Title: Re: Macros
Post by: Foggy on January 06, 2008, 04:15:11 PM
It was a good idea but the text file was empty, is it possible that the replace macro is dropping the quoted text?

to solve dramas such this, i created a log for the macros, so we'll be able to see how they are executed.
This option won't be saved. It is meant that you use it rarely and for a short time.

ok, that could be quite useful. The error message we get down the bottom of the main hfs window has also been very useful.
Title: Re: Macros
Post by: Mars on January 10, 2008, 07:24:41 PM
i don't know if it is possible to rejetto to create a lot of macros 

{{length line|#line|source}}  return the number of caracters (exept #10#13) of the line #line from source

{{count lines|source}}  return number of begining of lines in source (NOT number of #10#13)  if source is empty this macro return 0, if the last line is 'abcde'  then it is a valid line.

{{trim lines|source}} works as {{trim|source}} but it remove empty lines at END and BEGIN of source

usage by example  {{trim lines| {{section|mysection}} }}

sometime I use empty line to separate sections in my template.

{{cut lines|begin_line|end_line|source}}

begin_line and end_line can be negativ values

usage by example {{cut line|1|{{sub|{{length line|source.txt}}|x}}|source.txt}}

missing to macro {{for|}} a macro named {{exit for}}

usage by example 
{{for|x|1|{{count lines|source}}|{{if|{{length line|{{^x}}|source}}>63|{{exit for}}|Line {{^x}} is <64 /if}} /for}}



modification to accept {{?urlvar|defaultvalue}}

application {{get|url|sort={{?sort|n}}|rev={{?rev|1}} }}
ceci n'est qu'un exemple non restrictif

Quote
<form name=frm>
Name <input id=login name=name value="{{?name|%user%}}">
<p>Text <input id=text name=text>
<p><input type=submit>
</form>
<script>document.frm.text.focus();</script>
<a href="{{get|url|text=}}">REFRESH</a>
Title: Re: Macros delete and rename file
Post by: Mars on January 11, 2008, 12:27:33 PM
{{append | path+file | texte }}

{{save | path+file | text }}

{{delete | path+file }}

{{rename | path+file | newname }}

can you create the two last macros, rejetto?
Title: Re: Macros
Post by: rejetto on January 13, 2008, 08:51:04 PM
Ok for delete and rename.

i don't know if it is possible to rejetto to create a lot of macros 

don't ask if it is possible.
ask if it is convenient/suitable.

Quote
{{length line|#line|source}}  return the number of caracters (exept #10#13) of the line #line from source

what you will use it for?

Quote
{{count lines|source}}  return number of begining of lines in source (NOT number of #10#13)  if source is empty this macro return 0, if the last line is 'abcde'  then it is a valid line.

in standard text files the number of lines IS the number of #13#10. I remember having read it on wikipedia (http://en.wikipedia.org/wiki/Newline).
indeed my Pspad editor does this way.
Microsoft Notepad does not ::)

Consider we shouldn't make macros for EVERY need. For some specific purposes you can use javascript. It works. Macros are meant for making common things with no javascript.

Quote
{{trim lines|source}} works as {{trim|source}} but it remove empty lines at END and BEGIN of source

trim already do remove empty lines. try before asking ;)

Quote
missing to macro {{for|}} a macro named {{exit for}}

at the moment it can't be done, because {{for}} was implemented as a sort of {{repeat}}.

Quote
modification to accept {{?urlvar|defaultvalue}}
application {{get|url|sort={{?sort|n}}|rev={{?rev|1}} }}
ceci n'est qu'un exemple non restrictif

use {{or|{{?sort}}|n}}
Title: macro FOR for beginners
Post by: Mars on January 13, 2008, 10:48:11 PM
If we want to make a thing in the style

{{for|A|2|10|2|{{for|B|1|5|2|{{^A}}+{{^B}}={{ADD|{{^A}}|{{^B}} }}<p> /for}} /for}}<p>{{^A}}+{{^B}}

The result is not the one that we can hope
0
+=0
+=0
+=0
+=0
+=0
+=0
+=0
+=0
+=0
+=0
+=0
+=0
+=0
+=0
10+5


You must correct it by insert some {{\ and /}} as

{{for|A|2|10|2|{{\ {{for|B|1|5|2|{{\{{^A}}+{{^B}}={{ADD|{{^A}}|{{^B}} }}<p>/}} /for}} /}} /for}}<p>{{^A}}+{{^B}}

and all will be correct after
2+1=3
2+3=5
2+5=7
4+1=5
4+3=7
4+5=9
6+1=7
6+3=9
6+5=11
8+1=9
8+3=11
8+5=13
10+1=11
10+3=13
10+5=15
10+5


Title: Re: Macros
Post by: Mars on January 14, 2008, 12:22:18 AM
{{length line|#line|source}}

{{count lines|source}}

{{cut lines|begin_line|end_line|source}}


Do not forget that source can be the contents of an external file

Quote
Consider we shouldn't make macros for EVERY need. For some specific purposes you can use javascript. It works. Macros are meant for making common things with no javascript.

I am not completely the same opinion, the macro are there to be executed at the level of the server, and so that certain actions which are possible with javascript, they are not seen by the user.

We can mask certain items in mode page as I made it, but by showing the code all the information is present.
With javascript I can simulate  restrict account on directories but it is simpler when HFS makes it, and in more the quantity of information transfer is lesser.

Title: Re: Macros
Post by: rejetto on January 14, 2008, 12:27:41 AM
{{length line|#line|source}}
{{count lines|source}}
{{cut lines|begin_line|end_line|source}}
Do not forget that source can be the contents of an external file

yes, i guessed so. Can you tell me what's your purpose with such macros?

Quote
I am not completely the same opinion,

i'm sorry, but i won't spend years building a complete language. It makes NO sense. I already said it before. When HFS will support CGI, people interested in a full language will install PHP, Perl, anything.
Title: Re: Macros
Post by: Mars on January 14, 2008, 12:35:02 AM
Quote
When HFS will support CGI, people interested in a full language will install PHP, Perl, anything.

 ;D I know, but it is not before 2010, and by waiting , what can we do?? To colour in our templates.... ;D ;D ;D
Title: Re: Macros
Post by: ebola on January 14, 2008, 10:56:40 AM
Hi

What about a macro that makes hfs execute an executable/bat?

I'm thinking of:
1. Upload ok => call external program generating and save MD5/SHA256 to file => get the MD5 from there and add it to file-comment to verify
2. Upload ok => call AntiVius and check file => if AV return = 0 => Add file to UL-folder if not inform User it's infected


Cheers,
ebola
Title: Re: Macros
Post by: Foggy on January 14, 2008, 11:29:31 AM
they are some good ideas, I especially like the anti virus example. md5 I think can already be automatically generated, have a look inside the fingerprints menu.
Title: Re: Macros
Post by: Foggy on January 14, 2008, 02:16:24 PM
to go with append, a macro to write at the beginning of a file could be quite useful. I know I would use such a macro so that I can load the file and execute and/or list the data in a certain order. I think the correct term for it is prepend.
Title: Re: Macros
Post by: rejetto on January 14, 2008, 02:41:45 PM
instead of writing to file, prepend in a variable. {{set|x|here{{^x}}}}
at the end of it all, you'll save the variable in a file.
Title: Re: Macros
Post by: Mars on January 14, 2008, 04:20:01 PM
{{save | file.txt|YOUR MESSAGE <br>{{load | chat.txt}} /save}}

to add at beginning of file

{{if|{{filesize | file.txt}}>lengthmax}}|
  {{save | file.txt|{{cut||maxfile|{{load | file.txt}} }} /save}}

to cut file if he is too long

it is what i use in chat.tpl
Title: Re: Macros
Post by: rejetto on January 15, 2008, 06:07:59 AM
What about a macro that makes hfs execute an executable/bat?

i will think on it
Title: Re: Macros
Post by: Foggy on January 18, 2008, 03:49:25 AM
This one is probably a big ask, but are arrays possible?
Title: Re: Macros
Post by: rejetto on January 18, 2008, 03:50:57 AM
talk about your needs. how would you use it?
Title: Re: Macros
Post by: Foggy on January 18, 2008, 04:12:01 AM
currently I am writing to a file a list, that is then parsed each time the page is loaded to get the most recent 25 entries and then 25 more in for each page.

problem is as you go further into the pages, the load on the server is greater because to find the items for that page I have to start start from the start of the list and loop through X times to eliminate the pages before the current one.

basically it would be eliminating this macro, because with an array I can just use a for loop directly on the values I am after. {{if|{{or|{{{{?p}}=1}}|{{not|{{?p}}}}}}||{{\{{for|B|1|{{sub|{{mul|{{^topic-limit}}|{{?p}}}}|25}}|{{\{{set|topic-order|{{cut|{{add|{{length|{{substring||;|{{^topic-order}}}}}}|2}}||{{^topic-order}}}}}}/}}/for}}/}}/if}}

the list is written like 1;2;3;4;5;... etc

on a side note I first tried that macro using if not but it had trouble with the quoting of the commands to execute.

I hope that made sense  :P
Title: Re: Macros
Post by: rejetto on January 18, 2008, 05:02:18 AM
Next beta will be able to correctly run
Code: [Select]
{{random{{for|x|1|10|{{\|{{^x}}/}}/for}}/random}}
that is: a nestd macro will be able to expand to multiple parameters for the outer macro.
currently you are limited to just 1.
Title: Re: Macros
Post by: TSG on January 18, 2008, 07:25:30 AM
I have 2 bugs.

1. Macro sections are giving me a line break again all of a sudden. Which breaks the code in places. (it happens on a sub page) the root is fine.

2. The load macro doesn't seem to work with a path... I need it to work with a path for my language files :)
Title: Re: Macros
Post by: rejetto on January 18, 2008, 07:52:53 AM
1. i made a test and it works just as #171. can you provide a way to reproduce it?

2. i made a test and it worked with path\file with ..\path\file and with \path\file
double check
Title: Re: Macros
Post by: TSG on January 18, 2008, 07:56:34 AM
1. Yes, it happens on every sub directory for me... i've tested 172 and now 174. I go into sub directory and the macro gives a line break after the text.

2. I have this and it does nothing... {{load|..\template\rawr_default\languages\en_au.txt}}
Title: Re: Macros
Post by: rejetto on January 18, 2008, 08:00:23 AM
1. i'm asking you to provide an example in form of template code. the smaller is the code, the better.

2. that is a relative path. relative paths are based on the HFS folder. is "template" folder right outside the folder you are running hfs.exe ?
Title: Re: Macros
Post by: TSG on January 18, 2008, 08:08:19 AM
The template folder is next to hfs.exe and {{load isnt even appearing in the macro.log.
[special:strings]
{{load|template/rawr_default/languages/en_au.txt}} < the macro doesnt even appear in the log, even when i put the load part into a section.


and for the first thing an example would be.

var theme="{{$theme}}"

In root directory:
var theme="rawr_blue";

In sub directories:
var theme="rawr_blue
";

The sections where working fine everywhere until today... i was using 172 till a few mins ago.
Title: Re: Macros
Post by: rejetto on January 18, 2008, 08:32:37 AM
1. I just tested with #174
this was the test template
Code: [Select]
[theme]
hey
[]
"{{$theme}}"

then accessed / and it printed "hey"
then accessed /new%20folder/ and it printed "hey"

2. since load is never executed, it is not a bug in {{load}}
Indeed special:strings is considered simple text and macros are never executed.
I see 2 solutions, to be weighed:
a) to run macros in special:strings
b) to make HFS use variable {{^special:string}} (that you can load with the file), and if it's empty, use [special:strings]
Title: Re: Macros
Post by: Foggy on January 18, 2008, 08:35:49 AM
I would leave special:strings how it is so you can use a strings table without an external file, but if using an external file I would use 'from table' instead.
Title: Re: Macros
Post by: rejetto on January 18, 2008, 08:44:28 AM
{{!}} is a special case of {{from table}}
but for localization we need to use ! because it's much shorter.
with fro, table you have to specify the name of the table also. every time.
Title: Re: Macros
Post by: TSG on January 18, 2008, 09:22:35 AM
I figured it out! The break is coming from the Diff Template value of [theme], so sections in Diff Template have a break after them!

The {{load}} macro i am still working with... I think we need the ability to fire a macro in [special:strings], cause even if u wanted to import some strings from another section, you need to fire {{$section}}.
Title: Re: Macros
Post by: rejetto on January 20, 2008, 05:29:01 PM
I figured it out! The break is coming from the Diff Template value of [theme], so sections in Diff Template have a break after them!

this means it is not a bug. Right?

Quote
The {{load}} macro i am still working with... I think we need the ability to fire a macro in [special:strings], cause even if u wanted to import some strings from another section, you need to fire {{$section}}.

from next beta, try using {{load|yourfile|special:string}}
this will load the file in {{^special:string}} that is a variable, not the section.
That's because {{!asd}} will search asd in several places, in this order:
in variable special:strings
in section special:strings
in the optional parameter
and if it is not found anyhwere, "asd" itself is returned
Title: Re: Macros
Post by: TSG on January 20, 2008, 05:52:21 PM
I figured it out! The break is coming from the Diff Template value of [theme], so sections in Diff Template have a break after them!

this means it is not a bug. Right?

No it means it IS a bug, the main template doesnt have breaks after sections, why should it be different for Diff template?

I will try this method when next build is released.
Title: Re: Macros
Post by: Mars on January 20, 2008, 10:14:54 PM
Quote
from next beta, try using {{load|yourfile|special:string}}
this will load the file in {{^special:string}} that is a variable, not the section.

one question

when using {{load|yourfirstfile|special:string}} before {{load|yoursecondfile|special:string}}

Is yoursecondfile append to {{!special:string}} or rewrite over {{!special:string}} ?

an option can be added
{{load|yourfile|special:string|sectionname}}

by example in yourfile are some sections

[special:strings]
mytext=english

[special:stings_fr]
mytext=français

[special:stings_it]
mytext=Italiano

using {{load|yourfile|special:strings|special:strings_fr}} load only content of section [special:strings_fr] from yourfile,  or [special:strings] if par[3] is not specified

2e question

{{load|yourfile|special:string}}  i think that only section [special:strings] into yourfile must be include, not all content of the file

It is to offers more possibility to load with same syntax others sections as [special:begin] included in variable {{!special:begin}}
{{load|yourfile|special:begin}}
That's because {{!asd}} will search asd in several places, in this order:
in section special:begin       {{set|myvar|text}}
in variable special:begin       {{set|myvar|Overloaded Text }}  can replace text defined above for a specific usage
(dans cet ordre pour une possible possible surcharge  des définitions de variables ou macros)
{{load|yourfile|special:begin|sectionname}}
it is possible with some restriction

Title: Macro: FROM TABLE
Post by: Mars on January 20, 2008, 10:36:08 PM
{{FROM TABLE|...}
how to use it?? ??

désolé si je suis passé à coté de la réponse dans un autre post

Title: Re: Macro: FROM TABLE
Post by: Foggy on January 21, 2008, 02:00:55 AM
{{FROM TABLE|...}
how to use it?? ??

{{from table|table/variable|string id}}
Title: Re: Macros
Post by: Mars on January 21, 2008, 08:10:54 AM

Quote
{from table|table/variable|string id}}

A concrete example would be welcome
Title: Re: Macros
Post by: Foggy on January 21, 2008, 09:00:10 AM
{{set|example|
foo=this is an example
foo2=this is another example
/set}}

{{from table|example|foo}} will return "this is an example"

{{from table|example|foo2}} will return "this is another example"
Title: Re: Macros
Post by: rejetto on January 22, 2008, 06:57:00 AM
when using {{load|yourfirstfile|special:string}} before {{load|yoursecondfile|special:string}}
Is yoursecondfile append to {{!special:string}} or rewrite over {{!special:string}} ?

it's overwritten

Quote
an option can be added
{{load|yourfile|special:string|sectionname}}

yes, but you can already do it using {{set|special:string|{{$sectionname|yourfile}}/set}}
We'll do it if we see any need of it.

Quote
2e question
{{load|yourfile|special:string}}  i think that only section [special:strings] into yourfile must be include, not all content of the file

ditto. you can already do it.
Title: Re: Macros
Post by: rejetto on January 22, 2008, 07:28:50 AM
No it means it IS a bug, the main template doesnt have breaks after sections, why should it be different for Diff template?
I will try this method when next build is released.

found the bug and fixed :)
the problem were not diff templates, but just "the last section of any template"
Title: Re: Macros
Post by: Mars on January 22, 2008, 08:42:34 AM
Quote
Quote from: mars on 20 January 2008, 23:14:54
when using {{load|yourfirstfile|special:string}} before {{load|yoursecondfile|special:string}}
Is yoursecondfile append to {{!special:string}} or rewrite over {{!special:string}} ?


it's overwritten


Quote
an option can be added
{{load|yourfile|special:string|sectionname}}


yes, but you can already do it using {{set|special:string|{{$sectionname|yourfile}}/set}}
We'll do it if we see any need of it.

Rejetto ,You forgot to clarify  ;)
Quote
from next beta, try using {{load|yourfile|special:string}}
this will load the file in {{^special:string}} that is a variable, not the section.
That's because {{!asd}} will search asd in several places, in this order:
in variable special:strings
in section special:strings
in the optional parameter
and if it is not found anyhwere, "asd" itself is returned
{{set|special:string|{{$sectionname|yourfile}}/set}}
{{set append|special:string|{{$sectionname|yoursecondfile}}/set}}

It completes your two answers

Title: A New Macro is ready to be used
Post by: Mars on January 29, 2008, 01:04:23 AM
for each | A | B1 | B2 | B3 | .....| Bn | C  

repeats C by replacing variable {{^A}} with every value from B1 to  Bn  (n>=1)

i have create this macro by example to replace more than one substring in a string
Quote

{{for each| A | 5 | 2 | 3 | 8 | 6 | 1 | 0 | {{\  &nbsp;({{^A}})&nbsp;/ /}} }}

result is  (5) /  (2) /  (3) /  (8) /  (6) /  (1) /  (0) /  



code source pour HFS
Quote
if pars.count < 3 then exit; // from here, only macros with at least 3 parameters

 if name ='for each' then
    foreach();

.........

 procedure foreach();
  var
    j, n : integer;
    theVar, code: string;
  begin
  try
    j:=max(1,pars.count-2);
    code:=par(pars.count-1);
    if code=''then exit;
    code:=dequote(code);
    theVar:=format('{{^%s}}',[p]);
    with TfastStringAppend.create do
      try
        for n:= 1 to j do
          begin
          append(xtpl(code, [theVar, par(n)]));
          end;
        result:=reset();
      finally free end;
    if assigned(md.cd) then
      md.cd.vars.values[p]:=intToStr(j);
  except end;
  end; // foreach

Title: Re: Macro REPLACE extended
Post by: Mars on January 29, 2008, 08:38:57 AM
replace | A1 | B1 | A2 | A2 | B2 | ....... | An | Bn | C  

returns C with every Ax replaced with Bx

code source pour HFS
Quote
  if name = 'replace' then
    replace();
.....
  procedure replace();
  var
    i: integer;
  begin
    p:=par(pars.Count -1);
    i:=0;
    while (i < pars.count-1) and not (i = pars.count-2) do
      begin
      p:=xtpl(p, [par(i), par(i+1)]);
      inc(i,2);
      end;
    result:=p;
  end; // replace


{{replace| 2|two | 3|three | 4|four | 7|seven | 9|nine | 0 1 2 3 4 5 6 7 8 9}}
{{replace| 2|two | 3|three | 4|four | 7|seven | 9|nine | 0| 0 1 2 3 4 5 6 7 8 9}}

result is 0 1 two three four 5 6 seven 8 nine
Title: Re: Macros
Post by: bacter on January 29, 2008, 11:40:06 PM
I'am still having problems with localization.

In the maintemplate i have
Quote
[special:begin]
{{load|bts_init.tpl}} {{comment|global vars, origin of request,force browserlang to availablelang(+selectedlang)->userlang}}
{{load|btslang_{{^userlang}}.tpl|special:string}}
[special:strings]
lfile=Languagefile in template
lfmodif=20080128
....

With build #177 this should work, but {{!lfile}} etc. return the values from [special:strings] and not from the vars loaded into 'special:string' from the file. ¿What am I doing wrong to get it working?
Title: Re: Macros
Post by: Mars on January 29, 2008, 11:45:02 PM
{{load|btslang_{{^userlang}}.tpl|special:string}}


modify to {{load|btslang_{{^userlang}}.tpl|special:strings}}
Title: Re: Macros
Post by: TSG on January 30, 2008, 03:54:59 AM
Might only be a bug in 178beta but i cant get the strings to go to all the other pages in the template. It only works for the main section of it.

This is my macro. The contents of the file works fine if i paste it in the tpl, but the load macro should work for localisation to be complete.
(i think in my version the load macro can use URI's for links so that isn't the bug)

[special:begin]
{{load|/template/rawr_default/languages/en.txt|special:strings}}
Title: Re: Macros
Post by: Foggy on January 30, 2008, 05:40:17 AM
are the other pages user defined sections? if so, try placing {{$special:begin}} at the top of the section.
Title: Re: Macros
Post by: TSG on January 30, 2008, 05:56:13 AM
Thanks that works, but I think assigning the load to special:strings should also make it a global var.
Title: Re: Macros
Post by: rejetto on January 30, 2008, 07:00:34 PM
ok, added
i hope you truly need these macros, because we must add only the macros we use
Title: Re: Macros
Post by: Foggy on January 31, 2008, 06:25:12 AM
when I use {{?var}} is it possible that if there isn't a url variable with that name that it then checks for a postvar with that name.
Title: Re: Macros
Post by: rejetto on January 31, 2008, 11:59:11 AM
i don't know if it would be a good idea.
for sure i can make a {{urlpostvar}} macro.
otherwise we can discuss having ? as urlpostvar, and not as alias of urlvar.
Title: Re: Macros
Post by: Mars on February 24, 2008, 10:06:43 PM
As there is not much again at the moment, it will be just small craftiness to put something itself under the tooth


when you find in your template

{{if|{{%bread-name%=}}|Home|%bread-name%}}

You can replace it by

{{or|%bread-name%|Home}}

Reminder: the macro {{OR|...}} sends back the first non-empty parameter

Title: Re: Macros
Post by: TSG on February 25, 2008, 09:40:16 AM
RAWR-Template already uses this and rejetto gave me that code :P guess he forgot to update his own.

The default template needs a fair bit of work, I could make it w3c web standard and better written within a nights work. It is quite bad at the moment. It uses xhtml yet doesn't follow many of the xhtml rules :P

{{breadcrumbs|{{\<a href="%bread-url%">{{or|%bread-name%|{{!lv_home}}}}/</a>/}}}}

Macro suggestion, {{encodeURI| }} {{decodeURI|}} {{escape|}} {{unescape|}}. I thought they were already suggested/implemented but they arent. Possible uses include encoding certain strings for use with flash applets, or just simply doing what the uses for these are in javascript/actionscript etc.

Lastly, is there a way to detect odd and even numbers, or a macro that could do such a job? I am interested to do this to implement alternate row colour into RAWR-Template.
Title: Re: Macros
Post by: rejetto on February 25, 2008, 10:53:23 PM
by using {{or}} for such purpose, it will consider "empty" folders with name "0" and "false".

{{mod|%number%|2}} will tell you if a number is odd. even with a {{not}}
Title: Re: Macros
Post by: rejetto on February 26, 2008, 12:01:55 AM
Macro suggestion, {{encodeURI| }} {{decodeURI|}} {{escape|}} {{unescape|}}.

could you please specify what they are supposed to do?
you can point me to an equivalent javascript function, if any.
Title: Re: Macros
Post by: TSG on February 26, 2008, 06:39:58 AM
ok,

http://www.w3schools.com/jsref/jsref_encodeURI.asp
http://www.w3schools.com/jsref/jsref_escape.asp

I use them alot but this explains it nicely.

And I do not know if it is possible... But it would be awesome to have one that converts special characters to their ascii or hex equivalent.
&nbsp; &amp; etc. But i don't think there is a defined function for it.
Title: Re: Macros
Post by: Mars on February 27, 2008, 09:50:41 AM
by waiting

{{set|encodeURI| {{\ replace | < | %3C | >| %3E | { | %7B | [ | %5B | ] | %5D| } | %7D | ....|$1}} /}} }}
{{set|decodeURI| {{\ replace | %3C | < | %3E| > | %7B| { | %5B  | [ | %5D| ] | %7D| }  | ....|$1}} /}} }}


{{^encodeURI | text }}
Title: Re: Macros
Post by: Andrew-Sirius on March 06, 2008, 11:01:16 AM
Hi!

How it is possible with the aid of the macro to verify the presence of file in the folder?
For example about.html

And if file is present, then carry out one action, but if it does not exist, then carry out another action.
Title: Re: Macros
Post by: TSG on March 06, 2008, 11:08:29 AM
The below macro is from my templates. filesize only works with system directories, not with URL, so to do what you ask I am unsure. Unless it is a real folder of course. Then just put the name of the file in the if NAME.

{.if|{.filesize|%folder-resource%\NAME.}
  |DO THIS
  |DO THIS
.}
Title: Re: Macros
Post by: rejetto on March 06, 2008, 11:21:32 AM
it will support URIs in next beta
Title: Re: Macros
Post by: Andrew-Sirius on March 06, 2008, 12:53:28 PM
The below macro is from my templates. filesize only works with system directories, not with URL, so to do what you ask I am unsure. Unless it is a real folder of course. Then just put the name of the file in the if NAME.

{.if|{.filesize|%folder-resource%\NAME.}
  |DO THIS
  |DO THIS
.}

Thanks! Now everything works! I'm so happy!!!
Title: Re: Macros
Post by: Mars on March 06, 2008, 01:40:27 PM
Quote
{.if|{.filesize|%folder-resource%\NAME.}
  |DO THIS
  |DO THIS
.}


it will support URIs in next beta

Useful idea, but you should not forget that to know the   URL-file size it is necessary to load him, what can be long with some GBytes and only for detecter its existence,
A solution would be a macro {.file exist | URLNAME.} or  {. get |can download| URLNAME.}
Title: Re: Macros
Post by: rejetto on March 06, 2008, 02:02:45 PM
no.
local URIs are just converted to local file paths.
URLs instead are a way slower of course, but it doesn't depend on the size of the file, it's just a request for information to the server.
Title: Re: Macros : one new macro
Post by: Mars on March 06, 2008, 04:21:57 PM
From a post of TSG
Quote
REQUIRES HFS BETA 183 or RECENT BUILD - http://www.rejetto.com/forum/index.php?board=33.0

I propose a macro short story whoever warned the administrator the used template requires a minimal version of hfs

{.min build|183.}

Code: [Select]
  if (name ='min build') then
    if addressmatch('127.0.0.1',md.cd.conn.address) then
       msgdlg('This template requires at least the build version '+p+' of hfs to work completely')
    else result:='';

Title: Re: Macros
Post by: Andrew-Sirius on March 06, 2008, 04:56:34 PM
Useful idea, but you should not forget that to know the   URL-file size it is necessary to load him, what can be long with some GBytes and only for detecter its existence,
A solution would be a macro {.file exist | URLNAME.} or  {. get |can download| URLNAME.}

No, it does not work. Nevertheless, the file, which is checked, must load
Title: Re: Macros
Post by: rejetto on March 06, 2008, 09:53:20 PM
I propose a macro short story whoever warned the administrator the used template requires a minimal version of hfs

you can already solve the problem {.if|{.%build% < 183.}| warning .}
Title: Re: Macros
Post by: TSG on March 06, 2008, 10:45:10 PM
I propose a macro short story whoever warned the administrator the used template requires a minimal version of hfs

you can already solve the problem {.if|{.%build% < 183.}| warning .}

I do not include this on purpose, basically I want all users of my templates beta testing, therefore finding a lot more bugs and creating a better template engine. Look how far HFS has come in the last 12 months :D! I like to think I am somewhat helpful to HFS and its community.
Title: Re: Macros
Post by: rejetto on March 07, 2008, 12:51:48 AM
sure you are, but i didn't understand the reason why you don't do that
Title: Re: Macros
Post by: TSG on March 07, 2008, 05:09:17 AM
Its another thing to update when releasing.
Its an extra thing for HFS to think about when generating the template.
If I'm gonna start making errors I may as well make errors for everything.
If the template is fucked it is obvious to upgrade HFS as...
I state it in the readme that they must upgrade their HFS.
I state it under the download links.

I think that's enough reasons :D.
Title: Re: Macros
Post by: rejetto on March 07, 2008, 11:42:10 AM
all your templates have a minimum number for the required build.
if you forget to update that number (that you can keep in the configuration on top) that won't break anything.
if your tpl requires 183, but for an error you are checking for the 181, it won't be worst than it is now.
Title: Re: Macros
Post by: Mars on March 07, 2008, 11:49:24 AM
I was writting when rejetto post before me....

The utility of such an action is to prevent the recursive questions on the use of new macros, which would provoke inevitably some bugs on new template with old version of HFS

Of more the solution of rejetto imply a message on the utilisteur, while I propose an alert at the level of hfs, what adorned me more logical, instead of testing templates from every angle and allowing to pass an error


I have already tested the solution of rejetto but it did not seem to me sufficient(self-important), where from my proposition of macro with a message of alert at the level of the server
Title: Re: Macros
Post by: rejetto on March 07, 2008, 01:07:37 PM
a macro to issue a warning message would be more flexible
Title: Re: Macros
Post by: TSG on March 07, 2008, 03:59:32 PM
I would prefer an alert from HFS as they import the template. Maybe something in [special:import].

[special:import]

{.if|{.BUILD_VAR=183.}|HFS ALERT INFORMATION.}

{.add folder|real|template.}
{.set item|/template|hide.}
{.set item|/template|no log.}

This way they are warned instantly. Instead of later, where they may just trust our builds to be stable and forget about testing it.
Title: Re: Macros
Post by: rejetto on March 07, 2008, 04:48:06 PM
you could, with the macro i just told
Title: Re: Macros
Post by: Mars on March 07, 2008, 05:38:31 PM


my {.min build|183}  or   {.min build|183|alert-text.}  is a shortcut of

{.if|{.and|{.match|127.0.0.1|%ip%.}|{.%build%<183.}.}|alert-text.}

Code: [Select]
if (name ='min build') then
  begin
  result:=''; 
  if addressmatch('127.0.0.1',md.cd.conn.address) then
    if par(1)>'' then result:=par(1)
                 else msgdlg('This template requires at least the build version '+p+' of hfs to work completely');
  end;
Title: Re: Macros
Post by: rejetto on March 07, 2008, 05:40:19 PM
this is a feature used only once and only in few templates.
i don't think we need a shortcut.
Title: Re: Macros
Post by: bacter on March 07, 2008, 05:49:02 PM
is there a new bug in the for loop from build 179 to 183? or changed sintax?
loopvar seems to have always final value!

with build #179:
{{for|ii|1|8|{{\[{{^ii}}]/}}}}  works

output:  [1][2][3][4][5][6][7][8]

with build #183:
{.for|ii|1|8|{:[{.^ii.}]:}.} does not work

output: [8][8][8][8][8][8][8][8]

hfs or my error ?
Title: Re: Macros
Post by: rejetto on March 07, 2008, 05:54:20 PM
bug
fixed in next build
Title: Re: Macros
Post by: bacter on March 07, 2008, 06:01:49 PM
rejetto,  thanks for that fast reply
Title: Re: Macros
Post by: Mars on March 07, 2008, 08:21:19 PM
Quote
Insert Quote
bug
fixed in next build

macro FOR EACH has the same bug

I am happy , i found where was the bug :D

theVar:=format('{{^%s}}',[p]);    into functions: for_ () and foreach()

repaced by theVar:=format(MARKER_OPEN +'^%s'+MARKER_CLOSE,[p]);   
Title: Re: Macros
Post by: rejetto on March 07, 2008, 11:19:12 PM
yes, i fixed foreach as well
but i will wait to publish, to collect some more news
Title: Re: Macros
Post by: rejetto on March 07, 2008, 11:44:57 PM
macros' syntax just doesn't allow spaces before the name of the macro.
this is always true except for infix operators like {. 3 >  2 .}
Title: Re: Macros
Post by: rejetto on March 08, 2008, 12:05:56 AM
i didn't mean what the code does or not.
i meant what's the expected syntax, and what you can expect to be working correctly now and in the future.
the trim is there because spaces are allowed after the name.

anyway, at the moment there's no important reason for this rule, but i think we can ignore the problem of space^var.
Title: Re: Macros
Post by: Mars on March 08, 2008, 01:11:26 AM
I remove what I said,  'for i:=1 to -1 do msgdlg( inttostr(i));' is never executed in the delphi language

i am deleting all my post about this subject
Title: Re: Macros
Post by: bacter on March 08, 2008, 01:22:11 AM
Would it be possible to add a new simple macro {.hex|xx.} ?

This would be useful for me when working with plaintext files to detect or replace the linebreaks.

examples: (csv holds the whole text loaded}

{.count substring |{.hex|0d.}{.hex|0a.}|{.^csv.}.}   to count lines

or:

{.replace|{.hex|0d.}{.hex|0a.}|<br />|{.^csv.}.} to insert line breaks
Title: Re: Macros
Post by: rejetto on March 08, 2008, 01:44:14 AM
no sorry, that solution cannot be.

what i can do is to preserve spaces in {.replace.} and {.count substring.}
the problem is a feature: for the user's convenience macros ignore blanks.
some macros don't, because blanks can be useful, so i can just add these to the list.
i will if no one complains.

for readability you can
Code: [Select]
{.set|nl|{:
:}.}
and then use (in next build) {.replace|{.^nl.}|<br>|{.^csv.}.}
Title: Re: Macros
Post by: Andrew-Sirius on March 08, 2008, 10:28:26 AM
Is it possible on base HFS to make the guest book? So that the records in it would remain in the machine, in which was established HFS.
Title: Re: Macros
Post by: rejetto on March 08, 2008, 02:57:01 PM
if they made a shoutbox, you can make a guestbook
Title: Re: Macros
Post by: TSG on March 08, 2008, 03:35:19 PM
Rejetto is correct, an extended version of my shoutbox would make a guestbook.

SilentPliz and Mars have put together a chat, I think using the methods in mine and javascript used in their chat would make a nice guestbook. I would have a play but I haven't got the time. I am focusing my attention to releasing RAWR-Player with FLV support, Terayon written on the base code of RAWR-Template and TPGen (we are up to making the interface).

Thanks rejetto for the macro. Will try it out with next release, most likely when RAWR-Player has FLV support I will release new builds of the templates.
Title: Re: Macros
Post by: Andrew-Sirius on March 09, 2008, 06:48:29 AM
if they made a shoutbox, you can make a guestbook

But shoutbox uses external server. My HFS is established in the local network without the output into the Internet; therefore I want so that the messages in the guest book would remain locally in the same machine, where was established HFS
Title: Re: Macros
Post by: rejetto on March 09, 2008, 02:11:15 PM
the shoutbox embedded in the RAWR template (http://www.rejetto.com/forum/index.php?topic=5456.0) doesn't use external servers to provide the shoutbox.
Title: Re: Macros
Post by: Mars on March 09, 2008, 03:04:10 PM
Quote
the shoutbox embedded in the RAWR template doesn't use external servers to provide the shoutbox.

Yes it is , as this link https://silentplizssl.serveftp.net/chat/
login anonymous
pass anonymous

all is made with internal template
Title: Re: Macros
Post by: rejetto on April 26, 2008, 12:30:51 AM
some posts have been moved to www.rejetto.com/forum/?topic=5839
Title: Re: Macros An illogical logic
Post by: Mars on January 04, 2009, 03:31:11 PM
I did not find normal that the use of the value true or quite other text is the opposite of 0 or an empty string

So, with these two functions  modified in main.pas it is possible to restore the correctness of the values.

A negation will be represented well by an empty string, 0 or false.

I insist with Rejetto so that he made them appear constantly in the future versions of HFS ;)

Quote
  function isFalse(s:string):boolean;
  begin
  s:=trim(s);                                                                 ///mars  
  result:=(lowercase(s)='false') or stringExists(s, ['','0']);   ///mars
  end;

  function isTrue(s:string):boolean; inline;
  begin
  result:=(lowercase(trim(s))='true') or not isFalse(s);       ///mars  
  end;

With it you can use macro requiring a parameter true or false without asking you the question to know which syntax to use.

To test a template it will be more understandable to write
{.If|false|.... .}, {.If|FALSE|.... .}, {.If|   false   |.... .} at choice rather than  {.if||.... .} or {.if|0|.... .}
Title: Re: Macros
Post by: rejetto on January 19, 2009, 03:45:25 PM
it's widely accept in the technical world that special cases should be kept at a minimum. I fear having more special strings for false could create problems.
About the reason you report, use "if not" instead. It's very readable, isn't it?
If you have other reasons, we can discuss them.

in the while, i can suggest you that stringExists is case insensitive, so you can use
result:=stringExists(trim(s), ['','0','false'])
if you like...
Title: Re: Macros
Post by: Mars on January 27, 2009, 10:59:14 PM
Quote
in the while, i can suggest you that stringExists is case insensitive, so you can use
result:=stringExists(trim(s), ['','0','false'])
if you like...

The syntax is good and reacts as I wish it, it is accepted for my part and already in the French version of silentpliz

****************************

One the other macro is incorporated into it:  {.add to log| your text.}  ( ;) to Rejetto)
Quote
  if name = 'add to log' then  //Add by mars
    begin
    mainfrm.add2log(p);
    result:='';
    end;
this macro put  'your text' in the log box of hfs.
I use it rather often to test the templates, instead of the dialog macro.



Title: Re: Macros
Post by: rejetto on February 01, 2009, 01:12:00 PM
and what about this
Code: [Select]
    if name = 'add to log' then
      begin
      mainfrm.add2log(p, md.cd, StringToColor(parEx(1,'color')) );
      result:='';
      end;
Title: Re: Macros
Post by: Mars on February 01, 2009, 09:43:54 PM
and what about this
Code: [Select]
    if name = 'add to log' then
      begin
      mainfrm.add2log(p, md.cd, StringToColor(parEx(1,'color')) );
      result:='';
      end;


I give the good macro syntax, but the macro code has a bug ;)

{.add to log| message blue |$F00000.}   {.add to log| message blue |ClBlue.}
{.add to log| message green |$00F000.}   {.add to log| message green |ClGreen.}
{.add to log| message red |$0000F0.}   {.add to log| message red |ClRed.}

 but the macro code has a bug, to correct it:

Quote
    if name = 'add to log' then
      begin
      mainfrm.add2log(p, NIL  , StringToColor(parEx(1,'color')) );
      result:='';
      end;

Otherwise the macro does not work when it is used in the hfs.events because there is no active connection during its call ;)

The ideal would be to have as possible syntax:

{.add to log| message blue |$F00000| message green |$00F000| message red |$0000F0.}

And to obtain in the log the result following on a line
00:13:11 message blue  message green  message red

It is just a little work in more for rejetto in the conception of the procedure add2log() ...

I count on him to take up the challenge, and to find us a solution which is as high as my waits. ;) ;D
Title: Re: Macros
Post by: rejetto on February 02, 2009, 04:04:17 PM
i think that's not the right way to fix it.
in event scripts md.cd should just be NIL, and thus equivalent to your constant NIL.
what's missing is the clearing of md.
fixed in next build.

about colors: it's nice, but don't know if it's important enough to take all parameters of "add to log". We may need additional parameters in the future.
Title: Re: Macros
Post by: Mars on February 02, 2009, 05:54:04 PM
Quote
about colors: it's nice, but don't know if it's important enough to take all parameters of "add to log". We may need additional parameters in the future.

It would allow to put in evidence of the particular elements in the string shown by the log, for example certain variables as %user%  and other , or to put in evidence in red of the specific alerts in the middle of a sentence and many other possibilities, if I make the demand it is that that will allow to see all this with a little more colour ;)
Title: Re: Macros
Post by: rejetto on February 03, 2009, 01:52:03 AM
i didn't say i don't understand how it would be useful. re-read. ;)
Title: Re: Macros
Post by: Mars on February 03, 2009, 09:56:09 AM
Then you will want to use maybe rather this syntax  ;D

{.add to log| [ color=blue] message blue [ /color] [ color=green] message green [ /color] [ color=red] message red [ /color] .}
Title: Re: Macros
Post by: Chrisp6825 on February 04, 2009, 05:37:44 AM
Hi. How would I do this? :


Code: [Select]
<script type="text/javascript">
var path = document.location.pathname;
var dir = path.substring(path.indexOf('/', 1)+1, path.lastIndexOf('/'));
</script>

{.set|directory|dir.}

Where it sets 'directory' to equal the value of 'dir' in javascript...
I cant figure it out.
Title: Re: Macros
Post by: TSG on February 04, 2009, 08:58:33 AM
Are you trying to show breadcrumbs or what? I am slightly confused....

You cant talk to macro with JavaScript without using post or get form data. Or AHAH, for example. Macro is Server Side, JavaScript is Client Side.
Title: Re: Macros
Post by: rejetto on February 04, 2009, 09:46:45 AM
Code: [Select]
<script type="text/javascript">
var path = document.location.pathname;
var dir = path.substring(path.indexOf('/', 1)+1, path.lastIndexOf('/'));
</script>
{.set|directory|dir.}

as TSG says, your macro will run BEFORE the javascript, because it runs on the server, while javascript on the client.
try using %folder% instead.
Title: Re: Macros
Post by: Chrisp6825 on February 04, 2009, 01:49:07 PM
Dang.. %folder%. I knew about that. I dont know why I didn't think about it. haha
Thanks. And no this isnt for bread crums.
Title: Re: Macros
Post by: Mars on February 04, 2009, 06:55:58 PM
about breadcrumbs: rejetto, can you simply modify the code source with this line?

result:=result+xtpl(p, [ '%bread-url%', e, '%bread-name%', ad[ i],'%bread-idx%', inttostr(i)
 ]);  //mod by mars 2009

He will add simply the variable %bread-idx% which allows to obtain the level of the sub-directory with as value 0 for the root.

I know that you will still ask me to justify the usefulness of such a variable ;D. to me it just seems obvious that there is a small hole to fill ;)

Title: Re: Macros
Post by: rejetto on February 05, 2009, 11:37:06 AM
being a very little thing i don't need explanations about it. ;)
i would like to know if you or anyone would use it...

the point is not "hole to fill" or "easy to make".
more complex it is, more useful it should be to justify its existence.
i didn't invent this rule! http://fr.wikipedia.org/wiki/Principe_KISS ;)

i may also decide to include this thing without explanation, but this is not the general rule i try to apply to hfs development.
i'm sorry you see it as a caprice.
Title: Re: Macros
Post by: Funboss on August 13, 2009, 02:01:51 PM
if they made a shoutbox, you can make a guestbook

But shoutbox uses external server. My HFS is established in the local network without the output into the Internet; therefore I want so that the messages in the guest book would remain locally in the same machine, where was established HFS

If you want to keep it simple, you can use an iframe in your template. Use php to create a simple and very costumizable shoutbox. You can use a text file instead of a database. You can use the usernames (%user%). Search the forum for 'Funboss Iframe' for more info about this. There is no need to use an external server, right?

Else { Forget my comment!  ;) }