Skip to content

Commit 6013b42

Browse files
committed
autogenerate the CSS template file
1 parent 6ea42b1 commit 6013b42

File tree

6 files changed

+408
-4
lines changed

6 files changed

+408
-4
lines changed

CHANGES

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
Revision history for Perl module CPAN::Mini::Webserver:
22

3+
0.44
4+
- autogenerate the CSS template file
5+
36
0.43 Thu Sep 18 17:14:50 BST 2008
47
- add an abstract to the Makefile.PL
58
- add a human-readable license

MANIFEST

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ CHANGES
33
lib/CPAN/Mini/Webserver.pm
44
lib/CPAN/Mini/Webserver/Index.pm
55
lib/CPAN/Mini/Webserver/Templates.pm
6+
lib/CPAN/Mini/Webserver/Templates/CSS.pm
67
Makefile.PL
78
MANIFEST This list of files
89
README

build_css.pl

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!perl
2+
use strict;
3+
use warnings;
4+
use Cwd qw(cwd);
5+
use CSS::Squish;
6+
use File::Find::Rule;
7+
use File::Slurp;
8+
use Perl::Tidy;
9+
use Template;
10+
use YAML qw(LoadFile DumpFile);
11+
12+
foreach my $filename ( File::Find::Rule->new->file->in('root/static/css') ) {
13+
next if $filename =~ /my-screen\.css/;
14+
unlink($filename) || die $!;
15+
}
16+
17+
my $settings = 'blueprint_0.7.1/lib/settings.yml';
18+
my $conf = LoadFile($settings);
19+
$conf->{cpanminiwebserver}->{path} = cwd . '/root/static/css/';
20+
DumpFile( $settings, $conf );
21+
use YAML;
22+
23+
system "cd blueprint_0.7.1/lib && ruby compress.rb -p cpanminiwebserver";
24+
25+
die "CSS files not generated" unless -f 'root/static/css/screen.css';
26+
27+
my $template = q{package CPAN::Mini::Webserver::Templates::CSS;
28+
use strict;
29+
use warnings;
30+
use Template::Declare::Tags;
31+
use base 'Template::Declare';
32+
33+
[% FOREACH file IN files %]
34+
[% name = file.0 %]
35+
[% css = file.1 %]
36+
template 'css_[% name %]' => sub {
37+
my $self = shift;
38+
my $css = <<'END';
39+
[% css %]
40+
END
41+
outs_raw $css;
42+
};
43+
[% END %]
44+
45+
1;
46+
};
47+
48+
my $tt = Template->new;
49+
$tt->process(
50+
\$template,
51+
{ files => [
52+
[ 'ie' => scalar read_file('root/static/css/ie.css') ],
53+
[ 'print' => scalar read_file('root/static/css/print.css') ],
54+
[ 'screen' => scalar read_file('root/static/css/screen.css') ],
55+
],
56+
},
57+
\my $perl,
58+
) || die $template->error();
59+
Perl::Tidy::perltidy( source => \$perl, destination => \my $tidied );
60+
write_file( 'lib/CPAN/Mini/Webserver/Templates/CSS.pm', $tidied );

lib/CPAN/Mini/Webserver.pm

+6-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ use PPI;
1919
use PPI::HTML;
2020
use Template::Declare;
2121

22-
Template::Declare->init( roots => ['CPAN::Mini::Webserver::Templates'] );
22+
Template::Declare->init(
23+
roots => [
24+
'CPAN::Mini::Webserver::Templates',
25+
'CPAN::Mini::Webserver::Templates::CSS'
26+
]
27+
);
2328

2429
if ( eval { require HTTP::Server::Simple::Bonjour } ) {
2530
extends 'HTTP::Server::Simple::Bonjour', 'HTTP::Server::Simple::CGI';

0 commit comments

Comments
 (0)