Commit a329f06e authored by Benito van der Zander's avatar Benito van der Zander

improve multipage template usability: prevent it from being overriden by...

improve multipage template usability: prevent it from being overriden by option wraparound; pattern paths are relative to template not calling directory; honor --silent
parent 3cf18133
<actions>
<action> <s>res := "default"</s> </action>
<action id="ac1"> <s>res := "v1"</s> </action>
<action id="ac2"> <s>res := "v2"</s> </action>
<action id="local"> <page url="tests/a.xml" templateFile="more.local.pattern"/> </action>
<action id="remote"> <page url="http://www.videlibri.de/xidelecho.php?abc=def"/> </action>
</actions>
\ No newline at end of file
<title>{$res}</title>
\ No newline at end of file
init
res := AAA
res:v1
res:v2
res:AAA
res:v1
res:v2
......@@ -523,7 +523,11 @@ tests/test.sh regression_multipage3b -e '<action><page url="http://videlibri.sou
tests/test.sh regression_htmlparse --input-format html '<ol><li>a<li>b<li>c</ol>' -e '//ol/li'
tests/test.sh variableActions [ '<a/>' --template-file tests/variable.actions ] '<b/>' --xquery '$first || ":" || $second '
tests/test.sh variableActions --template-file tests/variable.actions --xquery '$first || ":" || $second '
tests/test.sh moreActions1 --template-action ac1 --template-file tests/more.actions --xquery '"res:" || $res'
tests/test.sh moreActions2 -e '"init"||get("res")' --template-action ac2 --template-file tests/more.actions --xquery '"res:" || $res'
tests/test.sh moreActionsLocalPattern --template-action local --template-file tests/more.actions --xquery '"res:" || $res'
tests/test.sh moreActions -e '"init"||get("res")' --template-action ac1 --template-file tests/more.actions --xquery '"res:" || $res, for $i in ("ac2", "local", "ac1", "ac2") return ( x:call-action($i), "res:"||$res)' #variables set by call-action are reordered before the extract print, since the values of the extract are only known after the for has finished
echo
echo Results:
......
......@@ -840,6 +840,7 @@ TExtraction = class(TDataProcessing)
extractExclude, extractInclude: TStringArray;
extractKind: TExtractionKind;
templateUrl: string;
templateActions: TStringArray;
defaultName: string;
......@@ -1800,18 +1801,21 @@ procedure TExtraction.readOptions(reader: TOptionReaderWrapper);
var
tempstr: string;
begin
reader.read('extract', extract); //todo. option: extract-file
if not cgimode and strBeginsWith(extract, '@') then extract := strLoadFromFileChecked(strCopyFrom(extract, 2));
extract:=trim(extract);
if reader.read('extract-exclude', tempstr) then extractExclude := strSplit(tempstr, ',', false);
if reader.read('extract-include', tempstr) then extractInclude := strSplit(tempstr, ',', false);
if reader.read('extract-kind', tempstr) then if extract <> '' then extractKind := extractKindFromString(tempstr);
if reader.read('template-file', tempstr) then begin
extract := strLoadFromFileChecked(tempstr);
extractKind := ekMultipage;
if extract = '' then begin
reader.read('extract', extract); //todo. option: extract-file
if not cgimode and strBeginsWith(extract, '@') then extract := strLoadFromFileChecked(strCopyFrom(extract, 2));
extract:=trim(extract);
if reader.read('extract-exclude', tempstr) then extractExclude := strSplit(tempstr, ',', false);
if reader.read('extract-include', tempstr) then extractInclude := strSplit(tempstr, ',', false);
if reader.read('template-file', tempstr) then begin
templateUrl := tempstr;
extract := strLoadFromFileChecked(tempstr);
extractKind := ekMultipage;
end;
end;
if reader.read('template-action', tempstr) then templateActions := strSplit(tempstr, ',', false);
if (extractKind = ekAuto) and reader.read('extract-kind', tempstr) then if extract <> '' then extractKind := extractKindFromString(tempstr);
reader.read('default-variable-name', defaultName);
reader.read('print-type-annotations', printTypeAnnotations);
......@@ -2624,9 +2628,11 @@ begin
end;
ekMultipage: if assigned (onPrepareInternet) then begin
multipage.onPageProcessed:=@pageProcessed;
if parent.silent then multipage.onLog := nil else multipage.onLog := @multipage.selfLog;
multipage.internet := onPrepareInternet(parent.userAgent, parent.proxy, @parent.httpReact);
multipagetemp := TMultiPageTemplate.create();
multipagetemp.loadTemplateFromString(extract);
if extract = '' then raise Exception.Create('Multipage-action-template is empty');
multipagetemp.loadTemplateFromString(extract, ExtractFileName(templateUrl), ExtractFileDir(templateUrl));
multipage.setTemplate(multipagetemp);
multipage.perform(templateActions);
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment