use of com.google.template.soy.soytree.MsgHtmlTagNode in project closure-templates by google.
the class TemplateParserTest method testParseMsgHtmlTagWithPhname.
@Test
public void testParseMsgHtmlTagWithPhname() throws Exception {
String templateBody = "{@param learnMoreUrl :?}\n" + " {msg desc=\"\"}\n" + " <a href=\"{$learnMoreUrl}\" phname=\"beginLearnMoreLink\">\n" + " Learn more\n" + " </A phname=\"end_LearnMore_LINK\">\n" + " <br phname=\"breakTag\" /><br phname=\"breakTag\" />" + "<br phname=\"break_tag\" />\n" + " {/msg}\n";
List<StandaloneNode> nodes = parseTemplateContent(templateBody, FAIL).getChildren();
assertEquals(1, nodes.size());
MsgNode mn0 = ((MsgFallbackGroupNode) nodes.get(0)).getChild(0);
assertEquals(6, mn0.numChildren());
MsgPlaceholderNode mpn0 = (MsgPlaceholderNode) mn0.getChild(0);
MsgHtmlTagNode mhtn0 = (MsgHtmlTagNode) mpn0.getChild(0);
assertEquals("a", mhtn0.getLcTagName());
assertEquals("BEGIN_LEARN_MORE_LINK", mhtn0.genBasePhName());
assertEquals("<a href=\"{$learnMoreUrl}\" phname=\"beginLearnMoreLink\">", mhtn0.toSourceString());
MsgPlaceholderNode mpn2 = (MsgPlaceholderNode) mn0.getChild(2);
MsgHtmlTagNode mhtn2 = (MsgHtmlTagNode) mpn2.getChild(0);
assertEquals("/a", mhtn2.getLcTagName());
assertEquals("END_LEARN_MORE_LINK", mhtn2.genBasePhName());
assertEquals("</A phname=\"end_LearnMore_LINK\">", mhtn2.toSourceString());
MsgPlaceholderNode mpn3 = (MsgPlaceholderNode) mn0.getChild(3);
MsgHtmlTagNode mhtn3 = (MsgHtmlTagNode) mpn3.getChild(0);
assertEquals("br", mhtn3.getLcTagName());
assertEquals("BREAK_TAG", mhtn3.genBasePhName());
assertEquals("<br phname=\"breakTag\"/>", mhtn3.toSourceString());
MsgPlaceholderNode mpn4 = (MsgPlaceholderNode) mn0.getChild(4);
MsgHtmlTagNode mhtn4 = (MsgHtmlTagNode) mpn4.getChild(0);
MsgPlaceholderNode mpn5 = (MsgPlaceholderNode) mn0.getChild(5);
MsgHtmlTagNode mhtn5 = (MsgHtmlTagNode) mpn5.getChild(0);
assertEquals("br", mhtn5.getLcTagName());
assertEquals("BREAK_TAG", mhtn5.genBasePhName());
assertEquals("<br phname=\"break_tag\"/>", mhtn5.toSourceString());
assertFalse(mhtn0.genSamenessKey().equals(mhtn2.genSamenessKey()));
assertFalse(mhtn0.genSamenessKey().equals(mhtn3.genSamenessKey()));
assertTrue(mhtn3.genSamenessKey().equals(mhtn4.genSamenessKey()));
assertFalse(mhtn3.genSamenessKey().equals(mhtn5.genSamenessKey()));
}
use of com.google.template.soy.soytree.MsgHtmlTagNode 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.MsgHtmlTagNode in project closure-templates by google.
the class InsertMsgsVisitorTest method testBasicMsgsUsingSoySource.
@Test
public void testBasicMsgsUsingSoySource() {
SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(BASIC_TEST_FILE_CONTENT).parse().fileSet();
TemplateNode template = (TemplateNode) SharedTestUtils.getNode(soyTree);
// Before.
assertThat(template.numChildren()).isEqualTo(5);
MsgNode msg = ((MsgFallbackGroupNode) template.getChild(2)).getChild(0);
assertThat(msg.numChildren()).isEqualTo(5);
MsgHtmlTagNode msgHtmlTag2 = (MsgHtmlTagNode) ((MsgPlaceholderNode) msg.getChild(2)).getChild(0);
assertThat(msgHtmlTag2.numChildren()).isEqualTo(3);
MsgHtmlTagNode msgHtmlTag4 = (MsgHtmlTagNode) ((MsgPlaceholderNode) msg.getChild(4)).getChild(0);
assertThat(msgHtmlTag4.numChildren()).isEqualTo(1);
assertThat(((RawTextNode) msgHtmlTag4.getChild(0)).getRawText()).isEqualTo("</a>");
// Execute the visitor.
new InsertMsgsVisitor(null, /* msgBundle */
FAIL).insertMsgs(template);
// After.
assertThat(template.numChildren()).isEqualTo(12);
assertThat(((PrintNode) template.getChild(0)).getExpr().toSourceString()).isEqualTo("$boo");
assertThat(((RawTextNode) template.getChild(1)).getRawText()).isEqualTo("scary ");
assertThat(((RawTextNode) template.getChild(2)).getRawText()).isEqualTo("random");
assertThat(((PrintNode) template.getChild(3)).getExpr().toSourceString()).isEqualTo("$foo");
assertThat(((RawTextNode) template.getChild(4)).getRawText()).isEqualTo("<a href=\"");
assertThat(((PrintNode) template.getChild(5)).getExpr().toSourceString()).isEqualTo("$goo");
assertThat(((RawTextNode) template.getChild(6)).getRawText()).isEqualTo("\">");
assertThat(((RawTextNode) template.getChild(7)).getRawText()).isEqualTo("slimy");
assertThat(((RawTextNode) template.getChild(8)).getRawText()).isEqualTo("</a>");
assertThat(((RawTextNode) template.getChild(9)).getRawText()).isEqualTo(" ");
assertThat(((RawTextNode) template.getChild(10)).getRawText()).isEqualTo("dairy");
assertThat(((PrintNode) template.getChild(11)).getExpr().toSourceString()).isEqualTo("$moo");
}
Aggregations