use of com.google.template.soy.soytree.MsgPlaceholderNode in project closure-templates by google.
the class MsgCompiler method putPlaceholderIntoMap.
private void putPlaceholderIntoMap(Expression mapExpression, MsgNode originalMsg, Map<String, Statement> placeholderNameToPutStatement, SoyMsgPlaceholderPart placeholder) throws AssertionError {
String placeholderName = placeholder.getPlaceholderName();
if (!placeholderNameToPutStatement.containsKey(placeholderName)) {
MsgPlaceholderNode repPlaceholderNode = originalMsg.getRepPlaceholderNode(placeholder.getPlaceholderName());
if (repPlaceholderNode.numChildren() == 0) {
throw new IllegalStateException("empty rep node for: " + placeholderName);
}
StandaloneNode initialNode = repPlaceholderNode.getChild(0);
Statement putEntyInMap;
if (initialNode instanceof MsgHtmlTagNode) {
putEntyInMap = addHtmlTagNodeToPlaceholderMap(mapExpression, placeholderName, (MsgHtmlTagNode) initialNode);
} else if (initialNode instanceof CallNode) {
putEntyInMap = addCallNodeToPlaceholderMap(mapExpression, placeholderName, (CallNode) initialNode);
} else if (initialNode instanceof PrintNode) {
putEntyInMap = addPrintNodeToPlaceholderMap(mapExpression, placeholderName, (PrintNode) initialNode);
} else if (initialNode instanceof RawTextNode) {
putEntyInMap = addRawTextNodeToPlaceholderMap(mapExpression, placeholderName, (RawTextNode) initialNode);
} else {
// the AST for MsgNodes guarantee that these are the only options
throw new AssertionError("Unexpected child: " + initialNode.getClass());
}
placeholderNameToPutStatement.put(placeholder.getPlaceholderName(), putEntyInMap.withSourceLocation(repPlaceholderNode.getSourceLocation()));
}
}
use of com.google.template.soy.soytree.MsgPlaceholderNode in project closure-templates by google.
the class UnescapingVisitor method visitRawTextNode.
@Override
protected void visitRawTextNode(RawTextNode node) {
if (node.getHtmlContext() != HtmlContext.HTML_PCDATA && node.getHtmlContext() != HtmlContext.HTML_NORMAL_ATTR_VALUE) {
return;
}
// Don't unescape the raw translated text nodes within an {msg} tag. Do escape text nodes which
// are nested in placeholders inside {msg} tags (since they aren't directly translated). Unless
// they're further in {msg} tags that are nested in placeholders. Don't worry; we've got tests!
MsgFallbackGroupNode containingMsg = node.getNearestAncestor(MsgFallbackGroupNode.class);
if (containingMsg != null) {
MsgPlaceholderNode containingPlaceholder = node.getNearestAncestor(MsgPlaceholderNode.class);
// Unless we're _directly_ in a placeholder.
if (containingPlaceholder == null || !SoyTreeUtils.isDescendantOf(containingPlaceholder, containingMsg)) {
return;
}
}
node.getParent().replaceChild(node, new RawTextNode(node.getId(), UnescapeUtils.unescapeHtml(node.getRawText()), node.getSourceLocation(), node.getHtmlContext()));
}
use of com.google.template.soy.soytree.MsgPlaceholderNode in project closure-templates by google.
the class SimplifyVisitorTest method testMsgBlockNodeChildrenAreNotReplaced.
@Test
public void testMsgBlockNodeChildrenAreNotReplaced() throws Exception {
String soyFileContent = "{namespace boo}\n" + "\n" + "{template .foo}\n" + "\n" + " {msg desc=\"\"}\n" + " blah\n" + " {'blah'}\n" + " blah\n" + " {call .aaa /}\n" + " blah\n" + " <div class=\"{call .aaa /}\">\n" + " </div>\n" + " blah\n" + " {/msg}\n" + "{/template}\n" + "\n" + "/***/\n" + "{template .aaa}\n" + " blah\n" + "{/template}";
MsgNode msgNode = ((MsgFallbackGroupNode) simplifySoyFiles(soyFileContent).getChild(0).getChild(0).getChild(0)).getChild(0);
assertThat(msgNode.numChildren()).isEqualTo(8);
// The MsgPlaceholderNode children are not replaced.
assertThat(msgNode.getChild(1)).isInstanceOf(MsgPlaceholderNode.class);
assertThat(msgNode.getChild(3)).isInstanceOf(MsgPlaceholderNode.class);
assertThat(msgNode.getChild(5)).isInstanceOf(MsgPlaceholderNode.class);
assertThat(msgNode.getChild(6)).isInstanceOf(MsgPlaceholderNode.class);
// But the contents within the MsgPlaceholderNode children can be replaced.
assertThat(((MsgPlaceholderNode) msgNode.getChild(1)).getChild(0)).isInstanceOf(RawTextNode.class);
}
Aggregations