Package com.floreysoft.jmte

Examples of com.floreysoft.jmte.Engine


    private Engine engine = null;
    // Black magic for the renderer to access the current model
    private Stack<Map<String, Object>> modelStack = new Stack<Map<String, Object>>();

    private TemplateEngine() {
        engine = new Engine();
        engine.registerNamedRenderer(new StringUtilRenderer());
        engine.registerNamedRenderer(new ContestCategoryRenderer());
        engine.registerNamedRenderer(new HTMLRenderer());
        engine.registerNamedRenderer(new ReifyRenderer());
        engine.registerNamedRenderer(new FormatRenderer());
View Full Code Here


import java.util.List;
import java.util.Map;

public class TemplateEngineTest {
    public static void main(String[] args) {
        Engine engine = new Engine();

        engine.registerAnnotationProcessor(new AnnotationProcessor<String>() {
            @Override
            public String getType() {
                return "testanno";
            }

            @Override
            public String eval(AnnotationToken annotationToken, TemplateContext templateContext) {
                return annotationToken.getReceiver() + " " + annotationToken.getArguments();

            }
        });

        Map<String, Object> model = new HashMap<String, Object>();
        List<String> list = new ArrayList<String>();
        list.add("1");
        list.add("2");
        model.put("list", list);
        String template = "${@testanno arg1,arg2}${foreach list li ,}${li}${end}";
        String result = engine.transform(template, model);
        System.out.println(result);
    }
View Full Code Here

        return ("\n" + indentPatter.matcher(fragment).replaceAll(spaces));
    }

    public String fillTemplate(Config config) throws IOException {
        String template = Resources.toString(Client.class.getClassLoader().getResource("config.tpl"), Charsets.UTF_8);
        Engine engine = new Engine();
        Map<String, Object> model = new HashMap<>();
        model.put("update", config.getUpdate());
        model.put("port", config.getPort());
        model.put("locale", config.getLocale());
        model.put("score_display_duration", config.getScore_display_duration());
        model.put("ai_place_tile_delay", config.getAi_place_tile_delay());
        model.put("beep_alert", config.getBeep_alert());
        model.put("client_name", config.getClient_name());

        if (config.getConfirm() != null) {
            model.put("confirm", indent(1, yaml.dumpAs(config.getConfirm(), Tag.MAP, FlowStyle.BLOCK)));
        }
        PlayersConfig pc = config.getPlayers();
        if (pc != null) {
            if (pc.getColors() != null && !pc.getColors().isEmpty()) {
                StringBuilder colors = new StringBuilder();
                for (ColorConfig cfg : pc.getColors()) {
                    colors.append("\n  - ");
                    colors.append(yaml.dumpAs(cfg, Tag.MAP, FlowStyle.FLOW).trim());
                }
                model.put("colors", colors.toString());
            }
            if (pc.getNames() != null && !pc.getNames().isEmpty()) {
                model.put("player_names", yaml.dumpAs(pc.getNames(), Tag.SEQ, FlowStyle.FLOW).trim());
            }
            if (pc.getAi_names() != null && !pc.getAi_names().isEmpty()) {
                model.put("ai_names", yaml.dumpAs(pc.getAi_names(), Tag.SEQ, FlowStyle.FLOW).trim());
            }
        }

        if (config.getPlugins() != null && !config.getPlugins().isEmpty()) {
            model.put("plugins", indent(1, yaml.dumpAs(config.getPlugins(), Tag.SEQ, FlowStyle.BLOCK)));
        }
        if (config.getPresets() != null && !config.getPresets().isEmpty()) {
            model.put("presets", indent(1, yaml.dumpAs(config.getPresets(), Tag.MAP, FlowStyle.BLOCK)));
        }
        if (config.getConnection_history() != null && !config.getConnection_history().isEmpty()) {
            model.put("connection_history", yaml.dumpAs(config.getConnection_history(), Tag.SEQ, FlowStyle.FLOW).trim());
        }

        DebugConfig dc = config.getDebug();
        model.put("hasDebug", dc != null);
        if (dc != null) {
            model.put("save_format", dc.getSave_format());
            model.put("autosave", dc.getAutosave());
            if (dc.getAutostart() != null) {
                model.put("autostart", indent(2, yaml.dumpAs(dc.getAutostart(), Tag.MAP, FlowStyle.BLOCK)));
            }
            if (dc.getTile_definitions() != null) {
                model.put("tile_definitions", indent(2, yaml.dumpAs(dc.getTile_definitions(), Tag.MAP, FlowStyle.BLOCK)));
            }
            if (dc.getDraw() != null) {
                model.put("draw", indent(1, yaml.dumpAs(dc.getDraw(), Tag.SEQ, FlowStyle.BLOCK)));
            }
            if (dc.getOff_capabilities() != null) {
                model.put("off_capabilities", indent(2, yaml.dumpAs(dc.getOff_capabilities(), Tag.SEQ, FlowStyle.BLOCK)));
            }
            model.put("area_highlight", dc.getArea_highlight());
        }

        String result = engine.transform(template, model);
        result = result.replace(" !!"+PresetConfig.class.getName(), "");
        result = result.replace("\n", System.lineSeparator());
        return result;
    }
View Full Code Here

TOP

Related Classes of com.floreysoft.jmte.Engine

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.