function testMarkdown1() { $data = <<<MARKDOWN # Hello It's a trap MARKDOWN; $result = <<<HTML <h1>Hello</h1> <p>It's a trap</p> HTML; POINT::clear(); POINT::inline('test1', $data); $this->assertEquals(str_replace("\r\n", "\n", $result), POINT::get('test1', 'markdown-html')); }
static function insert($point_name) { echo "/****** point {$point_name} */\r\n" . POINT::get($point_name) . "/****finish point {$point_name} *//*\r\n"; }
/** * execute all file-pairs in a row */ public function process() { //self::log(2,$this->store); register_shutdown_function(array($this, '_handleFatal')); if (!empty($this->exported_var)) { extract($this->exported_var); } $___total_cnt = 0; $___all_cnt = 0; while ($___m = $this->getpair()) { $error = error_get_last(); if (is_array($error)) { break; } //$this->debug('xxx-'.print_r($___m,true)); $srcfile = $___m[0]; $dstfile = $___m[1]; $___all_cnt++; switch ($___m[2]) { case 'eval': case 'file': case 'echo': $filemtime = 0; if (is_file($srcfile)) { $this->srcfile = $srcfile; $filemtime = filemtime($srcfile); } else { $this->srcfile = '<-string->'; } if (!empty($___m[3]['xtime'])) { $filemtime = max($filemtime, $___m[3]['xtime']); } if (!empty($___m[3])) { if (!empty($___m[3]['force'])) { $filemtime = time(); } } $___s = $this->prep_file($srcfile, $___m[2] != 'echo'); if ($___m[2] == 'echo') { $srcfile = ''; } if (!is_null($___s)) { $oldcwd = getcwd(); if (is_file($srcfile)) { chdir(dirname($srcfile)); //$this->debug('xml_read:',getcwd()); } POINT::$eval_src = $srcfile; POINT::$eval_idx = 0; eval($___s); chdir($oldcwd); if (empty($dstfile)) { $this->cfg_time($filemtime); } if ($this->post_process($dstfile, $filemtime, $___m[3]['code'])) { $srcfile = self::ic('con', $srcfile); $dstfile = self::ic('con', $dstfile); $this->log(2, "e>{$srcfile}"); if (strlen($srcfile) + strlen($dstfile) > 75) { $this->log(2, "\n\r "); } $this->log(2, "-->{$dstfile}"); $___total_cnt++; $this->log(2, "\n\r"); } break; } case 'copy': if (empty($dstfile)) { break; } $___s = pathinfo($dstfile); //$this->debug( '!dst -"'.$dstfile.'" ',$___s); //print_r($___s); if (!empty($___s['dirname']) && !is_dir($___s['dirname'])) { $this->log(2, $___s['dirname']); mkdir($___s['dirname'], 0777, true); } if (is_file($dstfile)) { $mtime = @filemtime($dstfile); } else { $mtime = 0; } $this->debug(array($mtime, filemtime($srcfile))); if (!is_file($dstfile) || filemtime($dstfile) < filemtime($srcfile)) { if (!empty($___m[3]['code'])) { $data = file_get_contents($srcfile); $this->decode($data, $___m[3]['code']); } else { $data = file_get_contents($srcfile); } file_put_contents($dstfile, $data); $this->betouch($dstfile, filemtime($srcfile)); $srcfile = self::ic('con', $srcfile); $dstfile = self::ic('con', $dstfile); $this->log(2, "c>{$srcfile}"); if (strlen($srcfile) + strlen($dstfile) > 75) { $this->log(2, "\n\r "); } $this->log(2, "-->{$dstfile}" . "\n\r"); // was last modified: " . date ("F d Y H:i:s.", filectime($srcfile)); $___total_cnt++; } break; } } $error = error_get_last(); if (is_array($error)) { $this->log(1, sprintf('Error: %s(%s) module raised "%s" ' . "\n\r", realpath($this->srcfile), $error['line'], $error['message']) . print_r(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS), true)); } $this->log(1, sprintf("\ntotal %s of %s files copied.\n\r", $___total_cnt, $___all_cnt)); }
function testFilterJS2JS() { $data = <<<DATA function sortfunc(a, b) { return a - b; } /** * Draws table by rectandles description * * @param {Object} arr - {x:, y:, h:, w:, color:} rectangles descriptors */ function makeTable(arr) { var i, r, x, y, aL; // so calc all rows and cells var rows = {}, cells = {}, curcel = 0, currow = 0, table = []; for (i = 0, aL = arr.length; i < aL; i++) { r = arr[i]; cells[r.x] = 0; cells[r.x + r.w] = 0; rows[r.y] = 0; rows[r.y + r.h] = 0; } //renumber rows and cells (function () { var _cell = [], _row = []; for (i in cells) _cell.push(i); for (i in rows) _row.push(i); _cell.sort(sortfunc); _row.sort(sortfunc); cells = {}; rows = {}; for (i = 0; i < _cell.length; i++) cells[_cell[i]] = curcel++; for (i = 0; i < _row.length; i++) rows[_row[i]] = currow++; })() // so row-cells really sorted; //create table image for (i in cells) table.push(new Array(currow)); // draw rectangles at the table image for (i = 0, aL = arr.length; i < aL; i++) { r = arr[i]; for (x = cells[r.x]; x < cells[r.x + r.w]; x++) for (y = rows[r.y]; y < rows[r.y + r.h]; y++) { table[x + 1][y + 1] = r; } } var html = [], last = 0; html.push('<col width="1">'); // height definition col for (i in cells) { html.push('<col width="' + (i - last) + '">'); last = i; } // so create the rest html last = 0; var emptycel; function fillemptycell(){ if (!!emptycel) { html.push('<td' + (emptycel == 1 ? '' : ' colspan="' + emptycel + '"') + '><!-- \\ --></td>'); emptycel = 0; } } DATA; $pattern = <<<RESULT function sortfunc(a, b) {\\nreturn a - b;\\n}\\nfunction makeTable(arr) {\\nvar i, r, x, y, aL;\\nvar rows = {}, cells = {}, curcel = 0, currow = 0, table = [];\\nfor (i = 0, aL = arr.length; i < aL; i++) {\\nr = arr[i];\\ncells[r.x] = 0;\\ncells[r.x + r.w] = 0;\\nrows[r.y] = 0;\\nrows[r.y + r.h] = 0;\\n}\\n(function () {\\nvar _cell = [], _row = [];\\nfor (i in cells) _cell.push(i);\\nfor (i in rows) _row.push(i);\\n_cell.sort(sortfunc);\\n_row.sort(sortfunc);\\ncells = {};\\nrows = {};\\nfor (i = 0; i < _cell.length; i++) cells[_cell[i]] = curcel++;\\nfor (i = 0; i < _row.length; i++) rows[_row[i]] = currow++;\\n})()\\nfor (i in cells) table.push(new Array(currow));\\nfor (i = 0, aL = arr.length; i < aL; i++) {\\nr = arr[i];\\nfor (x = cells[r.x]; x < cells[r.x + r.w]; x++)\\nfor (y = rows[r.y]; y < rows[r.y + r.h]; y++) {\\ntable[x + 1][y + 1] = r;\\n}\\n}\\nvar html = [], last = 0;\\nhtml.push('<col width=\\"1\\">');\\nfor (i in cells) {\\nhtml.push('<col width=\\"' + (i - last) + '\\">');\\nlast = i;\\n}\\nlast = 0;\\nvar emptycel;\\nfunction fillemptycell(){\\nif (!!emptycel) {\\nhtml.push('<td'\\n+ (emptycel == 1 ? '' : ' colspan=\\"' + emptycel + '\\"')\\n+ '><!-- \\\\ --></td>');\\nemptycel = 0;\\n}\\n}\\n RESULT; $this->assertEquals(trim(POINT::filter(POINT::filter($data, 'jscompress'), '2js')), $this->nl2nl($pattern)); }
public function main() { $this->log('<%=$version%>', Project::MSG_INFO); // define a force tag $time = false; if ($this->force) { $xtime = strtotime($this->force); if (!$xtime) { $time = time(); if ($this->force != 'force') { $this->log('wrong date "' . $this->force . '"', Project::MSG_WARN); } } else { $time = $xtime; } } $this->preprocessor->cfg_time($time); $this->preprocessor->logLevel = $this->logLevel; // difine variable definitions foreach ($this->parameters as $v) { $file = $v->getFile(); if (@is_readable($file)) { foreach (file($file) as $vv) { if (preg_match('/^(?:\\;.*|\\#.*|([^=]+)=(.*))$/', $vv, $mm)) { if (!empty($mm[1])) { $this->preprocessor->export(trim($mm[1]), trim($mm[2])); } } } } else { $this->preprocessor->export($v->getName(), $v->getValue()); } } //run it! if (!!$this->config) { $this->log('making "' . $this->config . '"', Project::MSG_WARN); POINT::clear(); $this->preprocessor->xml_read($this->config); $this->preprocessor->process(); } else { if (!empty($this->xconfigs)) { $config = ''; foreach ($this->xconfigs as $v) { $config .= $v->getText(); } $this->log('making "' . $config . '"', Project::MSG_WARN); POINT::clear(); $this->preprocessor->xml_read($config); $this->preprocessor->process(); } } }
/** * ловим ошибку - вставка кода в // комментарии */ function testPOINTComment() { $data = <<<HTML <?xml version='1.0' standalone='yes'?> <config> <files dstdir='tests'> <echo name="xx.txt"><![CDATA[ /* <% POINT::start('xxx');%> it's a text <% POINT::finish();%> */ // <%=POINT::get('xxx');%> ## <%=POINT::get('xxx');%> /* <%=POINT::get('xxx');%> */ ]]></echo> </files> </config> HTML; $result = <<<HTML // ---- point::xxx ---- it's a text ## ---- point::xxx ---- it's a text /* --- point::xxx --- */ it's a text HTML; $preprocessor = preprocessor::instance(); $preprocessor->xml_read($data); $preprocessor->process(); $data = file_get_contents('tests/xx.txt'); $this->assertEquals($this->nl2nl($result), $this->nl2nl($data)); POINT::clear(); unlink('tests/xx.txt'); }