com.mitchellbosecke.pebble.node.FromNode Maven / Gradle / Ivy
Show all versions of pebble Show documentation
package com.mitchellbosecke.pebble.node;
import com.mitchellbosecke.pebble.extension.NodeVisitor;
import com.mitchellbosecke.pebble.node.expression.Expression;
import com.mitchellbosecke.pebble.template.EvaluationContextImpl;
import com.mitchellbosecke.pebble.template.PebbleTemplateImpl;
import com.mitchellbosecke.pebble.utils.Pair;
import java.io.Writer;
import java.util.List;
/**
* From Node for
*
* {% from "templateName" import macroName as alias %}
*
* @author yanxiyue
*/
public class FromNode extends AbstractRenderableNode {
private final Expression> fromExpression;
private final List> namedMacros;
public FromNode(int lineNumber, Expression> fromExpression,
List> namedMacros) {
super(lineNumber);
this.fromExpression = fromExpression;
this.namedMacros = namedMacros;
}
@Override
public void render(PebbleTemplateImpl self, Writer writer, EvaluationContextImpl context) {
String templateName = (String) fromExpression.evaluate(self, context);
self.importNamedMacrosFromTemplate(templateName, namedMacros);
}
@Override
public void accept(NodeVisitor visitor) {
visitor.visit(this);
}
}