rejetto forum

{{after the list| ..... }} and order of macros

Mars · 5 · 4199

0 Members and 1 Guest are viewing this topic.

Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
{{after the list| ..}} work only corectly in section [files]


[files]
{{after the list| 1}}

%list%

{{after the list| 2}}


in order 
1)%list%
2){{after the list| 1}}
3){{after the list| 2}}
 all is right to now

with full template

order to tpl execute


1)   [special:begin]

2)  seaching all items  [file] [folder] [links]

3)  execute %files%

4) execute %liste%

5){{after the list| section [files] }}

6)main template
   head and body

template for test
Quote
<head>
{{comment  |FIRST line HEAD}}

{{comment  |Last line HEAD}}
</head>

<body>
{{comment |First line BODY}}
{{after the list| At begin of BODY}}
{{comment | BEFORE LIST}}
%files%
{{comment | AFTER LIST}}

{{comment |Last line BODY}}
</body>
</html>

[file=folder=link]
item{{count}}

[special:begin]
{{comment|Normaly at BEGIN OF MACROS.LOG}}


[files]
{{comment| first line of files}}
{{after the list| At begin of files}}
%list%
{{after the list| At end of files}}

macros.log (thanks rejetto )
Quote
---
   > {{comment|Normaly at BEGIN OF MACROS.LOG}}
   <

---
   > {{count}}
   < 0

---
   > %files%
   < %files%

   > %list%
   < %list%

   > {{comment| first line of files}}
   <

   > {{after the list| At begin of files}}
   < At begin of files

   > {{after the list| At end of files}}
   < At end of files

   > {{comment  |FIRST line HEAD}}
   <

   > {{comment  |Last line HEAD}}
   <

   > {{comment |First line BODY}}
   <

   > {{after the list| At begin of BODY}}
   < At begin of BODY

   > {{comment | BEFORE LIST}}
   <

   > {{comment | AFTER LIST}}
   <

   > {{comment |Last line BODY}}
   <


a good order will be


Quote
---
   > {{comment|Normaly at BEGIN OF MACROS.LOG}}
   <

   > {{comment  |FIRST line HEAD}}
   <

   > {{comment  |Last line HEAD}}
   <

   > {{comment |First line BODY}}
   <

   > {{after the list| At begin of BODY}}
   < At begin of BODY

   > {{comment | BEFORE LIST}}
   <

---
   > %files%
   < %files%


   > {{comment| first line of files}}
   <


   > %list%
   < %list%

---
   > {{count}}
   < 0

   > {{after the list| At begin of files}}
   < At begin of files

   > {{after the list| At end of files}}
   < At end of files


   > {{comment | AFTER LIST}}
   <

   > {{comment |Last line BODY}}
   <


if you have as me some macros in each item and in some section , you have certenly some 'bug' and you don't understand why? reason is above. :-[
template is not evaluate in order we things.... ;D



Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
a good order will be

   > {{after the list| At begin of BODY}}
   < At begin of BODY

...

   > {{count}}
   < 0

you want "after the list" BEFORE the list?


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
mon insertitude devant cette situation est que chaque 'objet' devrait être traité dans l'ordre où il apparait dans le template.

peut être pour des raisons concernant certains %symbols%, la LIST est traitée en premier, juste après l'appel à [spécial:begin] , mais selon moi elle devrait etre traitée lors de l'appel à %list% et non avant,

je pense qu'il est nécessaire de réorganiser la fonction Tmainfrm.getFolderPage


