rythmengine / rythmengine

A "Razor" like, rich featured, high performance and easy to use Java template engine
http://www.rythmengine.org
Apache License 2.0
251 stars 65 forks source link

Problem using Rythm.render(File,Map) --> CompileException [variable name] cannot be resolved to a variable. #291

Open adaviding opened 9 years ago

adaviding commented 9 years ago

Please help.

I am using the Rythm engine as suggested in one of the HelloWorld examples shown here: http://rythmengine.org/doc/tutorial.md#env

I get an error when running the last line of the unit test.

    @Test
    public void testZookeeperRythm2()
    {
        String appFolder = Application.detectAppFolder().getAbsoluteFile() + "/";
        //  Rythm requires a Map or a JSONWrapper.  Both techniques yielded the same error.
        HashMap<String,Object> map = new HashMap<String,Object>();
        map.put("tickTime", "2000");
        //  ... insert a bunch of other map.put statements here ... //
        //  The "zoo.cfg.rythm" file.
        String templateFile = appFolder+"installer/zookeeper/zoo.cfg.rythm";
        //  This line generates the error
        String renderedString = Rythm.render(new File(templateFile), map);
    }

I am definitely creating the Map correctly. I am attaching the templateFile that was used as zoo.cfg.rythm.txt. An exception gets thrown on line 343 of TemplateClass.java (screenshot templateclass).

Here is the exception:

org.rythmengine.exception.CompileException: tickTime cannot be resolved to a variable

Template: C:/Dev/bs/data-tools/data-tools/bsquare-app/AppFolder/installer/zookeeper/zoo.cfg.rythm

Relevant template source lines:
-------------------------------------------------
>> 1: tickTime=@tickTime
   2: initLimit=@initLimit
   3: syncLimit=@syncLimit
   4: dataDir=@appDataFolder
   5: clientPort=@clientPort
   6: autopurge.snapRetainCount=@autoPurgeSnapRetainCount
   7: autopurge.purgeInterval=@autoPurgeInterval

Relevant Java source lines:
-------------------------------------------------
   44: 
   45:  @Override public org.rythmengine.utils.TextBuilder build(){
   46:      buffer().ensureCapacity(201);
   47: p("tickTime="); //line: 1
   48: 
>> 49: try{pe(tickTime);} catch (RuntimeException e) {__handleTemplateExecutionException(e);}  //line: 1
   50: p("\ninitLimit="); //line: 2
   51: 
   52: try{pe(initLimit);} catch (RuntimeException e) {__handleTemplateExecutionException(e);}  //line: 2
   53: p("\nsyncLimit="); //line: 3
   54: 
   55: try{pe(syncLimit);} catch (RuntimeException e) {__handleTemplateExecutionException(e);}  //line: 3
adaviding commented 9 years ago

Nevermind, I just fixed this issue. I didn't have an "@args" line at the top of my template file. So now I am very impressed with Rythm.

greenlaw110 commented 9 years ago

It should automatically declare tickTime as java.lang.Object if you don't have @args statement. So it's still an issue I need to look into