コード例 #1
0
ファイル: wpshell.php プロジェクト: royalwang/wp-scripts
function shell_preg_color($preg, $color, $rval, $part = '\\0', $delim = "\n")
{
    return implode($delim, preg_replace($preg, shell_color($color) . $part . "", explode($delim, $rval)));
}
コード例 #2
0
ファイル: build-js.php プロジェクト: carriercomm/magma
/**
 * Concats javascript files in a given directory into a single script
 * 
 * @param directory directory to scan for html files
 * @param first     array of filenames to be inserted first - order of array preserved
 * @param last      array of filenames to be inserted last - order of array upheld
 * @param ignore    filenames to ignore
 */
function concat_js($directory, $first = null, $last = null)
{
    $js = '';
    $filenames = get_filenames($directory, '/\\.js$/');
    // insert first files
    if ($first) {
        foreach ($first as $filename) {
            // array_search returns false if search failed
            if (is_numeric($key = array_search($filename, $filenames))) {
                $js .= file_get_contents("{$directory}{$filename}");
                unset($filenames[$key]);
            } else {
                echo shell_color('Error:', 'red') . " given first file {$filename} is not in {$directory}\n";
            }
        }
    }
    // temp store last files and remove
    $temp = '';
    if ($last) {
        foreach ($last as $filename) {
            // array_search returns false if search failed
            if (is_numeric($key = array_search($filename, $filenames))) {
                $temp .= file_get_contents("{$directory}{$filename}");
                unset($filenames[$key]);
            } else {
                echo shell_color('Error:', 'red') . " given last file {$filename} is not in {$directory}\n";
            }
        }
    }
    // concat other files
    foreach ($filenames as $filename) {
        $js .= file_get_contents("{$directory}{$filename}");
    }
    // append last
    $js .= $temp;
    return $js;
}
コード例 #3
0
ファイル: build-doc.php プロジェクト: carriercomm/magma
        if (file_exists("{$responses_dir}{$method}.json")) {
            $markup .= '<pre>' . htmlentities(file_get_contents("{$responses_dir}{$method}.json")) . '</pre>';
        } else {
            $markup .= '<p>No example response</p>';
        }
        $html .= $markup;
    } else {
        $html .= '<p>No description</p>';
    }
    $html .= '</div>';
}
$contents .= '</ul></div>';
// insert test options
$html = preg_replace('/\\$\\{method-options\\}/', $tester_methods, $html);
$tester_html = preg_replace('/\\$\\{method-options\\}/', $tester_methods, $tester_html);
// insert table of contents
$html = preg_replace('/\\$\\{contents\\}/', $contents, $html);
// insert example requests into tester script
$footer = file_get_contents($footer);
$footer = preg_replace('/\\$\\{requests\\}/', implode(",\n", $tester_requests), $footer);
$html .= $footer;
$tester_html .= $footer;
file_put_contents("{$report_directory}{$report_name}", $html);
file_put_contents("{$tester_directory}{$tester_name}", $tester_html);
echo shell_color('Success:', 'green') . " {$report_name} saved to {$report_directory}\n";
echo shell_color('Success:', 'green') . " {$tester_name} saved to {$tester_directory}\n";
// generate workflow example doc
$html = markdown($workflow_md);
file_put_contents($workflow_html, $html);
echo shell_color('Success:', 'green') . " {$workflow_html} saved\n";
コード例 #4
0
ファイル: build-html.php プロジェクト: carriercomm/magma
 function embed_html_blocks($states_directory, $blocks_directory, $compiled_directory, $verbose = false, $wrap = true, $strip_comments = false)
 {
     if ($wrap) {
         // get wrap.html for wrapping all blocks with body/head html
         $wrap_html = file_get_contents($blocks_directory . "wrap.html");
     }
     $statenames = get_filenames($states_directory);
     // regex pattern for block stub
     $block_stub_regex = '/ *<!--[ ]*\\[BLOCK\\][ ]*-->\\n/';
     foreach ($statenames as $statename) {
         // check for .state extension
         if (preg_match('/\\.state$/', $statename)) {
             // returns file lines in an array
             // files contain blocknames
             $blocknames = file($states_directory . $statename);
             $html = array('');
             // html stack
             $namespace = array('');
             // namespace stack for filenames
             // action of current block depends on indention of next block
             for ($i = 0; $i < count($blocknames); $i++) {
                 $blockname = trim($blocknames[$i]);
                 $level = get_level($blocknames[$i], $statename);
                 if ($i < count($blocknames) - 1) {
                     $next_blockname = $blocknames[$i + 1];
                     $next_level = get_level($next_blockname, $statename);
                 } else {
                     $next_blockname = 'EOF';
                     $next_level = 0;
                 }
                 // grab the html
                 $block = file_get_contents($blocks_directory . implode($namespace) . $blockname . ".html");
                 if (!$block) {
                     die(shell_color('Error:', 'red') . " No block named {$blockname} in {$states_directory}{$statename}\n");
                 }
                 // concat block to top of html stack
                 $html[count($html) - 1] .= $block;
                 // block is higher level than next - embed block(s)
                 if (($level_diff = $level - $next_level) > 0) {
                     // embed for each level
                     for ($j = 0; $j < $level_diff; $j++) {
                         $block = array_pop($html);
                         preg_match_all($block_stub_regex, end($html), $block_stub);
                         if (!count($block_stub[0])) {
                             die(shell_color('Error:', 'red') . " No block comment stub to embed into state {$states_directory}{$statename}\n" . end($html));
                         } elseif (count($block_stub[0]) > 1) {
                             die(shell_color('Error:', 'red') . " Too many block comment stubs to embed into state {$states_directory}{$statename}\n" . end($html));
                         }
                         // get block indention
                         preg_match('/^\\s*/', $block_stub[0][0], $indent);
                         // get rid of any unused [BLOCK] statements
                         $block = preg_replace($block_stub_regex, '', $block);
                         // add indents to html blocks so alignment is correct when embedded
                         $block = preg_replace('/(.+)\\n/', $indent[0] . '\\1' . "\n", $block);
                         array_pop($namespace);
                         $html[count($html) - 1] = preg_replace($block_stub_regex, $block, end($html));
                     }
                     // block is lower level than next - concat block to current level then push a new level
                 } elseif (($level_diff = $next_level - $level) > 0) {
                     // make sure contained blocks are indicated by one level of indention in
                     if ($level_diff != 1) {
                         die(shell_color('Error:', 'red') . " Contained block " . trim($next_blockname) . " indicated by more than one level of indention in state file {$statename}\n");
                     } else {
                         array_push($html, '');
                         // trim anything after + for overloaded blocks
                         if (strpos($blockname, '+')) {
                             $blockname = substr($blockname, 0, strpos($blockname, '+'));
                         }
                         array_push($namespace, $blockname . '.');
                     }
                     // get rid of unused embed comments
                 } else {
                     $html[count($html) - 1] = preg_replace($block_stub_regex, '', $html[count($html) - 1]);
                 }
             }
             // convert array to string
             $html = $html[0];
             if ($wrap) {
                 // indent one level then wrap in main body/head html
                 $html = preg_replace('/(.+)\\n/', str_repeat(' ', 4) . '\\1' . "\n", $html);
                 $html = preg_replace($block_stub_regex, $html, $wrap_html);
             }
             if ($strip_comments) {
                 $html = preg_replace('/ *\\<![ \\r\\n\\t]*(--.*--[ \\r\\n\\t]*)\\>\\n?/', '', $html);
                 // strip any leftover block comments
             } else {
                 $html = preg_replace($block_stub_regex, '', $html);
             }
             // save to statename.html file
             $filename = preg_replace('/\\.state/', '.html', $statename);
             file_put_contents($compiled_directory . $filename, $html);
             if ($verbose) {
                 echo shell_color('Added:', 'cyan') . " {$compiled_directory}{$filename}\n";
             }
             // filename doesn't have .state extension
         } else {
             echo shell_color('Warning:', 'red') . " ignoring {$states_directory}{$statename} since it does not have state extension\n";
         }
     }
     echo shell_color('Success:', 'green') . " html saved to {$compiled_directory}\n";
 }