rejetto forum

macro legacy

0 Members and 1 Guest are viewing this topic.

Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
Default template in next beta will start with these lines

Code: [Select]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<!--{.comment|--><h1 style='margin-bottom:100em'>WARNING: this template is only to be used with HFS 2.3 (and macros enabled)</h1> <!--.} -->

When the template is used in HFS 2.2, the warning is displayed instead of a mess.
I think every "modern" template for HFS should adopt a similar solution.


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
A small update not to be obliged to overload the template

Quote
  try
    assert(assigned(cbData), 'cbMacros: cbData=NIL');
    md:=cbData;

    name:=fullmacro;
    if (name[1] = '%') and (name[length(name)] = '%') then
      begin
      handleSymbol();
      exit;
      end;

    if pars.count = 0 then exit;
    // extract first parameter as 'name'
    name:=trim(pars[0]);
    pars.delete(0);    // this operation is done with a memory move over pointers. Having few parameters normally, it's fast. We may eventually avoid this deletion and consider parameters starting from 1.
    if name = '' then exit;
    macroError('not supported or wrong number of parameters');
    // eventually remove trailing
    if pars.Count > 0 then
      begin
      p:=pars[pars.count-1];
      if ansiEndsText('/'+name, p) then
        begin
        setLength(p, length(p)-length(name)-1);
        pars[pars.count-1]:=p;
        end;
      end;

    // here we try to handle some shortcuts.
    // it's a special starting character that identifies the macro, and the rest of the name is a parameter.
    p:=copy(name,2,MAXINT);
    // comment it's for comments, or if you just don't want the output a macro to be sent to the browser.
    // the content of comment (the parameter) is executed as anything else, it's not like macro quoting.


    if not mainfrm.enableMacrosChk.checked then
      begin
      if name = 'warning' then
        result:=par(0)
        else
        result:='';  // result:=fullmacro;
      exit;
      end;


    if name[1] = '$' then
      section(0);

    if name[1] = '!' then
      try result:=or_([fromTable('special:strings',p), md.tpl.getStrByID(p), par(0), p]) except end;

    if name[1] = '^' then
      call(0);

    if name[1] = '?' then  // shortcut for 'urlvar'
      result:=urlvar(p);

    if (name = 'comment') or (name = 'warning') then
      begin
      result:='';
      exit;
      end;


all disabled macro are replaced by an empty string

Quote
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<!--{.comment|--><h1 style='margin-bottom:100em'>WARNING: this template is only to be used with HFS 2.3 (and macros enabled)</h1> <!--.} -->
{.warning|<h1 style='margin-bottom:100em'>WARNING: this template is only to be used with HFS 2.3 (and macros enabled)</h1>.}
<html>


WARNING works as COMMENT when Enable Macros is checked.

Good work and good idea all the same, rejetto


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
yours is a nice idea mars, but it is not compatible with 2.2


Offline Fysack

  • Tireless poster
  • ****
    • Posts: 598
  • present picture
    • View Profile
    • Admin
you make me happy mars  8)
GOD CAN READ YOUR MIND