| 1 |
use strict; |
| 2 |
use warnings; |
| 3 |
|
| 4 |
use File::chdir; |
| 5 |
|
| 6 |
my @input = (["conversion"]); |
| 7 |
|
| 8 |
my @names = ("size", "angle", "time", "frequency", "resolution"); |
| 9 |
|
| 10 |
my %units = ( |
| 11 |
"size" => ["px", "pt", "pc", "mm", "cm", "in"], |
| 12 |
"angle" => ["deg", "grad", "rad", "turn"], |
| 13 |
"time" => ["s", "ms"], |
| 14 |
"frequency" => ["Hz", "kHz"], |
| 15 |
"resolution" => ["dpi", "dpcm", "dppx"], |
| 16 |
); |
| 17 |
|
| 18 |
my @template; |
| 19 |
|
| 20 |
foreach my $name (@names) |
| 21 |
{ |
| 22 |
my @units = @{$units{$name}}; |
| 23 |
my $tmpl = ".result {\n"; |
| 24 |
for (my $i = 0; $i < scalar(@units); $i++) { |
| 25 |
for (my $n = 0; $n < scalar(@units); $n++) { |
| 26 |
$tmpl .= sprintf(' output: (0%s + 1%s)', $units[$i], $units[$n]) . ";\n"; |
| 27 |
$tmpl .= sprintf(' output: (4.2%s / 1%s)', $units[$i], $units[$n]) . ";\n"; |
| 28 |
$tmpl .= sprintf(' output: (4.2%s * 1%s / 1%s)', $units[$i], $units[$n], $units[$i]) . ";\n"; |
| 29 |
} |
| 30 |
} |
| 31 |
$tmpl .= "}\n"; |
| 32 |
push @template, $name; |
| 33 |
push @template, $tmpl; |
| 34 |
} |
| 35 |
|
| 36 |
sub render { |
| 37 |
use File::Slurp qw(write_file); |
| 38 |
my ($names, $template, @fields) = @_; |
| 39 |
$template =~ s/\%(\d+)\%/$fields[$1]/g; |
| 40 |
local $CWD = $CWD; |
| 41 |
foreach (@{$names}) { |
| 42 |
mkdir $_; |
| 43 |
$CWD = $_; |
| 44 |
} |
| 45 |
print "created ", join("/", @{$names}), "\n"; |
| 46 |
return write_file('input.scss', { binmode => ':raw' }, $template); |
| 47 |
|
| 48 |
} |
| 49 |
|
| 50 |
while (defined(my $name = shift @template)) { |
| 51 |
my $template = shift(@template); |
| 52 |
foreach my $input (@input) { |
| 53 |
render([$input->[0], $name], $template, @{$input}); |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
# <>; |