Author Topic: Macros  (Read 67491 times)

0 Members and 1 Guest are viewing this topic.

Offline Mars

  • Operator
  • Insane poster
  • *****
  • Posts: 1799
    • View Profile
Macros
« on: December 08, 2007, 12: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
« Last Edit: December 12, 2007, 01:11:16 PM by mars »
FRENCH MEMBER : Si vous comprenez la langue française,  n'hésitez pas à l'utiliser pour une meilleure aide de ma part

Offline bacter

  • Operator
  • Insane poster
  • *****
  • Posts: 682
    • View Profile
temp
« Reply #1 on: December 08, 2007, 01: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'.
your computer has no brain - use your own !

Offline Mars

  • Operator
  • Insane poster
  • *****
  • Posts: 1799
    • View Profile
temp
« Reply #2 on: December 08, 2007, 04: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.!!!
« Last Edit: December 08, 2007, 04:17:39 PM by mars »
FRENCH MEMBER : Si vous comprenez la langue française,  n'hésitez pas à l'utiliser pour une meilleure aide de ma part

Offline rejetto

  • Administrator
  • Insane programmer
  • *
  • Posts: 12837
    • View Profile
Re: Macros
« Reply #3 on: December 09, 2007, 11:52:52 AM »
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

Offline Mars

  • Operator
  • Insane poster
  • *****
  • Posts: 1799
    • View Profile
Re: Macros
« Reply #4 on: December 09, 2007, 01: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}} ]]

FRENCH MEMBER : Si vous comprenez la langue française,  n'hésitez pas à l'utiliser pour une meilleure aide de ma part

Offline rejetto

  • Administrator
  • Insane programmer
  • *
  • Posts: 12837
    • View Profile
Re: Macros
« Reply #5 on: December 09, 2007, 01: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.
« Last Edit: December 09, 2007, 01:46:01 PM by rejetto »

Offline Foggy

  • Insane poster
  • *****
  • Posts: 806
    • View Profile
Re: Macros
« Reply #6 on: December 09, 2007, 11:17:47 PM »
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.
« Last Edit: December 09, 2007, 11:36:54 PM by Foggy »

Offline TSG

  • Operator
  • Insane poster
  • *****
  • Posts: 1934
    • View Profile
    • RAWR-Designs
Re: Macros
« Reply #7 on: December 10, 2007, 12: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.

Offline Mars

  • Operator
  • Insane poster
  • *****
  • Posts: 1799
    • View Profile
Re: Macros
« Reply #8 on: December 10, 2007, 12: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
FRENCH MEMBER : Si vous comprenez la langue française,  n'hésitez pas à l'utiliser pour une meilleure aide de ma part

Offline Mars

  • Operator
  • Insane poster
  • *****
  • Posts: 1799
    • View Profile
Re: Macros
« Reply #9 on: December 10, 2007, 03: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)
« Last Edit: December 10, 2007, 03:33:19 PM by mars »
FRENCH MEMBER : Si vous comprenez la langue française,  n'hésitez pas à l'utiliser pour une meilleure aide de ma part

Offline Mars

  • Operator
  • Insane poster
  • *****
  • Posts: 1799
    • View Profile
Re: Macros
« Reply #10 on: December 10, 2007, 03: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

« Last Edit: December 10, 2007, 04:11:49 PM by mars »
FRENCH MEMBER : Si vous comprenez la langue française,  n'hésitez pas à l'utiliser pour une meilleure aide de ma part

Offline bacter

  • Operator
  • Insane poster
  • *****
  • Posts: 682
    • View Profile
Re: Macros
« Reply #11 on: December 10, 2007, 06:18:23 PM »
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.

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.











your computer has no brain - use your own !

Offline Mars

  • Operator
  • Insane poster
  • *****
  • Posts: 1799
    • View Profile
Re: Macros
« Reply #12 on: December 10, 2007, 06:53:08 PM »
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,
FRENCH MEMBER : Si vous comprenez la langue française,  n'hésitez pas à l'utiliser pour une meilleure aide de ma part

Offline rejetto

  • Administrator
  • Insane programmer
  • *
  • Posts: 12837
    • View Profile
Re: Macros
« Reply #13 on: December 10, 2007, 07:01:18 PM »
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

Offline rejetto

  • Administrator
  • Insane programmer
  • *
  • Posts: 12837
    • View Profile
Re: Macros
« Reply #14 on: December 10, 2007, 07:18:51 PM »
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