Search in sources :

Example 11 with TemplateNode

use of com.google.template.soy.soytree.TemplateNode in project closure-templates by google.

the class FindIjParamsVisitor method exec.

/**
 * Computes injected params info for a template.
 *
 * <p>Note: This method is not thread-safe. If you need to get injected params info in a
 * thread-safe manner, then please use {@link #execOnAllTemplates}() in a thread-safe manner.
 */
public IjParamsInfo exec(TemplateNode rootTemplate) {
    TransitiveDepTemplatesInfo depsInfo = findTransitiveDepTemplatesVisitor.exec(rootTemplate);
    if (!depsInfoToIjParamsInfoMap.containsKey(depsInfo)) {
        ImmutableMultimap.Builder<String, TemplateNode> ijParamToCalleesMultimapBuilder = ImmutableMultimap.builder();
        for (TemplateNode template : depsInfo.depTemplateSet) {
            if (!templateToLocalIjParamsMap.containsKey(template)) {
                templateToLocalIjParamsMap.put(template, getAllIjs(template));
            }
            for (String localIjParam : templateToLocalIjParamsMap.get(template)) {
                ijParamToCalleesMultimapBuilder.put(localIjParam, template);
            }
            for (TemplateParam injectedParam : template.getInjectedParams()) {
                ijParamToCalleesMultimapBuilder.put(injectedParam.name(), template);
            }
        }
        IjParamsInfo ijParamsInfo = new IjParamsInfo(ijParamToCalleesMultimapBuilder.build());
        depsInfoToIjParamsInfoMap.put(depsInfo, ijParamsInfo);
    }
    return depsInfoToIjParamsInfoMap.get(depsInfo);
}
Also used : TemplateNode(com.google.template.soy.soytree.TemplateNode) TransitiveDepTemplatesInfo(com.google.template.soy.passes.FindTransitiveDepTemplatesVisitor.TransitiveDepTemplatesInfo) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) TemplateParam(com.google.template.soy.soytree.defn.TemplateParam)

Example 12 with TemplateNode

use of com.google.template.soy.soytree.TemplateNode in project closure-templates by google.

the class CheckTemplateVisibility method visitCallBasicNode.

@Override
protected void visitCallBasicNode(CallBasicNode node) {
    visitChildren(node);
    String calleeName = node.getCalleeName();
    TemplateNode definition = templateRegistry.getBasicTemplate(calleeName);
    if (definition != null && !isVisible(node, definition)) {
        errorReporter.report(node.getSourceLocation(), CALLEE_NOT_VISIBLE, calleeName, definition.getVisibility().getAttributeValue(), definition.getParent().getFilePath());
    }
}
Also used : TemplateNode(com.google.template.soy.soytree.TemplateNode)

Example 13 with TemplateNode

use of com.google.template.soy.soytree.TemplateNode in project closure-templates by google.

the class RenderVisitor method visitCallBasicNode.

@Override
protected void visitCallBasicNode(CallBasicNode node) {
    TemplateNode callee = templateRegistry.getBasicTemplate(node.getCalleeName());
    if (callee == null) {
        throw RenderException.createWithSource("Attempting to render undefined template '" + node.getCalleeName() + "'.", node);
    }
    visitCallNodeHelper(node, callee);
}
Also used : TemplateNode(com.google.template.soy.soytree.TemplateNode)

Example 14 with TemplateNode

use of com.google.template.soy.soytree.TemplateNode in project closure-templates by google.

the class BaseTofu method renderMainHelper.

/**
 * Renders a template and appends the result to a StringBuilder.
 *
 * @param templateRegistry A registry of all templates.
 * @param outputBuf The Appendable to append the rendered text to.
 * @param templateName The full name of the template to render.
 * @param data The data to call the template with. Can be null if the template has no parameters.
 * @param ijData The injected data to call the template with. Can be null if not used.
 * @param activeDelPackageNames The set of active delegate package names.
 * @param msgBundle The bundle of translated messages, or null to use the messages from the Soy
 *     source.
 * @param cssRenamingMap Map for renaming selectors in 'css' tags, or null if not used.
 * @return The template that was rendered.
 */
