Upgraded Dropwizard, adjusted template handling accordingly.
Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker-online-tester/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker-online-tester/commit/01a23c57 Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker-online-tester/tree/01a23c57 Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker-online-tester/diff/01a23c57 Branch: refs/heads/master Commit: 01a23c57516744aae0fb988eb0db140b15e29e20 Parents: 36d5a23 Author: ddekany <ddek...@apache.org> Authored: Fri Mar 23 23:10:41 2018 +0100 Committer: ddekany <ddek...@apache.org> Committed: Fri Mar 23 23:10:41 2018 +0100 ---------------------------------------------------------------------- dependencies.gradle | 2 +- .../onlinetester/view/FreeMarkerOnlineView.java | 2 +- src/main/resources/freemarker-online.yml | 5 +- src/main/resources/view/freemarker-online.ftl | 169 ------------------- src/main/resources/view/main.ftlh | 167 ++++++++++++++++++ src/main/resources/view/utils.ftl | 38 ----- src/main/resources/view/utils.ftlh | 36 ++++ 7 files changed, 208 insertions(+), 211 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-freemarker-online-tester/blob/01a23c57/dependencies.gradle ---------------------------------------------------------------------- diff --git a/dependencies.gradle b/dependencies.gradle index 33bcf98..e1fa3c5 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -17,7 +17,7 @@ * under the License. */ -ext.dropwizard_version = "1.1.1"; +ext.dropwizard_version = "1.3.0"; ext.jackson_version = "2.8.9"; ext.jeresy_version = "2.25"; ext.libraries = [ http://git-wip-us.apache.org/repos/asf/incubator-freemarker-online-tester/blob/01a23c57/src/main/java/org/apache/freemarker/onlinetester/view/FreeMarkerOnlineView.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/onlinetester/view/FreeMarkerOnlineView.java b/src/main/java/org/apache/freemarker/onlinetester/view/FreeMarkerOnlineView.java index 3932dda..a04a4f2 100644 --- a/src/main/java/org/apache/freemarker/onlinetester/view/FreeMarkerOnlineView.java +++ b/src/main/java/org/apache/freemarker/onlinetester/view/FreeMarkerOnlineView.java @@ -115,7 +115,7 @@ public class FreeMarkerOnlineView extends View { * @param execute set to true if the execution should be triggered on page load. */ public FreeMarkerOnlineView() { - super("/view/freemarker-online.ftl", Charset.forName("utf-8")); + super("/view/main.ftlh"); } public String getTemplate() { http://git-wip-us.apache.org/repos/asf/incubator-freemarker-online-tester/blob/01a23c57/src/main/resources/freemarker-online.yml ---------------------------------------------------------------------- diff --git a/src/main/resources/freemarker-online.yml b/src/main/resources/freemarker-online.yml index 27070aa..c1268b2 100644 --- a/src/main/resources/freemarker-online.yml +++ b/src/main/resources/freemarker-online.yml @@ -35,8 +35,9 @@ server: requestLog: appenders: [] viewRendererConfiguration: - .ftl: + freemarker: # was `.ftl:` before Dropwizard 1.3.0 incompatibleImprovements: 2.3.28 locale: en_US timeZone: UTC - outputEncoding: UTF-8 \ No newline at end of file + outputEncoding: UTF-8 + templateExceptionHandler: rethrow \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker-online-tester/blob/01a23c57/src/main/resources/view/freemarker-online.ftl ---------------------------------------------------------------------- diff --git a/src/main/resources/view/freemarker-online.ftl b/src/main/resources/view/freemarker-online.ftl deleted file mode 100644 index f4c68b0..0000000 --- a/src/main/resources/view/freemarker-online.ftl +++ /dev/null @@ -1,169 +0,0 @@ -<#ftl outputFormat="HTML"> - -<#-- - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - ---> - -<#import "utils.ftl" as u> -<!DOCTYPE html> -<html> -<head> - <meta charset="utf-8"> - <link rel="stylesheet" href="assets/main.css"> - <link rel="stylesheet" href="https://unpkg.com/purecss@1.0.0/build/pure-min.css"> - - <script src="https://code.jquery.com/jquery-1.11.2.min.js"></script> - <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.blockUI/2.70/jquery.blockUI.min.js"></script> - <script src="https://cdnjs.cloudflare.com/ajax/libs/autosize.js/3.0.8/autosize.min.js"></script> - <script src="assets/script.js?v=4"></script><!-- Always increase v if the script.js is changed! --> - <script> - $(function() { - // Auto-focus on first form input: - $('#templateAndModelForm *:input[type!=hidden]:first').focus(); - - // Submit form when Ctrl+Enter is hit in a textarea: - - - // Dynamically adapt text areas heights to their content: - //$('#templateAndModelForm textarea').autosize(); - autosize($('textarea')); - - // Show/hide data model examples: - $("#showHideDataModelExamples").click(function(e) { - $("#dataModelExamples").toggle(); - $("#hideDataModelExamplesLabel").toggle(); - $("#showDataModelExamplesLabel").toggle(); - - e.preventDefault(); - return false; - }) - <#if execute> - execute(); - </#if> - }); - </script> - - <title>Online FreeMarker Template Tester</title> -</head> -<body> -<div id="layout"> - <div id="main"> - <div class="header"> - <h1>Online FreeMarker Template Tester</h1> - </div> - - <div class="content"> - <!--[if lte IE 8]> - <div style="background-color: #C00; color: #fff; padding: 12px 24px;"> - You seem to use Internet Explorer 8 or older. This page might won't work properly with that. - </div> - <![endif]--> - - <form id="templateAndModelForm" method="post" class="pure-form pure-form-stacked"> - <label for="template">Template <span class="faint">(Apache FreeMarker ${freeMarkerVersion})</span></label> - <textarea id="template" name="template" class="pure-input-1 source-code" - placeholder="Enter template, like: Hello ${r'${user}'}!" - >${template}</textarea> - - <label for="template"> - Data model - (<a id="showHideDataModelExamples" href="#" tabindex="-1"><!-- - --><span id="showDataModelExamplesLabel">show</span><!-- - --><span id="hideDataModelExamplesLabel" class="hiddenByDefault">hide</span> - examples</a>) - </label> - <div id="dataModelExamples" class="hiddenByDefault"> - <div class="description"> - Note: This syntax is specific to this online service; normally, you just have Java objects as - data-model. - </div> - <pre>someString = Some value -otherString = "JSON\nsyntax" -someNumber = 3.14 -someBoolean = true -someDate = 2014-02-28 -someTime = 20:50:30.5+02:00 -someDatetime = 2014-02-28T18:50Z -someList = ["JSON", "syntax", 1, 2, 3 ] -someMap = { "JSON syntax": true, "nestedList": [1, 2, 3] } -someXML = <example x="1">text</example></pre></div> - <textarea id="dataModel" name="dataModel" class="pure-input-1 source-code" - placeholder='Enter one or more assignments (e.g., user = John Doe), starting each in its own line.' - >${dataModel}</textarea> - <div class="formPanel"> - <div class="horizontalBox"> - <@u.htmlSelect caption="Output format" name="outputFormat" selectionOptions=outputFormats - helpLink='https://freemarker.apache.org/docs/dgui_misc_autoescaping.html' - helpHover='Influences auto-escaping' /> - </div> - <div class="horizontalBox"> - <@u.htmlSelect caption="Locale" name="locale" selectionOptions=locales - helpHover='Influences how numbers and date/time values are formatted' /> - </div> - <div class="horizontalBox"> - <@u.htmlSelect caption="Time zone" name="timeZone" selectionOptions=timeZones - helpHover='Date/time values are shown as seen from this time zone' /> - </div> - </div> - <div class="formPanel"> - <div class="horizontalBox"> - <@u.htmlSelect caption="Tag syntax" name="tagSyntax" selectionOptions=tagSyntaxes - helpLink='https://freemarker.apache.org/docs/dgui_misc_alternativesyntax.html#dgui_misc_alternativesyntax_tag' /> - </div> - <div class="horizontalBox"> - <@u.htmlSelect caption="Interpolation syntax" name="interpolationSyntax" selectionOptions=interpolationSyntaxes - helpLink='https://freemarker.apache.org/docs/dgui_misc_alternativesyntax.html#dgui_misc_alternativesyntax_interpolation' /> - </div> - </div> - <div class="formBottomButtonsContainer"> - <input id="eval-btn" type="button" value="Evaluate" class="pure-button pure-button-primary"/> - <span class="faint">Ctrl+Enter in input fields will submit this form too</span> - </div> - <div style="display:none" class="resultContainer"> - <label for="result">Result</label> - <textarea id="result" class="pure-input-1 source-code" readonly></textarea> - </div> - - </form> - </div><!-- content --> - - <div class="footer"> - FreeMarker documentation: - <a href="https://freemarker.apache.org/docs/" target="_blank">Contents</a> - | - <a href="https://freemarker.apache.org/docs/dgui_template_overallstructure.html" target="_blank">Overall syntax</a> - | - <a href="https://freemarker.apache.org/docs/dgui_template_exp.html#exp_cheatsheet" target="_blank">Expression syntax</a> - | - <a href="https://freemarker.apache.org/docs/ref_directive_alphaidx.html" target="_blank">List of <#<i>directives</i>></a> - | - <a href="https://freemarker.apache.org/docs/ref_builtins_alphaidx.html" target="_blank">List of <tt>?<i>built_in</i></tt> functions</a> - </div><!-- footer --> - </div><!-- main --> - - <!-- Fork me on GitHub: --> - <a href="https://github.com/apache/incubator-freemarker-online-tester" target="_blank"> - <img class="forkMeOnGithub" src="https://camo.githubusercontent.com/a6677b08c955af8400f44c6298f40e7d19cc5b2d/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f677261795f3664366436642e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_gray_6d6d6d.png"> - </a> -</div><!-- layout --> -</body> -</html> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker-online-tester/blob/01a23c57/src/main/resources/view/main.ftlh ---------------------------------------------------------------------- diff --git a/src/main/resources/view/main.ftlh b/src/main/resources/view/main.ftlh new file mode 100644 index 0000000..84af01f --- /dev/null +++ b/src/main/resources/view/main.ftlh @@ -0,0 +1,167 @@ +<#-- + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +--> + +<#import "utils.ftlh" as u> +<!DOCTYPE html> +<html> +<head> + <meta charset="utf-8"> + <link rel="stylesheet" href="assets/main.css"> + <link rel="stylesheet" href="https://unpkg.com/purecss@1.0.0/build/pure-min.css"> + + <script src="https://code.jquery.com/jquery-1.11.2.min.js"></script> + <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.blockUI/2.70/jquery.blockUI.min.js"></script> + <script src="https://cdnjs.cloudflare.com/ajax/libs/autosize.js/3.0.8/autosize.min.js"></script> + <script src="assets/script.js?v=4"></script><!-- Always increase v if the script.js is changed! --> + <script> + $(function() { + // Auto-focus on first form input: + $('#templateAndModelForm *:input[type!=hidden]:first').focus(); + + // Submit form when Ctrl+Enter is hit in a textarea: + + + // Dynamically adapt text areas heights to their content: + //$('#templateAndModelForm textarea').autosize(); + autosize($('textarea')); + + // Show/hide data model examples: + $("#showHideDataModelExamples").click(function(e) { + $("#dataModelExamples").toggle(); + $("#hideDataModelExamplesLabel").toggle(); + $("#showDataModelExamplesLabel").toggle(); + + e.preventDefault(); + return false; + }) + <#if execute> + execute(); + </#if> + }); + </script> + + <title>Online FreeMarker Template Tester</title> +</head> +<body> +<div id="layout"> + <div id="main"> + <div class="header"> + <h1>Online FreeMarker Template Tester</h1> + </div> + + <div class="content"> + <!--[if lte IE 8]> + <div style="background-color: #C00; color: #fff; padding: 12px 24px;"> + You seem to use Internet Explorer 8 or older. This page might won't work properly with that. + </div> + <![endif]--> + + <form id="templateAndModelForm" method="post" class="pure-form pure-form-stacked"> + <label for="template">Template <span class="faint">(Apache FreeMarker ${freeMarkerVersion})</span></label> + <textarea id="template" name="template" class="pure-input-1 source-code" + placeholder="Enter template, like: Hello ${r'${user}'}!" + >${template}</textarea> + + <label for="template"> + Data model + (<a id="showHideDataModelExamples" href="#" tabindex="-1"><!-- + --><span id="showDataModelExamplesLabel">show</span><!-- + --><span id="hideDataModelExamplesLabel" class="hiddenByDefault">hide</span> + examples</a>) + </label> + <div id="dataModelExamples" class="hiddenByDefault"> + <div class="description"> + Note: This syntax is specific to this online service; normally, you just have Java objects as + data-model. + </div> + <pre>someString = Some value +otherString = "JSON\nsyntax" +someNumber = 3.14 +someBoolean = true +someDate = 2014-02-28 +someTime = 20:50:30.5+02:00 +someDatetime = 2014-02-28T18:50Z +someList = ["JSON", "syntax", 1, 2, 3 ] +someMap = { "JSON syntax": true, "nestedList": [1, 2, 3] } +someXML = <example x="1">text</example></pre></div> + <textarea id="dataModel" name="dataModel" class="pure-input-1 source-code" + placeholder='Enter one or more assignments (e.g., user = John Doe), starting each in its own line.' + >${dataModel}</textarea> + <div class="formPanel"> + <div class="horizontalBox"> + <@u.htmlSelect caption="Output format" name="outputFormat" selectionOptions=outputFormats + helpLink='https://freemarker.apache.org/docs/dgui_misc_autoescaping.html' + helpHover='Influences auto-escaping' /> + </div> + <div class="horizontalBox"> + <@u.htmlSelect caption="Locale" name="locale" selectionOptions=locales + helpHover='Influences how numbers and date/time values are formatted' /> + </div> + <div class="horizontalBox"> + <@u.htmlSelect caption="Time zone" name="timeZone" selectionOptions=timeZones + helpHover='Date/time values are shown as seen from this time zone' /> + </div> + </div> + <div class="formPanel"> + <div class="horizontalBox"> + <@u.htmlSelect caption="Tag syntax" name="tagSyntax" selectionOptions=tagSyntaxes + helpLink='https://freemarker.apache.org/docs/dgui_misc_alternativesyntax.html#dgui_misc_alternativesyntax_tag' /> + </div> + <div class="horizontalBox"> + <@u.htmlSelect caption="Interpolation syntax" name="interpolationSyntax" selectionOptions=interpolationSyntaxes + helpLink='https://freemarker.apache.org/docs/dgui_misc_alternativesyntax.html#dgui_misc_alternativesyntax_interpolation' /> + </div> + </div> + <div class="formBottomButtonsContainer"> + <input id="eval-btn" type="button" value="Evaluate" class="pure-button pure-button-primary"/> + <span class="faint">Ctrl+Enter in input fields will submit this form too</span> + </div> + <div style="display:none" class="resultContainer"> + <label for="result">Result</label> + <textarea id="result" class="pure-input-1 source-code" readonly></textarea> + </div> + + </form> + </div><!-- content --> + + <div class="footer"> + FreeMarker documentation: + <a href="https://freemarker.apache.org/docs/" target="_blank">Contents</a> + | + <a href="https://freemarker.apache.org/docs/dgui_template_overallstructure.html" target="_blank">Overall syntax</a> + | + <a href="https://freemarker.apache.org/docs/dgui_template_exp.html#exp_cheatsheet" target="_blank">Expression syntax</a> + | + <a href="https://freemarker.apache.org/docs/ref_directive_alphaidx.html" target="_blank">List of <#<i>directives</i>></a> + | + <a href="https://freemarker.apache.org/docs/ref_builtins_alphaidx.html" target="_blank">List of <tt>?<i>built_in</i></tt> functions</a> + </div><!-- footer --> + </div><!-- main --> + + <!-- Fork me on GitHub: --> + <a href="https://github.com/apache/incubator-freemarker-online-tester" target="_blank"> + <img class="forkMeOnGithub" src="https://camo.githubusercontent.com/a6677b08c955af8400f44c6298f40e7d19cc5b2d/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f677261795f3664366436642e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_gray_6d6d6d.png"> + </a> +</div><!-- layout --> +</body> +</html> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker-online-tester/blob/01a23c57/src/main/resources/view/utils.ftl ---------------------------------------------------------------------- diff --git a/src/main/resources/view/utils.ftl b/src/main/resources/view/utils.ftl deleted file mode 100644 index 187c98d..0000000 --- a/src/main/resources/view/utils.ftl +++ /dev/null @@ -1,38 +0,0 @@ -<#ftl outputFormat='HTML'> - -<#-- - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - ---> - -<#macro htmlSelect caption name selectionOptions helpLink='' helpHover=''> - <div <@titleAttr helpHover />>${caption}<#if helpLink != ''> (<a href='${helpLink}' target='_blank'>?</a>)</#if></div> - <div> - <select name="${name}" id="${name}" class="pure-input-1" <@titleAttr helpHover />> - <#list selectionOptions as selectionOption> - <#local value = selectionOption.value> - <option value="${value}"<#if value == .vars[name]!> selected</#if>>${selectionOption.label}</option> - </#list> - </select> - </div> -</#macro> - -<#macro titleAttr title><#if title != ''>title="${title}"</#if></#macro> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker-online-tester/blob/01a23c57/src/main/resources/view/utils.ftlh ---------------------------------------------------------------------- diff --git a/src/main/resources/view/utils.ftlh b/src/main/resources/view/utils.ftlh new file mode 100644 index 0000000..29f93e8 --- /dev/null +++ b/src/main/resources/view/utils.ftlh @@ -0,0 +1,36 @@ +<#-- + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +--> + +<#macro htmlSelect caption name selectionOptions helpLink='' helpHover=''> + <div <@titleAttr helpHover />>${caption}<#if helpLink != ''> (<a href='${helpLink}' target='_blank'>?</a>)</#if></div> + <div> + <select name="${name}" id="${name}" class="pure-input-1" <@titleAttr helpHover />> + <#list selectionOptions as selectionOption> + <#local value = selectionOption.value> + <option value="${value}"<#if value == .vars[name]!> selected</#if>>${selectionOption.label}</option> + </#list> + </select> + </div> +</#macro> + +<#macro titleAttr title><#if title != ''>title="${title}"</#if></#macro> \ No newline at end of file