/*
 * Copyright (c) 2015 Konstantin Lepa <konstantin+ukase@lepabox.net>
 *
 * This file is part of Ukase.
 *
 *  Ukase is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as
 *  published by the Free Software Foundation, either version 3 of the
 *  License, or (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

package com.github.ukase.service;

import com.github.jknack.handlebars.Handlebars;
import com.github.jknack.handlebars.HandlebarsException;
import com.github.jknack.handlebars.Template;
import com.github.ukase.toolkit.render.RenderException;
import com.github.ukase.web.UkasePayload;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;

@Service
public class HtmlRenderer implements Renderer<UkasePayload, String> {
    private Handlebars handlebars;

    @Autowired
    public HtmlRenderer(Handlebars handlebars) {
        this.handlebars = handlebars;
    }

    @Override
    public String render(UkasePayload data) throws RenderException {
        try {
            Template template = handlebars.compile(data.getIndex());
            return template.apply(data.getData());
        } catch (IOException|HandlebarsException e) {
            throw new RenderException("Cannot produce html", e, "html");
        }
    }
}

@@ -1061,16 +1061,50 @@
 ayload;%0A
+import lombok.extern.log4j.Log4j;%0A
 import o
@@ -1244,16 +1244,23 @@
 Service%0A
+@Log4j%0A
 public c
@@ -1579,114 +1579,367 @@
     
-Template template = handlebars.compile(data.getIndex());%0A            return template.apply(data.getData())
+log.debug(%22Start rendering html, template%22 + data.getIndex());%0A            Template template = handlebars.compile(data.getIndex());%0A            log.debug(%22Template %22 + data.getIndex() + %22 compiled, rendering%22);%0A            String html = template.apply(data.getData());%0A            log.debug(%22Html rendered with size:%22 + html.length());%0A            return html
 ;%0A  
@@ -1984,16 +1984,37 @@
 xception
+%7CNullPointerException
  e) %7B%0A  

Improve logging on html renderer