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