use of com.google.template.soy.shared.restricted.SoyPrintDirective in project closure-templates by google.
the class PluginResolver method lookupPrintDirective.
/**
* Returns a print directive with the given name and arity.
*
* <p>An error will be reported according to the current {@link Mode} and a placeholder function
* will be returned if it cannot be found.
*/
public SoyPrintDirective lookupPrintDirective(String name, int numArgs, SourceLocation location) {
SoyPrintDirective soyPrintDirective = printDirectives.get(name);
if (soyPrintDirective == null) {
if (mode == Mode.REQUIRE_DEFINITIONS || mode == Mode.ALLOW_UNDEFINED_FUNCTIONS_FOR_V1_SUPPORT) {
reporter.report(location, UNKNOWN_PLUGIN, "print directive", name, SoyErrors.getDidYouMeanMessage(printDirectives.keySet(), name));
}
soyPrintDirective = createPlaceholderPrintDirective(name, numArgs);
}
checkNumArgs("print directive", soyPrintDirective.getValidArgsSizes(), numArgs, location);
warnIfDeprecated(name, soyPrintDirective, location);
return soyPrintDirective;
}
use of com.google.template.soy.shared.restricted.SoyPrintDirective in project closure-templates by google.
the class SoyFileSetParserBuilder method addPrintDirectives.
public SoyFileSetParserBuilder addPrintDirectives(Iterable<? extends SoyPrintDirective> soyPrintDirectives) {
Map<String, SoyPrintDirective> directives = new LinkedHashMap<>();
directives.putAll(soyPrintDirectiveMap);
for (SoyPrintDirective printDirective : soyPrintDirectives) {
directives.put(printDirective.getName(), printDirective);
}
this.soyPrintDirectiveMap = ImmutableMap.copyOf(directives);
return this;
}
use of com.google.template.soy.shared.restricted.SoyPrintDirective in project closure-templates by google.
the class SharedModuleTest method testBuiltinPluginsSupportAllBackends.
@Test
public void testBuiltinPluginsSupportAllBackends() throws Exception {
for (SoyPrintDirective directive : injector.getInstance(new Key<Set<SoyPrintDirective>>() {
})) {
assertThat(directive).isInstanceOf(SoyJsSrcPrintDirective.class);
assertThat(directive).isInstanceOf(SoyJavaPrintDirective.class);
assertThat(directive).isInstanceOf(SoyJbcSrcPrintDirective.class);
if (!PYSRC_DIRECTIVE_BLACKLIST.contains(directive.getName())) {
assertThat(directive).isInstanceOf(SoyPySrcPrintDirective.class);
}
}
}
use of com.google.template.soy.shared.restricted.SoyPrintDirective in project closure-templates by google.
the class GenJsExprsVisitor method visitPrintNode.
/**
* Example:
* <pre>
* {$boo.foo}
* {$goo.moo + 5}
* </pre>
* might generate
* <pre>
* opt_data.boo.foo
* gooData4.moo + 5
* </pre>
*/
@Override
protected void visitPrintNode(PrintNode node) {
CodeChunk.WithValue expr = translateExpr(node.getExpr());
// Process directives.
for (PrintDirectiveNode directiveNode : node.getChildren()) {
// Get directive.
SoyPrintDirective directive = directiveNode.getPrintDirective();
if (!(directive instanceof SoyJsSrcPrintDirective)) {
errorReporter.report(node.getSourceLocation(), UNKNOWN_SOY_JS_SRC_PRINT_DIRECTIVE, directiveNode.getName());
return;
}
// Get directive args.
List<ExprRootNode> argNodes = directiveNode.getArgs();
// Convert args to CodeChunks.
List<CodeChunk.WithValue> argChunks = new ArrayList<>(argNodes.size());
for (ExprRootNode argNode : argNodes) {
argChunks.add(translateExpr(argNode));
}
// Apply directive.
expr = SoyJsPluginUtils.applyDirective(translationContext.codeGenerator(), expr, (SoyJsSrcPrintDirective) directive, argChunks);
}
chunks.add(expr);
}
use of com.google.template.soy.shared.restricted.SoyPrintDirective in project closure-templates by google.
the class GenJsCodeVisitorAssistantForMsgs method generateMsgGroupVariable.
/**
* Returns a code chunk representing a translated variable.
*
* <p>Example:
*
* <pre>
* {msg desc="Link to help content."}Learn more{/msg}
* {msg desc="Tells user how to access a product." hidden="true"}
* Click <a href="}{$url}">here</a> to access {$productName}.
* {/msg}
* </pre>
*
* might return the following code chunk:
*
* <pre>
* /** @desc Link to help content. *{@literal /}
* var MSG_UNNAMED_9 = goog.getMsg('Learn more');
* var msg_s9 = MSG_UNNAMED_9;
* /** @desc Tells user how to access a product.
* * @hidden *{@literal /}
* var MSG_UNNAMED_10 = goog.getMsg(
* 'Click {$startLink}here{$endLink} to access {$productName}.',
* {startLink: '<a href="' + opt_data.url + '">',
* endLink: '</a>',
* productName: opt_data.productName});
* </pre>
*/
public CodeChunk.WithValue generateMsgGroupVariable(MsgFallbackGroupNode node) {
String tmpVarName = translationContext.nameGenerator().generateName("msg_s");
CodeChunk.WithValue msg;
if (node.numChildren() == 1) {
translationContext.soyToJsVariableMappings().setIsPrimaryMsgInUse(node, CodeChunk.WithValue.LITERAL_TRUE);
msg = generateSingleMsgVariable(node.getChild(0), tmpVarName);
} else {
// has fallbackmsg children
msg = generateMsgGroupVariable(node, tmpVarName);
}
// handle escaping
for (SoyPrintDirective printDirective : node.getEscapingDirectives()) {
msg = SoyJsPluginUtils.applyDirective(translationContext.codeGenerator(), msg, (SoyJsSrcPrintDirective) printDirective, /* args= */
ImmutableList.<CodeChunk.WithValue>of());
}
return msg;
}
Aggregations