Skip to content

Commit

Permalink
Another (smaller) refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
davorg committed Nov 30, 2019
1 parent a875e2c commit 51e0ac5
Showing 1 changed file with 24 additions and 25 deletions.
49 changes: 24 additions & 25 deletions bin/build
@@ -1,36 +1,27 @@
#!/usr/bin/perl
#!/usr/bin/perl -CS

use strict;
use warnings;
use 5.010;
use lib 'lib';

use FindBin '$Bin';
use Template;

use TwittElection::App;

my $app = TwittElection::App->new;
my $sch = $app->schema;
my $url = $app->base_url;

my $tt = Template->new({
ABSOLUTE => 1,
INCLUDE_PATH => "$Bin/../ttlib",
OUTPUT_PATH => "$Bin/../docs",
ENCODING => 'utf8',
});
my $te_app = TwittElection::App->new;

my @urls = build_constituency_pages($tt, $sch, $url);
my @urls = build_constituency_pages($te_app);

push @urls, build_party_pages($tt, $sch, $url);
push @urls, build_stats_page($tt, $sch, $url);
push @urls, build_static_pages($tt, $sch, $url);
push @urls, build_party_pages($te_app);
push @urls, build_stats_page($te_app);
push @urls, build_static_pages($te_app);

build_sitemap($tt, @urls);
build_sitemap($te_app, @urls);

sub build_constituency_pages {
my ($tt, $sch, $url) = @_;
my ($app) = @_;
my $sch = $app->schema;
my $url = $app->base_url;
my $tt = $app->tt;
my @return;

foreach my $c ($sch->resultset('Constituency')->all) {
Expand All @@ -56,7 +47,10 @@ sub build_constituency_pages {
}

sub build_party_pages {
my ($tt, $sch, $url) = @_;
my ($app) = @_;
my $sch = $app->schema;
my $url = $app->base_url;
my $tt = $app->tt;
my @return;

foreach my $p ($sch->resultset('Party')->sort_by_name->all) {
Expand All @@ -82,7 +76,10 @@ sub build_party_pages {
}

sub build_stats_page {
my ($tt, $sch, $url) = @_;
my ($app) = @_;
my $sch = $app->schema;
my $url = $app->base_url;
my $tt = $app->tt;

my $cand_rs = $sch->resultset('Candidate');
my $party_rs = $sch->resultset('Party');
Expand All @@ -103,7 +100,9 @@ sub build_stats_page {
}

sub build_static_pages {
my ($tt, $sch, $url) = @_;
my ($app) = @_;
my $url = $app->base_url;
my $tt = $app->tt;
my @returns;

for (qw[index about/index]) {
Expand All @@ -118,9 +117,9 @@ sub build_static_pages {
}

sub build_sitemap {
my ($tt, @urls) = @_;
my ($app, @urls) = @_;

$tt->process('sitemap.tt', { urls => \@urls }, 'sitemap.xml');
$app->tt->process('sitemap.tt', { urls => \@urls }, 'sitemap.xml', {binmode => ':utf8'});

return;
}
Expand Down

0 comments on commit 51e0ac5

Please sign in to comment.