Skip to content

Commit ce61eed

Browse files
committed
use Mustache templates
1 parent 5a76767 commit ce61eed

File tree

5 files changed

+27
-28
lines changed

5 files changed

+27
-28
lines changed

Phakefile.php

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
require __DIR__ . '/vendor/autoload.php';
23

34
function invoke_wp_cli( $cmd, $app ) {
45
$cmd .= ' --path=' . escapeshellarg( $app['path'] );
@@ -15,6 +16,12 @@ function invoke_wp_cli( $cmd, $app ) {
1516
return json_decode( $json, true );
1617
}
1718

19+
function render( $path, $binding ) {
20+
$m = new Mustache_Engine;
21+
$template = file_get_contents( __DIR__ . "/_templates/$path" );
22+
return $m->render( $template, $binding );
23+
}
24+
1825
desc( 'Generate a list of commands with all accepted arguments on STDOUT.' );
1926
task( 'syn-list', function( $app ) {
2027
function generate_synopsis( $command, $path = '' ) {
@@ -35,22 +42,9 @@ function generate_synopsis( $command, $path = '' ) {
3542
desc( 'Update the /commands/ page.' );
3643
task( 'cmd-list', function( $app ) {
3744
$wp = invoke_wp_cli( 'wp --cmd-dump', $app );
45+
$wp['version'] = $app['version'];
3846

39-
$out = '';
40-
41-
foreach ( $wp['subcommands'] as $command ) {
42-
$url = "https://github.com/wp-cli/wp-cli/blob/{$app['version']}/php/commands/{$command['name']}.php";
43-
44-
$out .= <<<EOB
45-
<tr>
46-
<td><a href="{$url}">{$command['name']}</a></td>
47-
<td>{$command['description']}</td>
48-
</tr>
49-
50-
EOB;
51-
}
52-
53-
file_put_contents( '_includes/cmd-list.html', $out );
47+
file_put_contents( '_includes/cmd-list.html', render( 'cmd-list.mustache', $wp ) );
5448
});
5549

5650
desc( 'Update the /config/ page.' );
@@ -64,15 +58,15 @@ function generate_synopsis( $command, $path = '' ) {
6458
continue;
6559

6660
if ( false !== $details['file'] ) {
67-
$config = "$key: " . htmlspecialchars( $details['file'] );
61+
$config = "$key: " . $details['file'];
6862
} else {
6963
$config = '';
7064
}
7165

7266
if ( false !== $details['runtime'] ) {
7367
$flag = ( true === $details['runtime'] )
7468
? "--[no-]$key"
75-
: "--$key" . htmlspecialchars( $details['runtime'] );
69+
: "--$key" . $details['runtime'];
7670
} else {
7771
$flag = '';
7872
}
@@ -81,15 +75,7 @@ function generate_synopsis( $command, $path = '' ) {
8175

8276
$description = $details['desc'];
8377

84-
$out .= <<<EOB
85-
<tr>
86-
<td><code>$config</code></td>
87-
<td><code>$flag</code></td>
88-
<td><code>$default</code></td>
89-
<td>$description</td>
90-
</tr>
91-
92-
EOB;
78+
$out .= render( 'config.mustache', compact( 'config', 'flag', 'default', 'description' ) );
9379
}
9480

9581
file_put_contents( '_includes/param-list.html', $out );

_includes/param-list.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<tr>
3838
<td><code>color: &lt;bool&gt;</code></td>
3939
<td><code>--[no-]color</code></td>
40-
<td><code>"auto"</code></td>
40+
<td><code>&quot;auto&quot;</code></td>
4141
<td>Whether to colorize the output</td>
4242
</tr>
4343
<tr>

_templates/cmd-list.mustache

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{{#subcommands}}
2+
<tr>
3+
<td><a href="https://github.com/wp-cli/wp-cli/blob/{{version}}/php/commands/{{name}}.php">{{name}}</a></td>
4+
<td>{{description}}</td>
5+
</tr>
6+
{{/subcommands}}

_templates/config.mustache

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<tr>
2+
<td><code>{{config}}</code></td>
3+
<td><code>{{flag}}</code></td>
4+
<td><code>{{default}}</code></td>
5+
<td>{{description}}</td>
6+
</tr>

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"require-dev": {
3-
"jaz303/phake": "dev-master"
3+
"jaz303/phake": "dev-master",
4+
"mustache/mustache": "~2.4"
45
}
56
}

0 commit comments

Comments
 (0)