-
Notifications
You must be signed in to change notification settings - Fork 85
/
crank.pl
executable file
·107 lines (91 loc) · 3.02 KB
/
crank.pl
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
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/perl
use 5.010;
use strict;
use warnings;
eval 'use Carp::Always'; # Not everyone has it
use Getopt::Long;
use File::Slurper qw(read_text);
use Encode qw(decode encode);
use Markdent::Simple::Fragment ();
use Template ();
use Template::Constants qw( :debug :chomp );
my $sourcepath = 's';
my $buildpath = 'build';
GetOptions(
'sourcepath:s' => \$sourcepath,
'buildpath:s' => \$buildpath,
) or exit;
-d $buildpath && -w $buildpath or die;
my $home = 'Home';
my $about = 'About';
my $pages = [
index => $home,
about => $about,
adodotnet => 'ADO.NET',
adodotnet_orm => 'ADO.NET ORM',
asp => 'ASP',
coldfusion => 'ColdFusion',
com_automation => 'COM',
csharp => 'C#',
delphi => 'Delphi',
adodotnet_ef => 'Entity Framework',
go => 'Go',
java => 'Java',
msaccess => 'MS Access',
perl => 'Perl',
php => 'PHP',
plsql => 'PL/SQL',
postgresql => 'PostgreSQL',
python => 'Python',
rlang => 'R',
ruby => 'Ruby',
scheme => 'Scheme',
vbdotnet => 'VB.NET',
];
MAIN: {
my @sidelinks;
my %tt_defaults = (
INCLUDE_PATH => [ qw( tt ) ],
OUTPUT_PATH => $buildpath,
DEBUG => DEBUG_UNDEF,
TRIM => CHOMP_ALL,
PRE_CHOMP => 1,
POST_CHOMP => 1,
ENCODING => 'utf8',
);
my $tt = Template->new( \%tt_defaults );
my $tt_first_pass = Template->new( { ENCODING => 'utf8' } );
my @pages = @{$pages};
while ( @pages ) {
my ($section,$desc) = splice( @pages, 0, 2 );
my $path = ($section eq 'index') ? './' : "./$section";
push( @sidelinks, {
path => $path,
text => $desc,
} );
}
my $vars = {
sidelinks => \@sidelinks,
};
$vars->{rel_static} = ( 'C' eq $ENV{LANG} ) ? q(./) : q(../); # path prefix to static assets
$vars->{rfc_1766_lang} = ( 'C' eq $ENV{LANG} ) ? 'en' : [map {tr/_/-/;$_} $ENV{LANG}]->[0];
@pages = @{$pages};
while ( @pages ) {
my ($section,$desc) = splice( @pages, 0, 2 );
my $source = read_text( "$sourcepath/$section.md" );
my $first_pass;
$tt_first_pass->process( \$source, undef, \$first_pass )
|| die sprintf("file: %s\nerror: %s\n", "$sourcepath/$section.md.tt2", $tt->error);
my $parser = Markdent::Simple::Fragment->new;
my $html = $parser->markdown_to_html(
dialect => 'GitHub',
markdown => $first_pass,
);
$html =~ s{<code>\n}{<code>}smxg;
$vars->{body} = $html;
$vars->{section} = ($section eq 'index') ? '.' : "$section.html";
$vars->{currlang} = ( ($desc eq $home) || ($desc eq $about) ) ? '' : $desc;
$tt->process( 'page.tt', $vars, "$section.html", { binmode => ':encoding(UTF-8)' } )
|| die sprintf("file: %s\nerror: %s\n", "$section.html", $tt->error);
}
}