Author Topic: Macros  (Read 74623 times)

0 Members and 1 Guest are viewing this topic.

Offline TSG

  • Operator
  • Tireless poster
  • *****
  • Posts: 1934
    • View Profile
    • RAWR-Designs
Re: Macros
« Reply #15 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
« Last Edit: December 11, 2007, 03:27:23 AM by That_Stevens_Guy »

Offline Foggy

  • Tireless poster
  • ****
  • Posts: 806
    • View Profile
Re: Macros
« Reply #16 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.

Offline bacter

  • Operator
  • Tireless poster
  • *****
  • Posts: 682
    • View Profile
Re: Macros
« Reply #17 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!)


your computer has no brain - use your own !

Offline Mars

  • Operator
  • Tireless poster
  • *****
  • Posts: 1890
    • View Profile
Re: Macros
« Reply #18 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


Offline bacter

  • Operator
  • Tireless poster
  • *****
  • Posts: 682
    • View Profile
Re: Macros
« Reply #19 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

your computer has no brain - use your own !

Offline Mars

  • Operator
  • Tireless poster
  • *****
  • Posts: 1890
    • View Profile
Re: Macros
« Reply #20 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%)
 

Offline TSG

  • Operator
  • Tireless poster
  • *****
  • Posts: 1934
    • View Profile
    • RAWR-Designs
Re: Macros
« Reply #21 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}}

Offline Mars

  • Operator
  • Tireless poster
  • *****
  • Posts: 1890
    • View Profile
Re: Macros
« Reply #22 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}}





Offline TSG

  • Operator
  • Tireless poster
  • *****
  • Posts: 1934
    • View Profile
    • RAWR-Designs
Re: Macros
« Reply #23 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.
« Last Edit: December 12, 2007, 11:31:38 AM by That_Stevens_Guy »

Offline Mars

  • Operator
  • Tireless poster
  • *****
  • Posts: 1890
    • View Profile
Re: Macros
« Reply #24 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}} }}


Offline TSG

  • Operator
  • Tireless poster
  • *****
  • Posts: 1934
    • View Profile
    • RAWR-Designs
Re: Macros
« Reply #25 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.
« Last Edit: December 12, 2007, 12:10:44 PM by That_Stevens_Guy »

Offline Mars

  • Operator
  • Tireless poster
  • *****
  • Posts: 1890
    • View Profile
Re: Macros
« Reply #26 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.

Offline TSG

  • Operator
  • Tireless poster
  • *****
  • Posts: 1934
    • View Profile
    • RAWR-Designs
Re: Macros
« Reply #27 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.
« Last Edit: May 13, 2010, 05:58:34 AM by TSG »

Offline bacter

  • Operator
  • Tireless poster
  • *****
  • Posts: 682
    • View Profile
Re: Macros
« Reply #28 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.
your computer has no brain - use your own !

Offline Mars

  • Operator
  • Tireless poster
  • *****
  • Posts: 1890
    • View Profile
Re: Macros
« Reply #29 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}}