示例#1
0
 @Override
 public final void emit(EmitContext context, Template<ASTNode.Template> template)
     throws TemplateException, IOException {
   GroovyTemplateEmitter emitter = new GroovyTemplateEmitter(template.getAbsolutePath().getName());
   EmitPhase tcc = new EmitPhase(context);
   tcc.emit(emitter, template.getModel());
   context.createResource(
       template.getRelativePath().getRawName() + "_", "groovy", emitter.toString());
 }
示例#2
0
  @Override
  public void process(
      final ProcessContext context, final Template<MustacheContext> mustacheTemplate) {
    // Nothing to do for now

    // Visit the mustache
    MustacheFactory factory =
        new DefaultMustacheFactory() {

          @Override
          public Reader getReader(String resourceName) {
            Path.Relative partialPath = (Path.Relative) Path.parse(resourceName);
            Template<MustacheContext> partial =
                (Template<MustacheContext>)
                    context.resolveTemplate(mustacheTemplate.getOrigin(), partialPath);
            if (partial != null) {
              return new StringReader(partial.getModel().source);
            } else {
              return null;
            }
          }

          public MustacheVisitor createMustacheVisitor() {
            return new DefaultMustacheVisitor(this) {
              @Override
              public void pragma(TemplateContext templateContext, String pragma, String args) {
                if ("param".equals(pragma)) {
                  mustacheTemplate.addParameter(args);
                } else {
                  super.pragma(templateContext, pragma, args);
                }
              }
            };
          }
        };

    // Does the name count ?
    factory.compile(
        new StringReader(mustacheTemplate.getModel().source),
        mustacheTemplate.getRelativePath().getSimpleName());
  }