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.
Constructor and description |
---|
StreamingTemplateEngine
() Create a streaming template engine instance using the default class loader |
StreamingTemplateEngine
(ClassLoader parentLoader) Create a streaming template engine instance using a custom class loader |
Type | Name and description |
---|---|
Template |
createTemplate(Reader reader) |
Methods inherited from class | Name |
---|---|
class TemplateEngine |
createTemplate, createTemplate, createTemplate, createTemplate |
class Object |
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll |
Create a streaming template engine instance using the default class loader
Create a streaming template engine instance using a custom class loader
The custom loader is used when parsing the template code
parentLoader
- The class loader to use when parsing the template code.
Creates a template instance using the template source from the provided Reader.
The template can be applied repeatedly on different bindings to produce custom output.
Technical detail{ parentClass, stringSectionList, binding, out -> //code generated by parsing the template data } *, we then curry in the parentClass and stringSectionList arguments so that the StreamingTemplate instance returned from 'createTemplate' internally contains a template closure on the form:
{ binding, out -> //code generated by parsing the template data } *Calling template.make(binding), curries in the 'binding' argument:
public Writable make(final Map map) { final Closure template = this.template.curry(new Object[]{map}); return (Writable) template; }which only leaves the 'out' argument unbound. The only method on the writable interface is writeTo(Writer out) so groovy rules about casting a closure to a one-method-interface apply and the above works. I.e. we return the now one argument closure as the Writable which can be serialized to System.out, a file, etc according to the Writable interface contract.
Copyright © 2003-2015 The Apache Software Foundation. All rights reserved.