You are not logged in.
In my TMVCApplication I need to load template files from application resources.
So I created patch that add some virtual functions to TMVCViewsMustache.
Source files:
mORMotMVC-20170801.zip
And now we can change file loading process.
For example, we need to load all template and static files from zip archive.
Zip archive can be stored in resources or on disk in separate file.
First, add TMVCViewsMustache descendant and override file loading methods:
type
TMyViews = class(TMVCViewsMustache)
FZip: TZipRead;
function FindTemplates(const Mask: TFileName): TFileNameDynArray; override;
function GetStaticFile(const aFileName: TFileName): RawByteString; override;
function GetTemplate(const aFileName: TFileName): RawUTF8; override;
function GetTemplateAge(const aFileName: TFileName): TDateTime; override;
end;
function TMyViews.FindTemplates(const Mask: TFileName): TFileNameDynArray;
var
i, c: Integer;
begin
SetLength(Result, 0);
for i := 0 to FZip.Count - 1 do
begin
if IsMatch(StringToUTF8(Mask), StringToUTF8(FZip.Entry[i].zipName), True) then
begin
c := Length(Result);
SetLength(Result, c + 1);
Result[c] := FZip.Entry[i].zipName;
end;
end;
end;
function TMyViews.GetStaticFile(const aFileName: TFileName): RawByteString;
var
LIndex: Integer;
begin
LIndex := FZip.NameToIndex(AFileName);
if LIndex >= 0 then
Result := FZip.Unzip(LIndex);
end;
function TMyViews.GetTemplate(const aFileName: TFileName): RawUTF8;
var
LIndex: Integer;
begin
LIndex := FZip.NameToIndex(AFileName);
if LIndex >= 0 then
Result := FZip.Unzip(LIndex);
end;
function TMyViews.GetTemplateAge(const aFileName: TFileName): TDateTime;
begin
Result := 0.0;
end;
And then change Start method:
procedure TBlogApplication.Start(aServer: TSQLRestServer);
begin
...
// publish IBlogApplication using Mustache Views
fMainRunner := TMVCRunOnRestServer.Create(Self, nil, '',
TMyViews.Create(Factory.InterfaceTypeInfo, (RestModel as TSQLRestServer).LogClass));
...
end;
Now files will be taken from zip archive (see SynZip.pas on how to create TZipRead instance).
Offline
Pull request:
https://github.com/synopse/mORMot/pull/87
Offline
@Chaa - did you see @Eugene Ilyin Boilerplate HTTP Server. It embed resources also
Offline
Yes, I see it.
Boilerplate server extracts all resources in application working folder on startup.
In my case there is no file writes at all - template and static files extracted from ZIP on demand.
But this is only one use case.
My requirements is to allow customizing some templates/static files, while others templates/files can not be changed.
Offline
ab, thanks for applying patch.
Continue playing with GitHub, forks and pull requests.
Offline
Since GetStaticFile was removed, is there another method to change static file loading?
Offline
Using a method-based service?
Or please check https://synopse.info/fossil/info/1eb998e68a
Offline
Thanks ab.
I need to share a static content between controllers. When a first controller's Views contains templates like header.partial or footer.partial and I used it from another controller through {{>../header.partial}} there is problem with a static content due to relative paths (blog/sub-uri/.static instead of blog/.static/)
Offline