Exemple #1
0
function get_test_result($name, $verbose = false)
{
    $path = __DIR__ . DIRECTORY_SEPARATOR . $name;
    $html = file_get_contents($path . '.html');
    if ($verbose) {
        echo "* rendering test '{$name}'\n";
    }
    try {
        $new = show_php($path . '.jade');
    } catch (Exception $err) {
        if ($verbose) {
            echo "! FATAL: php exception: " . str_replace("\n", "\n\t", $err) . "\n";
        }
        $new = null;
    }
    if ($new !== null) {
        $code = get_generated_html($new);
        // automatically compare $code and $html here
        $from = array("\n", "\r", "\t", " ", '"', "<!DOCTYPEhtml>");
        $to = array('', '', '', '', "'", '');
        $html = str_replace($from, $to, $html);
        $code = str_replace($from, $to, $code);
        $result = array($name, $html, $code);
        if (strcmp($html, $code)) {
            if ($verbose) {
                echo "  -{$html}\n";
                echo "  +{$code}\n\n";
            }
            return array(false, $result);
        }
        return array(true, $result);
    }
}
Exemple #2
0
error_reporting(E_ALL);
setup_autoload();
$nav_list = build_list(find_tests());
foreach ($nav_list as $type => $arr) {
    foreach ($arr as $e) {
        if ($e['name'] == 'index' || isset($argv[1]) && $e['name'] != $argv[1] && $argv[1] != '.') {
            continue;
        }
        $html = @file_get_contents($e['name'] . '.html');
        if ($html === FALSE) {
            print "! sample for test '{$e['name']}' not found.\n";
            continue;
        }
        print "* rendering test '{$e['name']}'\n";
        try {
            $new = show_php($e['name'] . '.jade');
        } catch (Exception $err) {
            print "! FATAL: php exception: " . str_replace("\n", "\n\t", $err) . "\n";
            $new = null;
            die;
        }
        if ($new !== null) {
            file_put_contents($e['name'] . '.jade.php', $new);
            $code = `php -d error_reporting="E_ALL & ~E_NOTICE" {$e['name']}.jade.php`;
            file_put_contents($e['name'] . '.jade.html', $code);
            // automatically compare $code and $html here
            $from = array("\n", "\r", "\t", " ", '"', "<!DOCTYPEhtml>");
            $to = array('', '', '', '', "'", '');
            $html = str_replace($from, $to, $html);
            $code = str_replace($from, $to, $code);
            if (strcmp($html, $code)) {
 public static function show_php($var, $indent = '&nbsp;&nbsp;', $niv = '0')
 {
     $str = '';
     if (is_array($var)) {
         $str .= "<b>[array][" . count($var) . "]</b><br />";
         foreach ($var as $k => $v) {
             for ($i = 0; $i < $niv; $i++) {
                 $str .= $indent;
             }
             $str .= "{$indent}<em>\"{$k}\"=></em>";
             $str .= self::show_php($v, $indent, $niv + 1);
         }
     } else {
         if (is_object($var)) {
             $str .= "<b>[objet]-class=[" . get_class($var) . "]-method=[";
             $arr = get_class_methods($var);
             foreach ($arr as $method) {
                 $str .= "[function {$method}()]";
             }
             $str .= "]-";
             $str .= "</b>";
             $str .= show_php(get_object_vars($var), $indent, $niv + 1);
         } else {
             $str .= "<em>[" . gettype($var) . "]</em>=[{$var}]<br />";
         }
     }
     return $str;
 }
Exemple #4
0
        }
        return $result;
    };
    return $print_nodes($ast);
}
function show_php($file)
{
    $jade = new \Jade\Jade(true);
    //return htmlspecialchars($jade->render($file));
    return $jade->render($file);
}
setup_autoload();
if (isset($_REQUEST['render'])) {
    $jade = new \Jade\Jade(true);
    $source = $jade->render(file_get_contents('index.jade'));
    file_put_contents('index.jade.php', $source);
}
$test = false;
if (isset($_REQUEST['test'])) {
    $test = $_REQUEST['test'];
    $base = dirname($test) . DIRECTORY_SEPARATOR;
    $html = basename($test, '.jade');
    $jade = file_get_contents($test);
    $html = file_get_contents($base . $html . '.html');
    $tokens = show_tokens($jade);
    $nodes = show_nodes($jade, $test);
    $php = show_php($test);
    $test = true;
}
$nav_list = build_list(find_tests());
require 'index.jade.php';