package spark.template.jade;

import de.neuland.jade4j.JadeConfiguration;
import de.neuland.jade4j.template.ClasspathTemplateLoader;
import de.neuland.jade4j.template.FileTemplateLoader;
import de.neuland.jade4j.template.JadeTemplate;
import spark.ModelAndView;
import spark.TemplateEngine;
import spark.template.jade.loader.SparkClasspathLoader;

import java.io.IOException;
import java.util.Map;

public class JadeEngine extends TemplateEngine {

    private JadeConfiguration configuration;

    public JadeEngine() {
        configuration = new JadeConfiguration();
        configuration.setTemplateLoader(new SparkClasspathLoader("templates/"));
    }

    public JadeEngine(String contentRoot) {
        configuration = new JadeConfiguration();
        configuration.setTemplateLoader(new SparkClasspathLoader(contentRoot));
    }

    public JadeEngine(JadeConfiguration configuration) {
        this.configuration = configuration;
    }

    @Override
    public String render(ModelAndView modelAndView) {
        try {
            JadeTemplate template = configuration.getTemplate(modelAndView.getViewName());

            return configuration.renderTemplate(template, (Map<String, Object>) modelAndView.getModel());
        } catch (IOException e) {
            throw new IllegalArgumentException(e);
        }
    }
}

@@ -1,136 +1,621 @@
-package spark.template.jade;%0A%0Aimport de.neuland.jade4j.JadeConfiguration;%0Aimport de.neuland.jade4j.template.ClasspathT
+/**%0A * Copyright (c) 2015%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage spark.t
 emplate
-Lo
+.j
 ade
-r
 ;
+%0A
 %0Aimp
@@ -640,35 +640,25 @@
 e4j.
-template.FileTemplateLoader
+JadeConfiguration
 ;%0Aim
@@ -703,16 +703,68 @@
 mplate;%0A
+%0Aimport java.io.IOException;%0Aimport java.util.Map;%0A%0A
 import s
@@ -872,58 +872,70 @@
 r;%0A%0A
-import java.io.IOException;%0Aimport java.util.Map;%0A
+/**%0A * Template engine to render HTML from jade templates.%0A */
 %0Apub
@@ -944,24 +944,32 @@
 c class Jade
+Template
 Engine exten
@@ -1043,166 +1043,326 @@
     
-public JadeEngine() %7B%0A        configuration = new JadeConfiguration();%0A        configuration.setTemplateLoader(new SparkClasspathLoader(%22templates/%22));%0A
+/**%0A     * Construct a jade template engine defaulting to the 'templates' directory%0A     * under the resource path.%0A     */%0A    public JadeTemplateEngine() %7B%0A        this(%22templates/%22);%0A    %7D%0A%0A    /**%0A     * Construct a jade template engine.%0A     *%0A     * @param templateRoot the template root directory to use%0A 
     
-%7D%0A
+*/
 %0A   
@@ -1369,24 +1369,32 @@
  public Jade
+Template
 Engine(Strin
@@ -1395,23 +1395,24 @@
 (String 
-content
+template
 Root) %7B%0A
@@ -1529,15 +1529,16 @@
 der(
-content
+template
 Root
@@ -1556,111 +1556,40 @@
     
-public JadeEngine(JadeConfiguration configuration) %7B%0A        this.configuration = configuration;
+/**%0A     * %7B@inheritDoc%7D
 %0A    
-%7D%0A
+ */
 %0A   
@@ -1599,16 +1599,51 @@
 verride%0A
+    @SuppressWarnings(%22unchecked%22)%0A
     publ
@@ -1793,17 +1793,16 @@
 ame());%0A
-%0A
         
@@ -1850,16 +1850,36 @@
 emplate,
+%0A                   
  (Map%3CSt

Rework the JadeTemplateEngine class internally