package me.chyxion.tigon.codegen.service.support;

import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import me.chyxion.tigon.codegen.model.CodeGenArgs;
import me.chyxion.tigon.codegen.service.CodeGenerator;

/**
 * @version 0.0.1
 * @since 0.0.1
 * @author Shaun Chyxion <br>
 * chyxion@163.com <br>
 * Oct 6, 2014 1:17:22 PM
 */
public class ViewCodeGen extends CodeGenerator {

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean accept(Map<String, Object> dataModel) {
        return (Boolean) dataModel.get("genView");
    }
    
    /**
     * {@inheritDoc}
     */
    @Override
    public String process(Map<String, Object> dataModel, String module, String model) {
        StringBuilder sbFilePath = new StringBuilder(viewsDir);
        if (StringUtils.isNotBlank(module)) {
            sbFilePath.append(module).append("/");
        }
        sbFilePath.append(model).append("/List.js");
        return render(new CodeGenArgs(
                CodeGenArgs.TARGET_VIEW, 
                "/codegen/view.ftl", 
                dataModel,
                sbFilePath.toString()));
    }
}