private TemplateNode renderMainHelper(TemplateRegistry templateRegistry, Appendable outputBuf, String templateName, @Nullable SoyRecord data, @Nullable SoyRecord ijData, Predicate<String> activeDelPackageNames, @Nullable SoyMsgBundle msgBundle, @Nullable SoyIdRenamingMap idRenamingMap, @Nullable SoyCssRenamingMap cssRenamingMap, boolean debugSoyTemplateInfo) {
    TemplateNode template = templateRegistry.getBasicTemplate(templateName);
    if (template == null) {
        throw new SoyTofuException("Attempting to render undefined template '" + templateName + "'.");
    } else if (template.getVisibility() == Visibility.PRIVATE) {
        throw new SoyTofuException("Attempting to render private template '" + templateName + "'.");
    }
    if (data == null) {
        data = SoyValueConverter.EMPTY_DICT;
    }
    if (ijData == null) {
        ijData = SoyValueConverter.EMPTY_DICT;
    }
    try {
        RenderVisitor rv = new RenderVisitor(new EvalVisitorFactoryImpl(), outputBuf, templateRegistry, data, ijData, activeDelPackageNames, msgBundle, idRenamingMap, cssRenamingMap, debugSoyTemplateInfo);
        rv.exec(template);
    } catch (RenderException re) {
        throw new SoyTofuException(re);
    }
    return template;
}
Also used : TemplateNode(com.google.template.soy.soytree.TemplateNode) SoyTofuException(com.google.template.soy.tofu.SoyTofuException) RenderException(com.google.template.soy.sharedpasses.render.RenderException) EvalVisitorFactoryImpl(com.google.template.soy.sharedpasses.render.EvalVisitorFactoryImpl) RenderVisitor(com.google.template.soy.sharedpasses.render.RenderVisitor)

Example 15 with TemplateNode

use of com.google.template.soy.soytree.TemplateNode in project closure-templates by google.

the class SourceLocationTest method testAdditionalSourceLocationInfo.

@Test
public void testAdditionalSourceLocationInfo() throws Exception {
    String template = JOINER.join("{namespace ns}", "{template .t}", "  hello, world", "{/template}");
    TemplateNode templateNode = SoyFileSetParserBuilder.forFileContents(template).parse().fileSet().getChild(0).getChild(0);
    SourceLocation location = templateNode.getSourceLocation();
    // Begin at {template
    assertEquals(2, location.getBeginLine());
    assertEquals(1, location.getBeginColumn());
    // End after .t}
    assertEquals(2, location.getEndLine());
    assertEquals(13, location.getEndColumn());
}
Also used : TemplateNode(com.google.template.soy.soytree.TemplateNode) SourceLocation(com.google.template.soy.base.SourceLocation) Test(org.junit.Test)

Aggregations

TemplateNode (com.google.template.soy.soytree.TemplateNode)89 Test (org.junit.Test)59 SoyFileSetNode (com.google.template.soy.soytree.SoyFileSetNode)35 TemplateRegistry (com.google.template.soy.soytree.TemplateRegistry)19 ErrorReporter (com.google.template.soy.error.ErrorReporter)11 ParseResult (com.google.template.soy.SoyFileSetParser.ParseResult)10 TransitiveDepTemplatesInfo (com.google.template.soy.passes.FindTransitiveDepTemplatesVisitor.TransitiveDepTemplatesInfo)9 RawTextNode (com.google.template.soy.soytree.RawTextNode)9 SoyFileNode (com.google.template.soy.soytree.SoyFileNode)8 TemplateParam (com.google.template.soy.soytree.defn.TemplateParam)7 FunctionNode (com.google.template.soy.exprtree.FunctionNode)6 PrintNode (com.google.template.soy.soytree.PrintNode)5 TemplateDelegateNode (com.google.template.soy.soytree.TemplateDelegateNode)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 SourceLocation (com.google.template.soy.base.SourceLocation)4 StringNode (com.google.template.soy.exprtree.StringNode)4 MsgFallbackGroupNode (com.google.template.soy.soytree.MsgFallbackGroupNode)4 ImmutableList (com.google.common.collect.ImmutableList)3 VarRefNode (com.google.template.soy.exprtree.VarRefNode)3 SoyMsgBundle (com.google.template.soy.msgs.SoyMsgBundle)3