Search in sources :

Example 11 with SimpleScalar

use of freemarker.template.SimpleScalar in project android by JetBrains.

the class FmExtractLettersMethodTest method check.

@SuppressWarnings("rawtypes")
private void check(String s, String expected) throws TemplateModelException {
    FmExtractLettersMethod method = new FmExtractLettersMethod();
    List list = Collections.singletonList(new SimpleScalar(s));
    assertEquals(expected, ((SimpleScalar) method.exec(list)).getAsString());
}
Also used : List(java.util.List) SimpleScalar(freemarker.template.SimpleScalar)

Example 12 with SimpleScalar

use of freemarker.template.SimpleScalar in project android by JetBrains.

the class FmActivityToLayoutMethodTest method check.

@SuppressWarnings("rawtypes")
private static void check(String s, String expected) throws TemplateModelException {
    FmActivityToLayoutMethod method = new FmActivityToLayoutMethod();
    List list = Collections.singletonList(new SimpleScalar(s));
    assertEquals(expected, ((SimpleScalar) method.exec(list)).getAsString());
}
Also used : List(java.util.List) SimpleScalar(freemarker.template.SimpleScalar)

Example 13 with SimpleScalar

use of freemarker.template.SimpleScalar in project android by JetBrains.

the class FmCamelCaseToUnderscoreMethodTest method check.

@SuppressWarnings("rawtypes")
private void check(String s, String expected) throws TemplateModelException {
    FmCamelCaseToUnderscoreMethod method = new FmCamelCaseToUnderscoreMethod();
    List list = Collections.singletonList(new SimpleScalar(s));
    assertEquals(expected, ((SimpleScalar) method.exec(list)).getAsString());
}
Also used : List(java.util.List) SimpleScalar(freemarker.template.SimpleScalar)

Example 14 with SimpleScalar

use of freemarker.template.SimpleScalar in project leopard by tanhaichao.

the class AbstractTemplateMethod method exec.

@Override
public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException {
    // arguments.toArray();
    Object[] args = new Object[arguments.size()];
    int i = 0;
    for (Object obj : arguments) {
        if (obj != null) {
            if (obj instanceof SimpleDate) {
                args[i] = ((SimpleDate) obj).getAsDate();
            } else if (obj instanceof SimpleNumber) {
                args[i] = ((SimpleNumber) obj).getAsNumber();
            } else if (obj instanceof SimpleNumber) {
                args[i] = ((SimpleNumber) obj).getAsNumber();
            } else if (obj instanceof SimpleScalar) {
                args[i] = ((SimpleScalar) obj).toString();
            } else if (obj instanceof StringModel) {
                args[i] = ((StringModel) obj);
            } else {
                logger.error("obj:" + obj.getClass());
                args[i] = obj.toString();
            }
        }
        i++;
    }
    try {
        return this.execute(args);
    } catch (TemplateModelException e) {
        throw e;
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new TemplateModelException(e.getMessage(), e);
    }
}
Also used : TemplateModelException(freemarker.template.TemplateModelException) SimpleDate(freemarker.template.SimpleDate) SimpleNumber(freemarker.template.SimpleNumber) StringModel(freemarker.ext.beans.StringModel) SimpleScalar(freemarker.template.SimpleScalar) TemplateModelException(freemarker.template.TemplateModelException)

Example 15 with SimpleScalar

use of freemarker.template.SimpleScalar in project leopard by tanhaichao.

the class BodyTemplateDirective method execute.

@Override
public void execute(Environment env, @SuppressWarnings("rawtypes") Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
    // String folder = ((SimpleScalar) params.get("template_folder")).getAsString();
    String templateName = ((SimpleScalar) params.get("template_name")).getAsString();
    // String templateName = (String) params.get("template_name");
    Template template = env.getConfiguration().getTemplate(templateName + ".ftl");
    template.process(DATA.get(), env.getOut());
}
Also used : SimpleScalar(freemarker.template.SimpleScalar) Template(freemarker.template.Template)

Aggregations

SimpleScalar (freemarker.template.SimpleScalar)23 List (java.util.List)17 SimpleNumber (freemarker.template.SimpleNumber)5 ArrayList (java.util.ArrayList)5 TemplateModel (freemarker.template.TemplateModel)4 Result (ninja.Result)4 Test (org.junit.Test)4 TemplateModelException (freemarker.template.TemplateModelException)3 StringModel (freemarker.ext.beans.StringModel)2 SimpleDate (freemarker.template.SimpleDate)2 ContainerUtil.newArrayList (com.intellij.util.containers.ContainerUtil.newArrayList)1 Template (freemarker.template.Template)1 Date (java.util.Date)1 ConstraintViolation (ninja.validation.ConstraintViolation)1