Package net.sf.lapg.templates.api.impl

Examples of net.sf.lapg.templates.api.impl.TemplatesFacade


  }

  public void testOverrides() {
    Hashtable<String,String[]> h = new Hashtable<String,String[]>();
    h.put("list", new String[] { "a", "b" });
    TemplatesFacade env = new TestTemplatesFacade(new DefaultNavigationFactory(),
        new StringTemplateLoader("inline", "${template overrides.my2}go next my2(${call base})\n\n${end}"),
        new ClassTemplateLoader(getClass().getClassLoader(), TEMPLATES_LOCATION, TEMPLATES_CHARSET));
    EvaluationContext context = new EvaluationContext(h);
    context.setVariable("util", new DefaultStaticMethods());

    // test 1
    String q = env.executeTemplate("overrides.my1", context, null, null);
    Assert.assertEquals("my1\n", q);

    // test 2
    q = env.executeTemplate("overrides.my2", context, null, null);
    Assert.assertEquals("go next my2(my2\n)\n\n", q);
  }
View Full Code Here


    Assert.assertEquals("", q);
  }

  public void testFile() {
    final Map<String,String> fileContent = new HashMap<String,String>();
    TemplatesFacade env = new TestTemplatesFacade(new DefaultNavigationFactory(), new ClassTemplateLoader(getClass().getClassLoader(), TEMPLATES_LOCATION, TEMPLATES_CHARSET)) {
      @Override
      public void createFile(String name, String contents) {
        fileContent.put(name, contents);
      }
    };
    EvaluationContext context = new EvaluationContext(new String[] { "aa", "bb" });

    // test 1
    String q = env.executeTemplate("file.file1", context, null, null);
    Assert.assertEquals("", q);
    Assert.assertEquals("Next\n", fileContent.get("aaaa.txt"));
    Assert.assertEquals(1, fileContent.size());
    fileContent.clear();

    // test 2
    q = env.executeTemplate("file.file2", context, null, null);
    Assert.assertEquals("", q);
    Assert.assertEquals(2, fileContent.size());
    Assert.assertEquals("Next\n", fileContent.get("aa.txt"));
    Assert.assertEquals("Next2\n", fileContent.get("bb.txt"));
  }
View Full Code Here

  // switch.ltp
  public void testSwitch() {
    final Map<String,Object> this_ = new HashMap<String,Object>();
    this_.put("aa", new Integer(11));
    TemplatesFacade env = new TestTemplatesFacade(new DefaultNavigationFactory(), new ClassTemplateLoader(getClass().getClassLoader(), TEMPLATES_LOCATION, TEMPLATES_CHARSET));
    EvaluationContext context = new EvaluationContext(this_);

    // test 1
    String q = env.executeTemplate("switch.check1", context, null, null);
    Assert.assertEquals("Yo", q);

    // test 2
    this_.put("aa", "abcd");
    q = env.executeTemplate("switch.check1", context, null, null);
    Assert.assertEquals("Ye", q);

    // test 3
    this_.put("aa", new Integer(12));
    q = env.executeTemplate("switch.check1", context, null, null);
    Assert.assertEquals("No", q);
  }
View Full Code Here

TOP

Related Classes of net.sf.lapg.templates.api.impl.TemplatesFacade

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.