diff --git a/documentation/src/main/java/controllers/templates/FragmentController.java b/documentation/src/main/java/controllers/templates/FragmentController.java new file mode 100644 index 000000000..73c7ff121 --- /dev/null +++ b/documentation/src/main/java/controllers/templates/FragmentController.java @@ -0,0 +1,42 @@ +/* + * #%L + * Wisdom-Framework + * %% + * Copyright (C) 2013 - 2014 Wisdom Framework + * %% + * Licensed 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. + * #L% + */ +// tag::controller[] +package controllers.templates; + +import org.wisdom.api.DefaultController; +import org.wisdom.api.annotations.Controller; +import org.wisdom.api.annotations.Route; +import org.wisdom.api.annotations.View; +import org.wisdom.api.http.HttpMethod; +import org.wisdom.api.http.Result; +import org.wisdom.api.templates.Template; + +@Controller +public class FragmentController extends DefaultController { + + @View("page") + Template template; + + @Route(method = HttpMethod.GET, uri = "/templates/page") + public Result welcome() { + return ok(render(template, "username", "Clement")); + } +} +// end::controller[] diff --git a/documentation/src/main/java/controllers/templates/WelcomeController.java b/documentation/src/main/java/controllers/templates/WelcomeController.java new file mode 100644 index 000000000..0d27b32b2 --- /dev/null +++ b/documentation/src/main/java/controllers/templates/WelcomeController.java @@ -0,0 +1,42 @@ +/* + * #%L + * Wisdom-Framework + * %% + * Copyright (C) 2013 - 2014 Wisdom Framework + * %% + * Licensed 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. + * #L% + */ +// tag::controller[] +package controllers.templates; + +import org.wisdom.api.DefaultController; +import org.wisdom.api.annotations.Controller; +import org.wisdom.api.annotations.Route; +import org.wisdom.api.annotations.View; +import org.wisdom.api.http.HttpMethod; +import org.wisdom.api.http.Result; +import org.wisdom.api.templates.Template; + +@Controller +public class WelcomeController extends DefaultController { + + @View("welcome") // <1> + Template template; // <2> + + @Route(method = HttpMethod.GET, uri = "/templates/welcome") + public Result welcome() { + return ok(render(template, "welcome", "Welcome on the Path to Wisdom")); // <3> + } +} +// end::controller[] diff --git a/documentation/src/main/resources/assets/index.ad b/documentation/src/main/resources/assets/index.ad index 74cb52ecc..f61d183b5 100644 --- a/documentation/src/main/resources/assets/index.ad +++ b/documentation/src/main/resources/assets/index.ad @@ -4,6 +4,7 @@ Version ${project.version} :description: This document is the documentation of the Wisdom Framework. :toc: right :sourcedir: ${project.basedir}/src/main/java +:resourcedir: ${project.basedir}/src/main/resources :assetdir: ${project.basedir}/src/main/assets :assetoutdir: ${project.basedir}/target/wisdom/assets :icons: font @@ -21,6 +22,7 @@ include::build-process.ad[] include::http.ad[] include::routing.ad[] include::response.ad[] +include::template.ad[] include::session-and-scope.ad[] include::json.ad[] include::file-upload.ad[] diff --git a/documentation/src/main/resources/assets/template.ad b/documentation/src/main/resources/assets/template.ad new file mode 100644 index 000000000..9c6e73058 --- /dev/null +++ b/documentation/src/main/resources/assets/template.ad @@ -0,0 +1,197 @@ +== Using Templates + +=== Template as a Service + +Just to makes you understand how the template system works, you should read these small paragraphs. + +Wisdom allows the integration of any template engine. By default, http://www.thymeleaf.org/[Thymeleaf] is provided. + Each template is exposed as a _service_ and can be injected in a controller using the `@View` annotation. This + pattern is used regardless the template engine you use. + +The `View` annotation is looking for a template with the specified name. It is equivalent to a regular `@Requires` +with a filter. + +=== The Thymeleaf Template Engine + +http://www.thymeleaf.org/[Thymeleaf] is an XML / XHTML / HTML5 template engine (extensible to other formats) that +can work both in web and non-web environments. It is really well suited for serving XHTML/HTML5 at the view layer of +web applications, but it can process any XML file even in offline environments. + +The main goal of Thymeleaf is to provide an elegant and well-formed way of creating templates. It allows you to create +powerful natural templates, that can be correctly displayed by browsers and therefore work also as static prototypes. + One of the main interest of Thymeleaf is a smooth collaboration with Web Designer. By using specific attributes on + HTML elements, you never interfere with the work of the web designers. They create the HTML page with whatever + structure, and CSS tricks, and you just identify the parts where you inject the data. + +It looks like this. As you can see, it's a pretty straightforward syntax supporting all the features you expect from a + template engine: variables, internationalization, iterations, layouts, fragments, object navigation, and much more. + +[source,xml,indent=0] +---- +
Name | +Price | +
---|---|
Oranges | +0.99 | +
this will be replace by the variable
+this will be replace by the variable (unescape so won't remove the contained HTML elements) +
+ +**Internationalized variable:** + +this will be replace by the variable using the request locale
+ +WARNING: Internationalized value are directly retrieved from the internationalization service from Wisdom. + +**Iteration:** + +You can iterate on collections, arrays, maps... + + +This is the first step to Wisdom, follow us...
+