use of com.google.template.soy.soytree.SoyNode.StandaloneNode in project closure-templates by google.
the class InsertMsgsVisitor method replaceMsgNode.
private void replaceMsgNode(MsgFallbackGroupNode node) {
// Check for plural or select message. Either report error or don't replace.
for (MsgNode msg : node.getChildren()) {
if (msg.isPlrselMsg()) {
errorReporter.report(node.getSourceLocation(), ENCOUNTERED_PLURAL_OR_SELECT);
return;
}
}
// Figure out which message we're going to use, and build its list of replacement nodes.
currReplacementNodes = null;
if (msgBundle != null) {
for (MsgNode msg : node.getChildren()) {
SoyMsg translation = msgBundle.getMsg(MsgUtils.computeMsgIdForDualFormat(msg));
if (translation != null) {
buildReplacementNodesFromTranslation(msg, translation);
break;
}
}
}
if (currReplacementNodes == null) {
buildReplacementNodesFromSource(node.getChild(0));
}
// Replace this MsgFallbackGroupNode with the replacement nodes.
ParentSoyNode<StandaloneNode> parent = node.getParent();
int indexInParent = parent.getChildIndex(node);
parent.removeChild(indexInParent);
parent.addChildren(indexInParent, currReplacementNodes);
currReplacementNodes = null;
}
use of com.google.template.soy.soytree.SoyNode.StandaloneNode in project closure-templates by google.
the class MsgUtils method buildMsgPartsForChildren.
// -----------------------------------------------------------------------------------------------
// Private helpers for building the list of message parts.
/**
* Builds the list of SoyMsgParts for all the children of a given parent node.
*
* @param parent Can be MsgNode, MsgPluralCaseNode, MsgPluralDefaultNode, MsgSelectCaseNode, or
* MsgSelectDefaultNode.
* @param msgNode The MsgNode containing 'parent'.
*/
private static ImmutableList<SoyMsgPart> buildMsgPartsForChildren(BlockNode parent, MsgNode msgNode) {
ImmutableList.Builder<SoyMsgPart> msgParts = ImmutableList.builder();
for (StandaloneNode child : parent.getChildren()) {
if (child instanceof RawTextNode) {
String rawText = ((RawTextNode) child).getRawText();
msgParts.add(SoyMsgRawTextPart.of(rawText));
} else if (child instanceof MsgPlaceholderNode) {
PlaceholderInfo placeholder = msgNode.getPlaceholder((MsgPlaceholderNode) child);
msgParts.add(new SoyMsgPlaceholderPart(placeholder.name(), placeholder.example()));
} else if (child instanceof MsgPluralNode) {
msgParts.add(buildMsgPartForPlural((MsgPluralNode) child, msgNode));
} else if (child instanceof MsgSelectNode) {
msgParts.add(buildMsgPartForSelect((MsgSelectNode) child, msgNode));
}
}
return msgParts.build();
}
use of com.google.template.soy.soytree.SoyNode.StandaloneNode in project closure-templates by google.
the class HtmlRewritePass method run.
@Override
public void run(SoyFileNode file, IdGenerator nodeIdGen) {
new Visitor(nodeIdGen, file.getFilePath(), errorReporter).exec(file);
/*
* Validates that the only children of close tags can be {@code phname} attributes.
*
* <p>Later passes validate that phnames for close tags only appear in messages.
*/
for (HtmlCloseTagNode closeTag : SoyTreeUtils.getAllNodesOfType(file, HtmlCloseTagNode.class)) {
List<StandaloneNode> children = closeTag.getChildren();
HtmlAttributeNode phNameAttribute = closeTag.getDirectAttributeNamed(MessagePlaceholders.PHNAME_ATTR);
HtmlAttributeNode phExAttribute = closeTag.getDirectAttributeNamed(MessagePlaceholders.PHEX_ATTR);
// the child at index 0 is the tag name
for (int i = 1; i < children.size(); i++) {
StandaloneNode child = children.get(i);
if (child == phNameAttribute || child == phExAttribute) {
// the phname and phex attributes are validated later and allowed in close nodes
continue;
}
errorReporter.report(child.getSourceLocation(), UNEXPECTED_CLOSE_TAG_CONTENT);
}
}
}
use of com.google.template.soy.soytree.SoyNode.StandaloneNode in project closure-templates by google.
the class HtmlAttributeNode method getStaticContent.
/**
* Returns the static value, if one exists, or null otherwise.
*/
@Nullable
public String getStaticContent() {
if (!hasValue()) {
return null;
}
HtmlAttributeValueNode attrValue = (HtmlAttributeValueNode) getChild(1);
if (attrValue.numChildren() == 0) {
return "";
}
if (attrValue.numChildren() > 1) {
return null;
}
StandaloneNode attrValueNode = attrValue.getChild(0);
if (!(attrValueNode instanceof RawTextNode)) {
return null;
}
return ((RawTextNode) attrValueNode).getRawText();
}
use of com.google.template.soy.soytree.SoyNode.StandaloneNode in project closure-templates by google.
the class HtmlCommentNode method toSourceString.
@Override
public String toSourceString() {
StringBuilder sb = new StringBuilder();
sb.append("<!--");
for (StandaloneNode node : this.getChildren()) {
sb.append(node.toSourceString());
}
sb.append("-->");
return sb.toString();
}
Aggregations