#1 mORMot 2 » Suggest adding for update Partial when mustache render. » 2023-02-26 08:11:27

suoke
Replies: 0

In order to detect the update of Partial contained in Mustache when I access it, I made the following changes:
for core.mustache

  TGetPartialNotify = function(const PartialName: RawUtf8;
    var partial: TSynMustache): boolean of object; //add

and

  TSynMustache = class protected fTemplate: RawUtf8;

  fGetPartialNotify: TGetPartialNotify;
  property GetPartialNotify: TGetPartialNotify read fGetPartialNotify
    write fGetPartialNotify;
        mtPartial:
          begin
            partial := nil;
            if fInternalPartials <> nil then
              partial := fInternalPartials.GetPartial(Value);
            if (partial = nil) and (Context.fOwner <> self) then
              // recursive call
              partial := Context.fOwner.fInternalPartials.GetPartial(Value);
            if (partial = nil) and (Context.Partials <> nil) then
              partial := Context.Partials.GetPartial(Value);
           
            if partial <> nil then
            begin
              //add here
              if Assigned(fGetPartialNotify) then
              begin
                if fGetPartialNotify(Value, partial) then
                begin
                  Context.Partials.AddOrReplaceObject(Value, partial);//!
                end;
              end;
              //end.
              partial.RenderContext(Context, 0, high(partial.fTags));
            end;
          end;
procedure TSynMustachePartials.AddOrReplaceObject(const aName: RawUtf8;
  oMustache: TSynMustache);
begin
  fList.AddObject(aName, oMustache, { raiseexisting= } false, nil,
    { replace= } true, false);

end;

Specify the method when creating mustache, and borrow the implementation method of TMvcViewsMustache. When calling mustache, you can detect the change of partia and update it.

            mustache := TSynMustache.Parse(Template);
            mustache.GetPartialNotify := mustacheParitalgetNotify;
function TViewsMustache.mustacheParitalgetNotify(const PartialName: RawUtf8;
  var partial: TSynMustache): boolean;
var
  vP: TViewPartial;
  age: TUnixTime;
begin
  Result := false;
  vP := FPartials.Items[PartialName];
  if vP <> nil then
  begin
    vP.Locker.ProtectMethod;
    if (vP.partial = nil) or ((fViewTemplateFileTimestampMonitor <> 0) and
      (vP.FileAgeCheckTick < GetTickCount64)) then
    begin
      age := GetTemplateAge(vP.ShortFileName);
      if (age <> vP.FileAgeLast) then
      begin
        Result := true;
        partial := TSynMustache.Parse(GetTemplate(vP.ShortFileName));

        if fViewTemplateFileTimestampMonitor <> 0 then
          vP.FileAgeCheckTick := GetTickCount64 +
            int64(fViewTemplateFileTimestampMonitor) * int64(1000);
      end;
    end;
  end;
end;

#2 mORMot 2 » Suggest adding aReplaceAndFreeOldObject for AddObject » 2023-02-26 07:55:06

suoke
Replies: 0

When Member data is managed externally,like

var
  SynMustacheCache: TSynMustacheCache = nil;

SynMustacheCache's data update,will Trigger exception when memory release.
so:
TRawUtf8List.AddObject  Suggest adding aReplaceAndFreeOldObject.

    function AddObject(const aText: RawUtf8; aObject: TObject;
      aRaiseExceptionIfExisting: boolean = false;
      aFreeAndReturnExistingObject: PPointer = nil;
      aReplaceExistingObject: boolean = false;
      aReplaceAndFreeOldObject: boolean = true): PtrInt;

add aReplaceAndFreeOldObject: boolean
and
update here

        if aReplaceExistingObject then
        begin
          if Obj = nil then
            raise ESynException.CreateUtf8
              ('%.AddOrReplaceObject with no object at [%]', [self, aText]);
          if aReplaceAndFreeOldObject then //add here
            FreeAndNil(fObjects[result]);
          fObjects[result] := aObject;
        end
        else
          result := -1;
        exit;

when we need update ,can set aReplaceAndFreeOldObject:=false;

#3 Re: mORMot 2 » Suggest adding "partial:=nil;" here » 2023-02-26 06:33:16

Modify here in my code

        mtPartial:
          begin
            partial := nil; //add here
            if fInternalPartials <> nil then // if not,will Throw an exception  In the next line of code
              partial := fInternalPartials.GetPartial(Value);
            if (partial = nil) and (Context.fOwner <> self) then
              // recursive call
              partial := Context.fOwner.fInternalPartials.GetPartial(Value);
            if (partial = nil) and (Context.Partials <> nil) then
              partial := Context.Partials.GetPartial(Value);
            if partial <> nil then
              partial.RenderContext(Context, 0, high(partial.fTags));
          end;

#4 mORMot 2 » Suggest adding "partial:=nil;" here » 2023-02-22 08:40:15

suoke
Replies: 2

If it is not set to NIL first, memory error exception will occur when calling this variable under some tests.


mormot.core.mustache
......
procedure TSynMustache.RenderContext(Context: TSynMustacheContext;
  TagStart, TagEnd: integer);
var
  partial: TSynMustache;
begin
//add partial:=nil;
  partial:=nil;
......
  while TagStart <= TagEnd do
......

#5 mORMot 2 » reload question for ex\mvc-blog in TMvcViewsMustache » 2023-02-21 12:34:08

suoke
Replies: 1

demo:ex\mvc-blog

When this DEMO is running, it can detect changes to the template *. html and update it. However, when the changes in the *. partial file cannot detect disease updates. So how to check and update the *. partial file when it is updated by other apps?

#6 mORMot 2 » Add update function for TSynMustachePartials » 2023-02-17 14:26:10

suoke
Replies: 0

Compared with mormot1, the TRawUtf8List of mormot2 has increased

function TRawUtf8List.AddOrReplaceObject(const aText: RawUtf8; aObject: TObject): PtrInt;

Therefore, it is suggested that TSynMustachePartials can add the update function on this basis, which can realize the template content update based on Mustache.

#7 Re: mORMot 2 » How to convert the SSL configuration file in NGINX mode to ... » 2023-02-09 18:00:43

Thank you very much!
It is recommended that you create a DEMO in your spare time that can implement SSL like NGINX. Users only need to reference *. crt and *. key~

#8 mORMot 2 » How to convert the SSL configuration file in NGINX mode to ... » 2023-02-09 17:01:48

suoke
Replies: 2

How to convert the SSL configuration file in NGINX mode to the mORMot2-master\ex\ThirdPartyDemos\tbo\05-WebMustache?


NGINX SSL LIKE
www.domainname.com.crt
www.domainname.com.key

    server {
        listen       50808;
        server_name  www.domainname.com;

        ssl on;
        ssl_certificate ./www.domainname.com.crt;
        ssl_certificate_key ./www.domainname.com.key;
        ssl_session_timeout 5m;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
        ssl_prefer_server_ciphers on;
       
        index index.html index.htm index.php; 
        error_page  405     =200 $uri;
        location / {
            add_header Access-Control-Allow-Origin *;
        }

    }

Board footer

Powered by FluxBB