1 | <?php |
---|
2 | |
---|
3 | /** |
---|
4 | * Strips the spaces at the beginning and end of each line and also the line breaks |
---|
5 | * <pre> |
---|
6 | * * mode : sets the content being stripped, available mode are 'default' or 'js' |
---|
7 | * for javascript, which strips the comments to prevent syntax errors |
---|
8 | * </pre> |
---|
9 | * |
---|
10 | * This software is provided 'as-is', without any express or implied warranty. |
---|
11 | * In no event will the authors be held liable for any damages arising from the use of this software. |
---|
12 | * |
---|
13 | * @author Jordi Boggiano <j.boggiano@seld.be> |
---|
14 | * @copyright Copyright (c) 2008, Jordi Boggiano |
---|
15 | * @license http://dwoo.org/LICENSE Modified BSD License |
---|
16 | * @link http://dwoo.org/ |
---|
17 | * @version 1.1.0 |
---|
18 | * @date 2009-07-18 |
---|
19 | * @package Dwoo |
---|
20 | */ |
---|
21 | class Dwoo_Plugin_strip extends Dwoo_Block_Plugin implements Dwoo_ICompilable_Block |
---|
22 | { |
---|
23 | public function init($mode = "default") |
---|
24 | { |
---|
25 | } |
---|
26 | |
---|
27 | public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type) |
---|
28 | { |
---|
29 | return ''; |
---|
30 | } |
---|
31 | |
---|
32 | public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content) |
---|
33 | { |
---|
34 | $params = $compiler->getCompiledParams($params); |
---|
35 | |
---|
36 | $mode = trim($params['mode'], '"\''); |
---|
37 | switch ($mode) { |
---|
38 | case 'js': |
---|
39 | case 'javascript': |
---|
40 | $content = preg_replace('#(?<!:)//\s[^\r\n]*|/\*.*?\*/#s','', $content); |
---|
41 | |
---|
42 | case 'default': |
---|
43 | default: |
---|
44 | } |
---|
45 | |
---|
46 | $content = preg_replace(array("/\n/","/\r/",'/(<\?(?:php)?|<%)\s*/'), array('','','$1 '), preg_replace('#^\s*(.+?)\s*$#m', '$1', $content)); |
---|
47 | |
---|
48 | return $content; |
---|
49 | } |
---|
50 | } |
---|