76e7c5a5 by Acetousk Committed by GitHub

Merge pull request #2 from moqui/test-upstream

Test upstream
2 parents 76e88ff2 3db488ac
...@@ -11,3 +11,4 @@ To install run (with moqui-framework): ...@@ -11,3 +11,4 @@ To install run (with moqui-framework):
11 ### Setup 11 ### Setup
12 12
13 - Have all email templates setup as a ProductStoreEmail to EmailTemplate see: the ProductStore's Emails page 13 - Have all email templates setup as a ProductStoreEmail to EmailTemplate see: the ProductStore's Emails page
14
......
1 /*
2 * This software is in the public domain under CC0 1.0 Universal plus a
3 * Grant of Patent License.
4 *
5 * To the extent possible under law, the author(s) have dedicated all
6 * copyright and related and neighboring rights to this software to the
7 * public domain worldwide. This software is distributed without any
8 * warranty.
9 *
10 * You should have received a copy of the CC0 Public Domain Dedication
11 * along with this software (see the LICENSE.md file). If not, see
12 * <http://creativecommons.org/publicdomain/zero/1.0/>.
13 */
14
15 apply plugin: 'groovy'
16
17 version = '3.0.0'
18 // sourceCompatibility = '1.8'
19 def moquiDir = file(projectDir.absolutePath + '/../../..')
20 def frameworkDir = file(moquiDir.absolutePath + '/framework')
21
22 repositories {
23 flatDir name: 'localLib', dirs: frameworkDir.absolutePath + '/lib'
24 mavenCentral()
25 }
26
27 // Log4J has annotation processors, disable to avoid warning
28 tasks.withType(JavaCompile) { options.compilerArgs << "-proc:none" }
29 tasks.withType(GroovyCompile) { options.compilerArgs << "-proc:none" }
30
31 dependencies {
32 implementation project(':framework')
33 testImplementation project(':framework').configurations.testImplementation.allDependencies
34 }
35
36 // by default the Java plugin runs test on build, change to not do that (only run test if explicit task)
37 // no longer workds as of gradle 4.8 or possibly earlier, use clear() instead: check.dependsOn.remove(test)
38 check.dependsOn.clear()
39
40 jar {
41 destinationDirectory = file(projectDir.absolutePath + '/lib')
42 // this is required to change from the default that includes the path to this module (ie 'runtime/component/mjml')
43 archiveBaseName = 'moqui-mjml'
44 }
45 task cleanLib(type: Delete) { delete file(jar.archivePath) }
46 clean.dependsOn cleanLib
47
48 test {
49 useJUnitPlatform()
50 testLogging { events "passed", "skipped", "failed" }
51 testLogging.showStandardStreams = true; testLogging.showExceptions = true
52 maxParallelForks 1
53
54 dependsOn cleanTest
55
56 systemProperty 'moqui.runtime', moquiDir.absolutePath + '/runtime'
57 systemProperty 'moqui.conf', 'conf/MoquiDevConf.xml'
58 systemProperty 'moqui.init.static', 'true'
59 maxHeapSize = "512M"
60
61 classpath += files(sourceSets.main.output.classesDirs)
62 // filter out classpath entries that don't exist (gradle adds a bunch of these), or ElasticSearch JarHell will blow up
63 classpath = classpath.filter { it.exists() }
64
65 beforeTest { descriptor ->
66 logger.lifecycle("Running test: ${descriptor}")
67 }
68 }
...@@ -16,7 +16,9 @@ along with this software (see the LICENSE.md file). If not, see ...@@ -16,7 +16,9 @@ along with this software (see the LICENSE.md file). If not, see
16 16
17 <extend-entity entity-name="EmailTemplate" package="moqui.basic.email"> 17 <extend-entity entity-name="EmailTemplate" package="moqui.basic.email">
18 <field name="grapesLocation" type="text-medium"/> 18 <field name="grapesLocation" type="text-medium"/>
19 <field name="grapesPublishedVersionName" type="text-short"/>
19 <field name="htmlLocation" type="text-medium"/> 20 <field name="htmlLocation" type="text-medium"/>
21 <field name="htmlPublishedVersionName" type="text-short"/>
20 </extend-entity> 22 </extend-entity>
21 <view-entity entity-name="ProductStoreEmailDetail" package="mantle.product.store"> 23 <view-entity entity-name="ProductStoreEmailDetail" package="mantle.product.store">
22 <member-entity entity-alias="PSE" entity-name="mantle.product.store.ProductStoreEmail"/> 24 <member-entity entity-alias="PSE" entity-name="mantle.product.store.ProductStoreEmail"/>
......
1 JAR files go in this directory and are picked up automatically by Moqui Framework based on the convention of the directory name 'lib'.
2
3 The build.gradle file uses this directory as the target for the built jar file, and deletes the built jar file as part of the clean task.
4
...@@ -17,11 +17,71 @@ along with this software (see the LICENSE.md file). If not, see ...@@ -17,11 +17,71 @@ along with this software (see the LICENSE.md file). If not, see
17 17
18 <actions> 18 <actions>
19 <entity-find-one entity-name="moqui.basic.email.EmailTemplate" value-field="emailTemplate" auto-field-map="[emailTemplateId:emailTemplateId]"/> 19 <entity-find-one entity-name="moqui.basic.email.EmailTemplate" value-field="emailTemplate" auto-field-map="[emailTemplateId:emailTemplateId]"/>
20 <if condition="!emailTemplate"> 20 <if condition="!emailTemplate || !emailTemplate.htmlLocation || !emailTemplate.htmlPublishedVersionName">
21 <return error="true" message="Email Template not found"/> 21 <return error="true" message="Email Template not found"/>
22 </if> 22 </if>
23 <set field="dataPre" from="ec.resource.getLocationReference(emailTemplate.htmlLocation).getText(emailTemplate.htmlPublishedVersionName)"/>
24 <if condition="dataPre == null">
25 <return error="true" message="Email Template does not exist at ${emailTemplate.htmlLocation} with version ${emailTemplate.htmlPublishedVersionName}"/>
26 </if>
27 <set field="doc" from="org.jsoup.Jsoup.parse(dataPre)"/>
28 <script><![CDATA[
29 doc.outputSettings().escapeMode(org.jsoup.nodes.Entities.EscapeMode.xhtml).prettyPrint(false);
30
31 doc.traverse(new org.jsoup.select.NodeVisitor() {
32 public void head(org.jsoup.nodes.Node node, int depth) {
33 if (node instanceof org.jsoup.nodes.TextNode) {
34 def text = node.getWholeText();
35 if(text.trim().length() > 0) {
36 def newText = "";
37 def lines = text.split("\n");
38 for (line in lines) {
39 if (line.startsWith("<br>")) {
40 line = line.replaceFirst(/^<br>/, "");
41 }
42 if (line.endsWith("<br>")) {
43 newText += line;
44 } else {
45 newText += line + "<br>";
46 }
47 }
48 if (newText.startsWith("<br>")) {
49 newText = newText.replaceFirst(/^<br>/, "");
50 }
51 node = org.jsoup.nodes.TextNode.createFromEncoded(newText);
52 }
53 }
54 }
55 public void tail(org.jsoup.nodes.Node node, int depth) {
56 // No action needed on tail
57 }
58 });
59 ]]></script>
60 <set field="dataPre" from="doc.html()"/>
61 <script><![CDATA[
62 String location = emailTemplate?.htmlLocation ?: "template.ftl";
63
64 freemarker.template.Template newTemplate;
65 Reader templateReader = null;
23 66
24 <set field="renderedText" from="ec.resource.template(emailTemplate.htmlLocation, 'ftl')"/> 67 try {
68 templateReader = new StringReader(context.dataPre);
69 // Use the getFtlConfiguration method from ec.resource.templateRenderers.ftl
70 newTemplate = new freemarker.template.Template(location, templateReader, ec.resource.templateRenderers.ftl.getFtlConfiguration());
71 } catch (Exception e) {
72 throw new org.moqui.BaseArtifactException("Error while initializing template at " + location, e);
73 } finally {
74 if (templateReader != null) {
75 try { templateReader.close(); }
76 catch (Exception e) { logger.error("Error closing template reader", e); }
77 }
78 }
79 StringWriter sw = new StringWriter()
80 try {
81 newTemplate.createProcessingEnvironment(ec.contextStack, sw).process();
82 } catch (Exception e) { throw new org.moqui.BaseArtifactException("Error rendering template at " + location, e); }
83 context.renderedText = sw.toString();
84 ]]></script>
25 </actions> 85 </actions>
26 86
27 <widgets> 87 <widgets>
......
...@@ -21,6 +21,9 @@ along with this software (see the LICENSE.md file). If not, see ...@@ -21,6 +21,9 @@ along with this software (see the LICENSE.md file). If not, see
21 <resource name="mjml"> 21 <resource name="mjml">
22 <method type="get"><service name="mjml.MjmlServices.load#GrapeJs"/></method> 22 <method type="get"><service name="mjml.MjmlServices.load#GrapeJs"/></method>
23 <method type="post"><service name="mjml.MjmlServices.store#GrapeJs"/></method> 23 <method type="post"><service name="mjml.MjmlServices.store#GrapeJs"/></method>
24 <resource name="afterMjmlStore">
25 <method type="get"><service name="mjml.MjmlServices.get#AfterMjmlStore"/></method>
26 </resource>
24 </resource> 27 </resource>
25 28
26 </resource> 29 </resource>
......