Search in sources :

Example 41 with JapidTemplate

use of cn.bran.japid.template.JapidTemplate in project Japid by branaway.

the class CompilerTests method testIfindef.

@Test
public void testIfindef() throws IOException, ParseException {
    String src = readFile("tests/ifindef.html");
    JapidTemplate bt = new JapidTemplate("tests/ifindef.html", src);
    JapidAbstractCompiler cp = new JapidTemplateCompiler();
    cp.compile(bt);
    String srcCode = bt.javaSource;
    //		System.out.println(srcCode);
    assertTrue(!srcCode.contains("_if"));
}
Also used : JapidAbstractCompiler(cn.bran.japid.compiler.JapidAbstractCompiler) JapidTemplate(cn.bran.japid.template.JapidTemplate) JapidTemplateCompiler(cn.bran.japid.compiler.JapidTemplateCompiler) Test(org.junit.Test)

Example 42 with JapidTemplate

use of cn.bran.japid.template.JapidTemplate in project Japid by branaway.

the class CompilerTests method testIfCommand.

@Test
public void testIfCommand() throws IOException {
    String src = readFile("JapidSample/app/japidviews/Application/ifs.html");
    JapidTemplate bt = new JapidTemplate("Application/ifs.html", src);
    JapidAbstractCompiler cp = new JapidLayoutCompiler();
    cp.compile(bt);
    String javaSource = bt.javaSource;
    System.out.println(javaSource);
    assertTrue(javaSource.contains("if(!asBoolean(ss))"));
    assertTrue(javaSource.contains("else if(!asBoolean(ss))"));
    assertTrue("invalid java code", JavaSyntaxTool.isValid(javaSource));
}
Also used : JapidAbstractCompiler(cn.bran.japid.compiler.JapidAbstractCompiler) JapidTemplate(cn.bran.japid.template.JapidTemplate) JapidLayoutCompiler(cn.bran.japid.compiler.JapidLayoutCompiler) Test(org.junit.Test)

Example 43 with JapidTemplate

use of cn.bran.japid.template.JapidTemplate in project Japid by branaway.

the class CompilerTests method testActionInvocation.

@Test
public void testActionInvocation() throws IOException {
    String src = readFile("tests/actions.html");
    JapidTemplate bt = new JapidTemplate("tests/actions.html", src);
    JapidAbstractCompiler cp = new JapidTemplateCompiler();
    cp.compile(bt);
    String source = bt.javaSource;
    System.out.println(source);
    assertTrue("invalid java code", JavaSyntaxTool.isValid(source));
    assertTrue(source.contains("MyController.foo()"));
    assertTrue(source.contains("MyController.bar()"));
}
Also used : JapidAbstractCompiler(cn.bran.japid.compiler.JapidAbstractCompiler) JapidTemplate(cn.bran.japid.template.JapidTemplate) JapidTemplateCompiler(cn.bran.japid.compiler.JapidTemplateCompiler) Test(org.junit.Test)

Example 44 with JapidTemplate

use of cn.bran.japid.template.JapidTemplate in project japid42 by branaway.

the class JapidTemplateTransformer method generate.

/**
	 * 
	 * @param fileName
	 *            the relative path of the template file from the source folder,
	 *            e.g., "my/path/mytemplate.html", which maps to
	 *            my.path.mytemplate.java
	 * @return
	 * @throws Exception
	 */
public File generate(String fileName) throws Exception {
    String realSrcFile = sourceFolder == null ? fileName : sourceFolder + "/" + fileName;
    String src = DirUtil.readFileAsString(realSrcFile);
    JapidTemplate temp = new JapidTemplate(fileName, src);
    JapidAbstractCompiler c = selectCompiler(src);
    c.setUseWithPlay(usePlay);
    c.compile(temp);
    String jsrc = temp.javaSource;
    String fileNameRoot = DirUtil.mapSrcToJava(fileName);
    String target = targetFolder == null ? sourceFolder : targetFolder;
    String realTargetFile = target == null ? fileNameRoot : target + "/" + fileNameRoot;
    File f = DirUtil.writeToFile(jsrc, realTargetFile);
    return f;
}
Also used : JapidTemplate(cn.bran.japid.template.JapidTemplate) File(java.io.File)

Aggregations

JapidTemplate (cn.bran.japid.template.JapidTemplate)44 JapidAbstractCompiler (cn.bran.japid.compiler.JapidAbstractCompiler)39 Test (org.junit.Test)39 JapidTemplateCompiler (cn.bran.japid.compiler.JapidTemplateCompiler)29 CompilationUnit (japa.parser.ast.CompilationUnit)12 JapidLayoutCompiler (cn.bran.japid.compiler.JapidLayoutCompiler)10 TagIf (cn.bran.japid.compiler.Tag.TagIf)2 TagInTag (cn.bran.japid.compiler.Tag.TagInTag)2 File (java.io.File)2 Matcher (java.util.regex.Matcher)2 JapidCompilationException (cn.bran.japid.compiler.JapidCompilationException)1 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 InputStreamReader (java.io.InputStreamReader)1 CategorizedProblem (org.eclipse.jdt.core.compiler.CategorizedProblem)1 IProblem (org.eclipse.jdt.core.compiler.IProblem)1 ClassFile (org.eclipse.jdt.internal.compiler.ClassFile)1