Package com.vtence.molecule.templating

Examples of com.vtence.molecule.templating.Template


    public void run(WebServer server) throws IOException {
        // We use Mustache templates with an .html extension
        Templates templates = new Templates(
                new JMustacheRenderer().fromDir(locateOnClasspath("examples/templates")).extension("html"));
        final Template layout = templates.named("layout");
        final Template greeting = templates.named("greeting");

        // Apply a common layout to all rendered pages
        server.filter("/", Layout.html(layout))
              .start(new DynamicRoutes() {{
                  get("/hello").to(new Application() {
                      public void handle(final Request request, final Response response) throws Exception {
                          response.contentType("text/html; charset=utf-8");
                          String name = request.parameter("name") != null ? request.parameter("name") : "World";
                          // Mustache can use any object or a Map as a rendering context
                          response.body(greeting.render(new User(name)));
                      }
                  });
              }});
    }
View Full Code Here


        FileServer files = new FileServer(content).header(CACHE_CONTROL, "public; max-age=60");
        // Serve static assets for css, js and image files from the content dir.
        StaticAssets assets = new StaticAssets(files).serve("/css", "/js", "/images");
        // We use Mustache templates with an .html extension
        Templates templates = new Templates(new JMustacheRenderer().fromDir(content).extension("html"));
        final Template index = templates.named("index");

              // Add content length header when size of content is known
        server.add(new ContentLengthHeader())
              // Make get and head requests conditional to freshness of client stored representation
              .add(new ConditionalGet())
              // Add ETag if response has no validation information
              .add(new ETag())
              // Compress bodies that are not images
              .add(new Compressor().compressibleTypes(JAVASCRIPT, CSS, HTML))
              .add(assets)
              .start(new Application() {
                  public void handle(Request request, Response response) throws Exception {
                      response.set(CONTENT_TYPE, HTML);
                      response.set(LAST_MODIFIED, request.parameter("timestamp"));
                      response.body(index.render(NO_CONTEXT));
                  }
              });
    }
View Full Code Here

TOP

Related Classes of com.vtence.molecule.templating.Template

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.