-
Notifications
You must be signed in to change notification settings - Fork 10
/
tale-jade
96 lines (60 loc) · 1.71 KB
/
tale-jade
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/php
<?php
use Tale\Jade\Compiler;
include 'vendor/autoload.php';
list($self, $action, $path, $target) = array_pad($argv, 4, null);
if ($action && $action !== 'compile') {
echo "I can't do anything more than compilation currently :(\n";
$action = null;
}
if (!$action || !$path) {
echo "Usage: $self compile <source> [<destination>]\n";
echo "Options:\n";
echo "--pretty\tFormat the output HTML\n";
exit;
}
$options = [];
foreach ($argv as $v) {
if ($v === '--pretty' || $v === '-p')
$options['pretty'] = true;
}
$map = [];
$path = realpath($path);
if (!$path) {
echo "The given source path is neither a file nor a directory.\n";
exit;
}
//Simple file -> file compile
if (is_file($path)) {
$path = realpath($path);
if (!$target)
$target = dirname($path).'/'.basename($path, '.jade').'.phtml';
$map[$path] = $target;
} else if (is_dir($path)) {
$path = rtrim($path, '/\\');
$files = glob("$path/*.jade");
if (!$target) {
$target = $path;
} else {
if (!is_dir($target))
mkdir($target, 0755, true);
$target = realpath($target);
if (!$target) {
echo "Failed to create output directory $path. Missing access rights maybe?\n";
exit;
}
}
foreach ($files as $file) {
$map[$file] = $target.'/'.basename($file, '.jade').'.phtml';
}
}
$compiler = new Compiler(array_replace([
'standAlone' => true
], $options));
echo "Starting compilation...\n";
foreach ($map as $source => $target) {
echo "Compiling [$source] to [$target]\n";
$phtml = $compiler->compileFile($source);
file_put_contents($target, $phtml);
}
echo "Finished!\n";