Setting up a default template path using Scalate with Spring

124 views
Skip to first unread message

Jon Wu

unread,
Jan 10, 2014, 11:11:42 PM1/10/14
to sca...@googlegroups.com
Hi,

I've been using Scalate with Spring but without using scalate-spring-mvc. Now I'm setting up a ScalateViewResolver in my Spring config but I'm not sure how to set template directories which is making all my paths in templates broken.

How can I set template directories when setting up my Spring config?

While setting the prefix below allows Scalate to locate the initial template, I was previously relying on /WEB-INF/templates/ to be in the template search path before so all my partials are included already with that in mind.

Here's what I tried:

  @Bean
  public ScalateViewResolver scalateView() {
    ScalateViewResolver res = new ScalateViewResolver();
    final scala.collection.immutable.List<File> templateDirectories = JavaConversions.asScalaBuffer(ImmutableList.of(new File("/WEB-INF/templates/"))).toList();
    res.templateEngine().apply(templateDirectories, "development");
    res.setPrefix("/WEB-INF/templates/");
    res.setSuffix(".jade");
    return res;
  }

I also tried the following but got a NPE:

scalateViewResolver.templateEngine().templateDirectories_$eq(JavaConversions.asScalaBuffer(ImmutableList.of("/WEB-INF/templates/")).toList());

Thanks for your help!
Jon

Jon Wu

unread,
Jan 13, 2014, 9:13:23 PM1/13/14
to sca...@googlegroups.com
After playing some more I think I'm going at this all wrong. I setup a Boot.scala instead and that seems to be closer but I'm still not sure how to change the source directories.

Before I had some code like this:

TemplateEngineFacade engineFacade = new TemplateEngineFacade();
engineFacade.setSourceDirectories(ImmutableList.of(new File("webapps/ROOT/WEB-INF/templates/")));

Issues:

1. My templates are in WEB-INF/templates of course, so how do I make that the source directory location when using Scalate with Spring?

2. More importantly (because I have no workaround), how and where do I configure number format for all templates rendered by Scalate through Spring? Can I set that up globally?

Before I had something like this but I was running that when calling layout explicitly:

    final DefaultRenderContext context = new DefaultRenderContext(fullUri, ENGINE, new PrintWriter(buffer));
    final DecimalFormat df = new DecimalFormat();
    df.setGroupingUsed(false);
    context.numberFormat_$eq(df);

Thanks!
Reply all
Reply to author
Forward
0 new messages