Permalink
Browse files

Dhaval/ashish12 | added support for if conditional with block in mixins

  • Loading branch information...
1 parent d5423f2 commit cb83ea4a4da96f9a4b87c1e3a713dddac0494958 @dhavalsdoshi dhavalsdoshi committed Mar 12, 2013
@@ -53,7 +53,20 @@ private Node getInjectionPoint(Node block) {
return node;
}
- if (node.hasBlock()) {
+ if(node instanceof ConditionalNode){
+ List<IfConditionNode> conditions = ((ConditionalNode) node).getConditions();
+ Node blockForIfConditionNode = conditions.get(0).getBlock();
+
+ if(!blockForIfConditionNode.hasNodes()) return blockForIfConditionNode;
+
+ Node nodeFromTree = getInjectionPoint(blockForIfConditionNode);
+ if (nodeFromTree != null) {
+ return nodeFromTree;
+ }
+ }
+
+
+ if (node.hasBlock()) {
if (!node.getBlock().hasNodes()) {
return node.getBlock();
}
@@ -20,30 +20,43 @@
@Test
public void testFullRun() throws IOException {
- JadeConfiguration cfg = new JadeConfiguration();
- // cfg.setDirectoryForTemplateLoading(new File("/where/you/store/templates"));
- Map<String, Object> root = new HashMap<String, Object>();
- root.put("hello", "world");
- root.put("hallo", null);
- JadeModel model = new JadeModel(root);
-
- JadeTemplate temp = cfg.getTemplate(getResourcePath("fullrun"));
+ String templateName = "fullrun";
+ String expected = "<div><div>Hi everybody</div></div>";
+ assertTemplateRendering(templateName, expected);
+ }
+
+ @Test
+ public void testFullRunForMixinWithConditional() throws IOException {
+ String templateName = "mixin_with_conditional";
+ String expected = "<div class=\"wrapper conditional\"><label>another nested label</label></div>";
+ assertTemplateRendering(templateName, expected);
+ }
+
+ private void assertTemplateRendering(String templateName, String expected) throws IOException {
+ JadeConfiguration cfg = new JadeConfiguration();
+ // cfg.setDirectoryForTemplateLoading(new File("/where/you/store/templates"));
+ Map<String, Object> root = new HashMap<String, Object>();
+ root.put("hello", "world");
+ root.put("hallo", null);
+ JadeModel model = new JadeModel(root);
+
+ JadeTemplate temp = cfg.getTemplate(getResourcePath(templateName));
// Writer out = new OutputStreamWriter(System.err);
- StringWriter out = new StringWriter();
- try {
+ StringWriter out = new StringWriter();
+ try {
temp.process(model, out);
} catch (JadeCompilerException e) {
e.printStackTrace();
fail();
}
- out.flush();
- assertEquals("<div><div>Hi everybody</div></div>", out.toString());
- }
-
+ out.flush();
+ assertEquals(expected, out.toString());
+ }
+
public String getResourcePath(String fileName) {
try {
- return TestFileHelper.getRootResourcePath() + "/template/fullrun";
+ return TestFileHelper.getRootResourcePath() + "/template/" + fileName;
} catch (FileNotFoundException e) {
e.printStackTrace();
}
@@ -0,0 +1,8 @@
+- alignment = "left"
+mixin alignConditional()
+ if alignment
+ .wrapper.conditional
+ block
+
++alignConditional
+ label="another nested label"

0 comments on commit cb83ea4

Please sign in to comment.