]> iEval git - plack-app-gruntmaster.git/blame - lib/Gruntmaster/Page.pm
Move header / footer to a separate module and update MANIFEST
[plack-app-gruntmaster.git] / lib / Gruntmaster / Page.pm
CommitLineData
42546e6c
MG
1package Gruntmaster::Page;
2
3use 5.014000;
4use strict;
5use warnings;
6use parent qw/Exporter/;
832cb45e 7our @EXPORT_OK = qw/generate/;
42546e6c
MG
8
9use File::Basename qw/fileparse/;
10use File::Slurp qw/write_file/;
11use IO::Compress::Gzip qw/gzip/;
12
13our $VERSION = '0.001';
14our @generators;
15
16use constant LANGUAGES => [ 'en' ];
17use constant CONTENT_TYPES => {
18 html => 'text/html; charset=UTF-8',
19 txt => 'text/plain; charset=UTF-8',
20};
21
42546e6c
MG
22sub declaregen{
23 my ($generator, $regex) = @_;
24 $generator = "Gruntmaster::Page::$generator";
25 eval "require $generator";
26 my $gensub = $generator->can('generate') or die "No such generator: $generator";
27 push @generators, [$regex, $gensub];
28}
29
fe78f0c1
MG
30{
31 my $component = qr'[^/]+';
32 my $contest = qr,(?:ct/$component/)?,;
33 declaregen Index => qr,^index$,;
34 declaregen Ct => qr,^ct/index$,;
35 declaregen 'Ct::Entry' => qr,^ct/$component/index$,;
36 #declaregen St => qr,^ct/$component/st/index$,;
37 declaregen Log => qr,^${contest}log/index$,;
38 declaregen 'Log::Entry' => qr,^${contest}log/$component/index$,;
39 declaregen Submit => qr,^${contest}submit$,;
40 declaregen Pb => qr,^${contest}pb/index$,;
41 declaregen 'Pb::Entry' => qr,^${contest}pb/$component/index$,;
42}
42546e6c
MG
43
44sub generate{
45 my ($path) = @_;
46 my ($path_noext, $ext) = $path =~ m/^(.*)\.(.*)$/;
47 my $basename = fileparse $path_noext;
48
49 open my $typemap, ">$path_noext.var";
50 say $typemap "URI: $basename\n";
51 for my $gen(@generators) {
52 my ($regex, $generator) = @$gen;
53 next unless $path_noext =~ $regex;
54 for my $lang (@{LANGUAGES()}) {
55 my $page = $generator->($path, $lang);
56 write_file "$path_noext.$lang.$ext", $page;
57 say $typemap "URI: $basename.$lang.$ext\nContent-Language: $lang\nContent-Type: " . CONTENT_TYPES->{$ext} . "\n";
58 gzip \$page => "$path_noext.$lang.gz.$ext", Minimal => 1;
59 say $typemap "URI: $basename.$lang.gz.$ext\nContent-Language: $lang\nContent-Encoding: gzip\nContent-Type: " . CONTENT_TYPES->{$ext} . "\n";
60 }
61 }
62 close $typemap;
63}
64
651;
66__END__
67# Below is stub documentation for your module. You'd better edit it!
68
69=head1 NAME
70
71Gruntmaster::Page - Perl extension for blah blah blah
72
73=head1 SYNOPSIS
74
75 use Gruntmaster::Page;
76 blah blah blah
77
78=head1 DESCRIPTION
79
80Stub documentation for Gruntmaster::Page, created by h2xs. It looks like the
81author of the extension was negligent enough to leave the stub
82unedited.
83
84Blah blah blah.
85
86=head2 EXPORT
87
88None by default.
89
90
91
92=head1 SEE ALSO
93
94Mention other useful documentation such as the documentation of
95related modules or operating system documentation (such as man pages
96in UNIX), or any relevant external documentation such as RFCs or
97standards.
98
99If you have a mailing list set up for your module, mention it here.
100
101If you have a web site set up for your module, mention it here.
102
103=head1 AUTHOR
104
105Marius Gavrilescu, E<lt>marius@E<gt>
106
107=head1 COPYRIGHT AND LICENSE
108
109Copyright (C) 2013 by Marius Gavrilescu
110
111This library is free software; you can redistribute it and/or modify
112it under the same terms as Perl itself, either Perl version 5.18.1 or,
113at your option, any later version of Perl 5 you may have available.
114
115
116=cut
This page took 0.02514 seconds and 4 git commands to generate.