Commit bd14bd1c by Seldaek

+ Plugins: Added a mode parameter to {strip} to allow stripping of javascript

code blocks that use "// comments", because without this special mode the comments result in syntax errors git-svn-id: svn://dwoo.org/dwoo/trunk@171 0598d79b-80c4-4d41-97ba-ac86fbbd088b
parent 53d45ca5
......@@ -14,6 +14,9 @@
+ API: Added Dwoo_Compilation_Exception methods getCompiler() and
getTemplate() so you can catch the exception and use those to build a nicer
error view with all the details you want
+ Plugins: Added a mode parameter to {strip} to allow stripping of javascript
code blocks that use "// comments", because without this special mode the
comments result in syntax errors
* The Compiler now ensures that a template starting with <?xml will not
conflict with php using the short_open_tag=On setting
* Complex arrays keys can be read using {$var["Long|Key*With.some)Crap"]},
......
......@@ -2,6 +2,10 @@
/**
* Strips the spaces at the beginning and end of each line and also the line breaks
* <pre>
* * mode : sets the content being stripped, available mode are 'default' or 'js'
* for javascript, which strips the comments to prevent syntax errors
* </pre>
*
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
......@@ -21,7 +25,7 @@
*/
class Dwoo_Plugin_strip extends Dwoo_Block_Plugin implements Dwoo_ICompilable_Block
{
public function init()
public function init($mode = "default")
{
}
......@@ -34,6 +38,16 @@ class Dwoo_Plugin_strip extends Dwoo_Block_Plugin implements Dwoo_ICompilable_Bl
{
$params = $compiler->getCompiledParams($params);
$mode = trim($params['mode'], '"\'');
switch ($mode) {
case 'js':
case 'javascript':
$content = preg_replace('#(?<!:)//\s[^\r\n]*|/\*.*?\*/#','', $content);
case 'default':
default:
}
$content = preg_replace(array("/\n/","/\r/",'/(<\?(?:php)?|<%)\s*/'), array('','','$1 '), preg_replace('#^\s*(.+?)\s*$#m', '$1', $content));
return $content;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment