Permalink
Browse files

added include tag to standard library

  • Loading branch information...
1 parent f5deac1 commit ac5f1fd7490e4d6837e3cf41d8f5f3ab7638dc87 @tthomas48 committed Feb 21, 2013
@@ -55,6 +55,7 @@ class HTML_Template_Nest_Taglib_Standard extends HTML_Template_Nest_Taglib
"foreach" => "HTML_Template_Nest_Taglib_Standard_ForeachTag",
"set" => "HTML_Template_Nest_Taglib_Standard_SetTag",
"attribute" => "HTML_Template_Nest_Taglib_Standard_AttributeTag",
+ "include" => "HTML_Template_Nest_Taglib_Standard_IncludeTag",
);
}
@@ -428,3 +429,20 @@ public function filter($output)
return "";
}
}
+class HTML_Template_Nest_Taglib_Standard_IncludeTag extends HTML_Template_Nest_Tag
+{
+ public function start()
+ {
+ $file = $this->getRequiredAttribute("name");
+ $viewPath = NULL;
+ foreach(HTML_Template_Nest_View::$INCLUDE_PATHS as $path) {
+ if(file_exists($path . "/" . $file . ".nst")) {
+ $viewPath = $path . "/" . $file . ".nst";
+ }
+ }
+ if($viewPath == NULL) {
+ throw new HTML_Template_Nest_TagException("Unable to find include $file in path.", $this->node);
+ }
+ return $this->compiler->compile($viewPath);
+ }
+}
@@ -89,4 +89,20 @@ public function testStandardLib()
trim(file_get_contents($filename))
);
}
+ public function testInclude()
+ {
+ HTML_Template_Nest_View::$CACHE = false;
+ HTML_Template_Nest_View::addIncludePath(dirname(__FILE__) . "/views");
+
+ $view = new HTML_Template_Nest_View("standardtaglib-include");
+
+ $view->addAttribute("headervar", "Header");
+ $view->addAttribute("footervar", "Footer");
+ $view->addAttribute("childvar", "Child");
+ $filename = dirname(__FILE__) . "/viewoutput/standardtaglib-include.html";
+ $this->assertEquals(
+ trim($view->render()),
+ trim(file_get_contents($filename))
+ );
+ }
}
@@ -0,0 +1 @@
+body{margin:0}.error{color:red}
Oops, something went wrong.
@@ -0,0 +1,3 @@
+
+function alertNow(msg){alert(msg);}
+var a=100;
@@ -0,0 +1 @@
+body{color:black}body .header{background-color:black;color:white}
@@ -0,0 +1,3 @@
+<header>Header</header>
+ <section>Child</section>
+<footer>Footer</footer>
@@ -0,0 +1,3 @@
+<nst:root xmlns:nst="http://nest.sourceforge.net/">
+ <section>${childvar}</section>
+</nst:root>
@@ -0,0 +1,6 @@
+<nst:root xmlns:nst="http://nest.sourceforge.net/"
+ xmlns:c="urn:nsttl:HTML_Template_Nest_Taglib_Standard">
+<header>${headervar}</header>
+<c:include name="standardtaglib-child" />
+<footer>${footervar}</footer>
+</nst:root>

0 comments on commit ac5f1fd

Please sign in to comment.