Quote
listing:=TfileListing.create();
  try
      diffTpl:=Ttpl.create;
    try
      diffTpl.over:=otpl as Ttpl;
      if otpl <> filelistTpl then
        diffTpl.fullText:=optUTF8(diffTpl.over, folder.getRecursiveDiffTplAsStr());

      isDMbrowser:= otpl = dmBrowserTpl;
      fullEncode:=not isDMbrowser;
      ofsRelUrl:=length(folder.url(fullEncode))+1;
      hasher:=Thasher.create;
      try
        hasher.loadFrom(folder.resource);

        md.cd:=conn.data;
        md.tpl:=diffTpl;
        md.folder:=folder;
        md.archiveAvailable:=folder.hasRecursive(FA_ARCHIVABLE) and not folder.hasRecursive(FA_DL_FORBIDDEN);

        table:=NIL;
        result:=diffTpl['special:begin'];
        tryApplyMacrosAndSymbols(result, @md, table);

        // cache these values
        fileTpl:=xtpl(diffTpl['file'], table);
        folderTpl:=xtpl(diffTpl['folder'], table);
        linkTpl:=xtpl(diffTpl['link'], table);
        hideExt:=folder.hasRecursive(FA_HIDE_EXT);
        // this may be heavy to calculate, only do it upon request
        img_file:=pos('~img_file', fileTpl) > 0;

        // build %list% based on dir[]
        numberFolders:=0; numberFiles:=0; numberLinks:=0;
        totalBytes:=0;
        oneAccessible:=FALSE;
        fast:=TfastStringAppend.Create();
        try
          for i:=0 to length(listing.dir)-1 do
            begin
            application.ProcessMessages();
            if conn.state = HCS_DISCONNECTED then break;
            data.lastActivityTime:=now();
            handleItem(listing.dir);
            end;
          list:=fast.reset();
        finally fast.free end;
      finally hasher.free end;

      if conn.state = HCS_DISCONNECTED then exit;

      // build final page
      if not oneAccessible then md.archiveAvailable:=FALSE;
      addArray(table, [
        '%upload-link%', if_(uploadAllowed(conn, folder), diffTpl['upload-link']),
        '%files%', if_(list='', diffTpl['nofiles'], diffTpl['files']),
        '%list%',list,
        '%number%', intToStr(numberFiles+numberFolders+numberLinks),
        '%number-files%', intToStr(numberFiles),
        '%number-folders%', intToStr(numberFolders),
        '%number-links%', intToStr(numberlinks),
        '%total-bytes%', intToStr(totalBytes),
        '%total-kbytes%', intToStr(totalBytes div KILO),
        '%total-size%', smartsize(totalBytes)
      ]);
      result:=result+diffTpl[''];
      md.f:=NIL;
      md.afterTheList:=TRUE;
      try tryApplyMacrosAndSymbols(result, @md, table)
      finally md.afterTheList:=FALSE end;

//include here something as
 result:=result+diffTpl['special:end'];
tryApplyMacrosAndSymbols(result, @md, table);

//then we can define by example {{set|mynumbersitems|{{add|'%number-files%|'%number-links%}}}}

//and to end macros
md.atTheEND:=TRUE;
try tryApplyMacrosAndSymbols(result, @md, table)
finally md.atTheEND:=FALSE end;
// and any where in template  {{at the end|{{^mynumbersitems}}}}


      applySequential();
      // ensure this is the last symbol to be translated
      result:=xtpl(result, [
        '\n', CRLF,
        '%build-time%', floatToStrF((now()-buildTime)*SECONDS, ffFixed, 7,3)
      ]);
    finally diffTpl.free end;
  finally listing.free end;
finally folder.unlock() end;
end; // getFolderPage



et modifier l'appel comme ceci
Quote
......
 begin
  // most symbols here, are here because they can be heavy to calculate, so we ensure we do
  // it only upon request. others are for centralization.
  result:=name; // by default, an unrecognized symbol remains the same (just as the song)
if name= '%list%' then
begin
listing.fromFolder( folder, conn, recur );
  if not recur or (otpl <> filelistTpl) then
      listing.sort(conn);
md.afterTheList:=TRUE; 
end;

  if ansiStartsText('%sym-', name) then // legacy: surpassed by {{section}}
    result:=tpl[substr(name,2,-1)]
  else if name = '%item-icon%' then
    itemIcon()....




Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
i'm already working on moving %list% there, spent some time on it, but it's not that easy. time will tell.


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
alors c'est en bonne voie ;D bon courage, en tout cas n' hésite pas  à exposer tes idées ou projets de modifications pour hfs , afin que nous puissions te soutenir , et meme pourquoi pas te fournir du code déjà tout prêt à être intégré.