3169a2e4 by Michael Jones

Merge branch 'use-raw-ftl-not-temp-dbresource' into 'master'

Use raw ftl not temp dbresource

See merge request !1
2 parents 755febc4 c50af2e1
...@@ -87,10 +87,30 @@ along with this software (see the LICENSE.md file). If not, see ...@@ -87,10 +87,30 @@ along with this software (see the LICENSE.md file). If not, see
87 } 87 }
88 ]]></script> 88 ]]></script>
89 <!-- <log level="warn" message="dataPre is ${dataPre}"/>--> 89 <!-- <log level="warn" message="dataPre is ${dataPre}"/>-->
90 <set field="grapesTempFile" from="grapesJsResource.makeFile(grapesFile?.dbResourceId + '.temp.json')"/> 90 <script><![CDATA[
91 <script>grapesTempFile.putText(dataPre)</script> 91 String location = "template.ftl";
92 <set field="data" from="ec.resource.template(grapesTempFile.location, 'ftl')"/> 92
93 <script>grapesTempFile.delete()</script> 93 freemarker.template.Template newTemplate;
94 Reader templateReader = null;
95
96 try {
97 templateReader = new StringReader(context.dataPre);
98 // Use the getFtlConfiguration method from ec.resource.templateRenderers.ftl
99 newTemplate = new freemarker.template.Template(location, templateReader, ec.resource.templateRenderers.ftl.getFtlConfiguration());
100 } catch (Exception e) {
101 throw new org.moqui.BaseArtifactException("Error while initializing template at " + location, e);
102 } finally {
103 if (templateReader != null) {
104 try { templateReader.close(); }
105 catch (Exception e) { logger.error("Error closing template reader", e); }
106 }
107 }
108 StringWriter sw = new StringWriter()
109 try {
110 newTemplate.createProcessingEnvironment(ec.contextStack, sw).process();
111 } catch (Exception e) { throw new org.moqui.BaseArtifactException("Error rendering template at " + location, e); }
112 context.data = sw.toString();
113 ]]></script>
94 <!-- <log level="warn" message="data is ${data}"/>--> 114 <!-- <log level="warn" message="data is ${data}"/>-->
95 <set field="moquiVars" from="globalGrapeVarList"/> 115 <set field="moquiVars" from="globalGrapeVarList"/>
96 </then> 116 </then>
...@@ -125,10 +145,30 @@ along with this software (see the LICENSE.md file). If not, see ...@@ -125,10 +145,30 @@ along with this software (see the LICENSE.md file). If not, see
125 } 145 }
126 ]]></script> 146 ]]></script>
127 <!-- <log level="warn" message="dataPre is ${dataPre}"/>--> 147 <!-- <log level="warn" message="dataPre is ${dataPre}"/>-->
128 <set field="grapesTempFile" from="grapesJsResource.makeFile(grapesFile?.dbResourceId + '.temp.json')"/> 148 <script><![CDATA[
129 <script>grapesTempFile.putText(dataPre)</script> 149 String location = "template.ftl";
130 <set field="data" from="ec.resource.template(grapesTempFile.location, 'ftl')"/> 150
131 <script>grapesTempFile.delete()</script> 151 freemarker.template.Template newTemplate;
152 Reader templateReader = null;
153
154 try {
155 templateReader = new StringReader(context.dataPre);
156 // Use the getFtlConfiguration method from ec.resource.templateRenderers.ftl
157 newTemplate = new freemarker.template.Template(location, templateReader, ec.resource.templateRenderers.ftl.getFtlConfiguration());
158 } catch (Exception e) {
159 throw new org.moqui.BaseArtifactException("Error while initializing template at " + location, e);
160 } finally {
161 if (templateReader != null) {
162 try { templateReader.close(); }
163 catch (Exception e) { logger.error("Error closing template reader", e); }
164 }
165 }
166 StringWriter sw = new StringWriter()
167 try {
168 newTemplate.createProcessingEnvironment(ec.contextStack, sw).process();
169 } catch (Exception e) { throw new org.moqui.BaseArtifactException("Error rendering template at " + location, e); }
170 context.data = sw.toString();
171 ]]></script>
132 <!-- <log level="warn" message="data is ${data}"/>--> 172 <!-- <log level="warn" message="data is ${data}"/>-->
133 <set field="moquiVars" from="globalGrapeVarList"/> 173 <set field="moquiVars" from="globalGrapeVarList"/>
134 </else-if> 174 </else-if>
......