2012-08-14 49 views
0

需要你的帮助!是否可以使用VirtualFile作为HTML模板提供程序?如何?

我希望标题是描述性的,但这里是细节

比方说,我们有5个Web应用程序,并让说,他们正在与5个不同的框架来完成。其中之一是使用playframework。现在,由于所有五个网站的品牌重塑都需要很长时间,所以我们想出了一个布局模板作为HTML页面,其中包含了播放标签。

我们需要使用这种布局,因为它是游戏应用程序源代码的一部分。现在我阅读API文档并找到VirtualFile类(VirtualFile API Docs)。由于文档非常简短,我不能从文档中告诉这个类的目的是什么,但是我看到它包含可能对我的情况有用的功能......

下面是使用.NET运行的同一个类。我之前做过这样的整合,但现在我也需要它在playframework中。还应注意以下链接从zip压缩包投放了例子,但VirtualPathProviders你可以从任何地方 Virtualizing Access to Content

服务模板任何帮助表示赞赏,寿,解决方案并不需要包括VirtualFile,但它必须是塞并玩。

注:我们正在使用playframework 1.2.1

感谢

回答

0

我找到解决我的问题,但不能与虚拟文件类。如果我在游戏中创建自定义标签,那么它可能会是空白,这将取代我的视图中的extend标记。

如果你看一下游戏的源代码,你可以找到我只需要工作 FastTags class, line 319

public static void _extends(Map<?, ?> args, Closure body, PrintWriter out, ExecutableTemplate template, int fromLine) { 
    try { 
     if (!args.containsKey("arg") || args.get("arg") == null) { 
      throw new TemplateExecutionException(template.template, fromLine, "Specify a template name", new TagInternalException("Specify a template name")); 
     } 
     String name = args.get("arg").toString(); 
     if (name.startsWith("./")) { 
      String ct = BaseTemplate.currentTemplate.get().name; 
      if (ct.matches("^/lib/[^/]+/app/views/.*")) { 
       ct = ct.substring(ct.indexOf("/", 5)); 
      } 
      ct = ct.substring(0, ct.lastIndexOf("/")); 
      name = ct + name.substring(1); 
     } 
     BaseTemplate.layout.set((BaseTemplate) TemplateLoader.load(name)); 
    } catch (TemplateNotFoundException e) { 
     throw new TemplateNotFoundException(e.getPath(), template.template, fromLine); 
    } 
} 

如何利用现有的要使用重载的方法TemplateLoader.load(String, String)它接受模板字符串(对比原执行到文件名),然后设置它以 BaseTemplate.layout.set(...)方法。当然,首先我需要通过HTTP请求从远程服务器获取模板。

相关问题