Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 125 lines (101 sloc) 3.29 KB
#!/usr/bin/perl -w
use strict;
use warnings;
eval 'use Carp::Always'; # Not everyone has it
use Getopt::Long;
use File::Slurp;
use Encode qw(decode_utf8);
use Text::Textile ();
use Template ();
use Template::Constants qw( :debug :chomp );
package Local::L10n; # Local::* is reserved
use parent 'Locale::Maketext';
use Locale::Maketext::Lexicon {
de_DE => [Gettext => 'share/locale/de_DE.po'],
};
package main;
my $sourcepath = 's';
my $buildpath = 'build';
GetOptions(
'sourcepath:s' => \$sourcepath,
'buildpath:s' => \$buildpath,
) or exit;
-d $buildpath && -w $buildpath or die;
my $pages = [
index => 'Home',
asp => 'ASP',
coldfusion => 'ColdFusion',
csharp => 'C#',
delphi => 'Delphi',
dotnet => '.NET',
java => 'Java',
perl => 'Perl',
php => 'PHP',
plsql => 'PL/SQL',
postgresql => 'PostgreSQL',
python => 'Python',
ruby => 'Ruby',
scheme => 'Scheme',
];
MAIN: {
my $handle = Local::L10n->get_handle; # set LANG to localise
my $textile = Text::Textile::Bobby->new(disable_encode_entities => 1);
$textile->flavor( 'xhtml1' );
my @sidelinks;
my %tt_first_pass_defaults =(
FILTERS => {
'loc' => sub {
my ($lexicon_key) = @_;
return eval { $handle->maketext($lexicon_key) } || $lexicon_key;
},
},
);
my %tt_defaults = (
INCLUDE_PATH => [ qw( tt ) ],
OUTPUT_PATH => $buildpath,
DEBUG => DEBUG_UNDEF,
TRIM => CHOMP_ALL,
PRE_CHOMP => 1,
POST_CHOMP => 1,
ENCODING => 'utf8',
%tt_first_pass_defaults,
);
my $tt = Template->new( \%tt_defaults );
my $tt_first_pass = Template->new( \%tt_first_pass_defaults );
my @pages = @{$pages};
while ( @pages ) {
my ($section,$desc) = splice( @pages, 0, 2 );
my $path = ($section eq 'index') ? './' : "./$section.html";
push( @sidelinks, {
path => $path,
text => $desc,
} );
}
my $vars = {
sidelinks => \@sidelinks,
};
@pages = @{$pages};
while ( @pages ) {
my ($section,$desc) = splice( @pages, 0, 2 );
my $source = read_file( "$sourcepath/$section.textile.tt2" );
my $first_pass;
$tt_first_pass->process( \$source, undef, \$first_pass )
|| die sprintf("file: %s\nerror: %s\n", "$sourcepath/$section.textile.tt2", $tt->error);
$vars->{body} = $textile->process( decode_utf8($first_pass) );
$vars->{body} =~ s{<code>\n}{<code>}smxg;
$vars->{currlang} = ( $desc eq 'Home' ) ? '' : $desc;
$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];
$tt->process( 'page.ttml', $vars, "$section.html", { binmode => ':encoding(UTF-8)' } )
|| die sprintf("file: %s\nerror: %s\n", "$section.html", $tt->error);
}
}
package Text::Textile::Bobby;
use base 'Text::Textile';
# This is for inline code formatting
sub format_code {
my $self = shift;
my $text = $self->SUPER::format_code( @_ );
$text =~ s/<code>/<code class="inline">/g;
return $text;
}