package cn.reghao.bnt.web.template.layout;

import cn.reghao.bnt.web.template.DirectiveHandler;
import cn.reghao.bnt.web.template.TemplateDirective;
import org.springframework.stereotype.Component;

/**
 * @since 4.0.0
 */
@Component
public class ExtendsDirective extends TemplateDirective {
    /**
     * 处理 ftl 模板中的 @layout.extends 标签
     *
     * @param
     * @return
     * @date 2023-04-11 16:30:29
     */
    @Override
    public String getName() {
        return "layout.extends";
    }

    @Override
    public void execute(DirectiveHandler handler) throws Exception {
        String theme = "classic";
        String layoutName =  handler.getString("name");
        layoutName = layoutName.startsWith("/") ? theme + layoutName : theme + "/" + layoutName;
        handler.bodyResult();
        handler.getEnv().include(layoutName, null, true);
    }
}
