Package net.sf.laja.template

Examples of net.sf.laja.template.Macro


  @Override
  public ILocal createLocal(ITemplate itemplate, IMacro imacro, IFunction ifunction) {
    if (imacro == null && ifunction == null) {
      throw new LajaException("#local variables can not exist outside a #macro or #function body.");
    }
    Macro macro = (Macro) imacro;

    if (macro == null) {
      macro = (Macro) ifunction;
    }
    return new Set(source, namespaces, templateTextWriter, macro, macro.getLocalContext());
  }
View Full Code Here


  }

  @Override
  public IMacro createMacro(ITemplate itemplate) {
    Template template = (Template) itemplate;
    return new Macro(false, source, namespaces, templateTextWriter, template.getContext());
  }
View Full Code Here

  }

  @Override
  public IFunction createFunction(ITemplate itemplate) {
    Template template = (Template) itemplate;
    return new Macro(true, source, namespaces, templateTextWriter, template.getContext());
  }
View Full Code Here

 
  private boolean isMacro(Context context, boolean isFunction) {
    if (!isMethodRef()) {
      return false;
    }
    Macro macro = getMacro(context);
   
   
    return macro != null && macro.isFunction() == isFunction;
  }
View Full Code Here

   
    return macro != null && macro.isFunction() == isFunction;
  }
 
  public Macro getMacro(Context context) {
    Macro macro = context.getMacro(getMethodName());
   
    if (macro == null && !namespaces.isDefaultNamespace(context)) {
      // If macro not found in specified namespace, also look in default namespace
      macro = namespaces.getDefaultNamespace().getMacro(getMethodName());
    }   
View Full Code Here

    return context.evaluate(attributeRef);
  }

  private Object getResultFromCurrentOrDefaultNamespace() {
    if (attributeRef.isMethodRef()) {
      Macro macro = context.getMacro(attributeRef.getMethodName());
     
      if (macro == null && !namespaces.isDefaultNamespace(context)) {
        return namespaces.getDefaultNamespace().evaluateMacro(attributeRef);
      }
     
View Full Code Here

 
  protected Object generateMacro() {
    if (nextAttributeRefs.hasAttributes()) {
      throw new InterpretationException(source, indexInSource, "Accessing attributes or methods on macros not supported. Use #set or #function");
    }
    Macro macro = attributeRef.getMacro(getContext());

    if (macro == null) {
      throw new InterpretationException(source, indexInSource, "Could not find macro '" + attributeRef.getMethodName() + "'");
    }
   
    if (attributeRef.hasMethodArguments()) {
      macro.populateDataArguments(attributeRef.getMethodArguments().getArguments());
    }

    if (macro.getBlock() != null) {
      macro.getBlock().generate();
    }
    return null;
  }
View Full Code Here

    }
    return null;
  }

  protected Object evaluateFunction() {
    Macro macro = attributeRef.getMacro(getContext());

    if (macro == null) {
      throw new InterpretationException(source, indexInSource, "Could not find macro '" + attributeRef.getMethodName() + "'");
    }
   
    if (attributeRef.hasMethodArguments()) {
      macro.populateDataArguments(attributeRef.getMethodArguments().getArguments());
    }

    if (macro.getBlock() == null) {
       throw new InterpretationException(source, indexInSource, "Missing return statement for function '" + macro.getName() + "'");
    }
    Object attribute = macro.getBlock().generate();
   
    if (!macro.getBlock().hasReturnBeenExecuted()) {
      throw new LajaException("No value was returned from macro '" + macro.getName() + "'");
    }

    attribute = evaluateExceptionAndListIndex(attribute);
    return nextAttributeRefs.evaluateNextAttributes(getContext(), attribute);
  }
View Full Code Here

    return result;
  }

  public Object evaluateMacro(AttributeRef attributeRef) {
    Macro macro = getMacro(attributeRef.getMethodName());

    if (macro == null) {
      throw new LajaException("Could not find macro '" + attributeRef.getMethodName() + "'");
    }

    getTemplateTextWriter().pushTextWriter();

    if (attributeRef.getMethodArguments() != null) {
      macro.populateDataArguments(attributeRef.getMethodArguments().getArguments());
    }

    Object result = null;

    if (macro.getBlock() != null) {
      if (macro.isFunction()) {
        if (macro.getBlock() == null) {
          throw new LajaException("Missing return statement for function '" + macro.getName() + "'");
        } else {
          result = macro.getBlock().generate();
          if (!macro.getBlock().hasReturnBeenExecuted()) {
            throw new LajaException("No value was returned from macro '" + macro.getName() + "'");
          }
          getTemplateTextWriter().popTextWriter();
          return result;
        }
      } else {
        macro.getBlock().generate();
        result = getTemplateTextWriter().popTextWriter();
      }
    }

    return result;
View Full Code Here

TOP

Related Classes of net.sf.laja.template.Macro

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.