From: Michael Andreen Date: Mon, 29 Jun 2009 08:24:13 +0000 (+0200) Subject: Use filter instead of having to stash the function everywhere X-Git-Url: https://ruin.nu/git/?p=ndwebbie.git;a=commitdiff_plain;h=7e20835b37901336388d4a82b59a027e83e0bcb9 Use filter instead of having to stash the function everywhere --- diff --git a/lib/NDWeb/Controller/Alliances.pm b/lib/NDWeb/Controller/Alliances.pm index 833143a..c2d40ff 100644 --- a/lib/NDWeb/Controller/Alliances.pm +++ b/lib/NDWeb/Controller/Alliances.pm @@ -62,7 +62,6 @@ sub list : Local { } . $order); $query->execute; $c->stash(alliances => $query->fetchall_arrayref({}) ); - $c->stash(comma => \&comma_value); } sub edit : Local { @@ -253,7 +252,6 @@ LIMIT 60) a push @alliances,$alliance; } $c->stash(alliances => \@alliances); - $c->stash( comma => \&comma_value) } diff --git a/lib/NDWeb/Controller/Members.pm b/lib/NDWeb/Controller/Members.pm index 440c51f..f6cbefd 100644 --- a/lib/NDWeb/Controller/Members.pm +++ b/lib/NDWeb/Controller/Members.pm @@ -29,7 +29,6 @@ sub index : Path : Args(0) { $c->stash(error => $c->flash->{error}); - $c->stash(comma => \&comma_value); $c->stash(u => $dbh->selectrow_hashref(q{SELECT planet,defense_points ,attack_points,scan_points,humor_points , (attack_points+defense_points+scan_points/20)::NUMERIC(5,1) as total_points diff --git a/lib/NDWeb/Controller/Raids.pm b/lib/NDWeb/Controller/Raids.pm index ab1adb5..6b4f16c 100644 --- a/lib/NDWeb/Controller/Raids.pm +++ b/lib/NDWeb/Controller/Raids.pm @@ -107,8 +107,6 @@ sub view : Local { $c->forward('findRaid'); $raid = $c->stash->{raid}; - $c->stash(comma => \&comma_value); - $c->stash(raid => $raid->{id}); my $planet; if ($c->user->planet){ @@ -548,7 +546,6 @@ sub targetlist : Local { my ($self, $c, $alliances, $order) = @_; my $dbh = $c->model; - $c->stash(comma => \&comma_value); $c->stash(allies => $alliances); $alliances ||= ''; my @alliances = split /,/, $alliances; diff --git a/lib/NDWeb/Controller/Rankings.pm b/lib/NDWeb/Controller/Rankings.pm index 1575d4e..b34792b 100644 --- a/lib/NDWeb/Controller/Rankings.pm +++ b/lib/NDWeb/Controller/Rankings.pm @@ -39,8 +39,6 @@ sub planets : Local { $c->detach('/default') if $offset < 0; $c->stash(offset => $offset); - $c->stash( comma => \&comma_value); - if (defined $order && $order =~ /^(scorerank|sizerank|valuerank|xprank|hit_us)$/){ $order = $1; }else { @@ -89,8 +87,6 @@ sub galaxies : Local { $c->detach('/default') if $offset < 0; $c->stash(offset => $offset); - $c->stash( comma => \&comma_value); - if (defined $order && $order =~ /^(scorerank|sizerank|valuerank|xprank|planets)$/){ $order = $1; }else{ @@ -136,8 +132,6 @@ sub alliances : Local { $c->detach('/default') if $offset < 0; $c->stash(offset => $offset); - $c->stash( comma => \&comma_value); - if (defined $order && $order =~ /^(scorerank|sizerank|valuerank|xprank|avgsize|avgscore|members)$/){ $order = $1; }else{ diff --git a/lib/NDWeb/Controller/Stats.pm b/lib/NDWeb/Controller/Stats.pm index 3ad7906..b257840 100644 --- a/lib/NDWeb/Controller/Stats.pm +++ b/lib/NDWeb/Controller/Stats.pm @@ -33,8 +33,6 @@ sub galaxy : Local { my ( $self, $c, $x, $y, $z ) = @_; my $dbh = $c->model; - $c->stash( comma => \&comma_value); - my $query = $dbh->prepare(q{SELECT x,y, size, size_gain, size_gain_day, score,score_gain,score_gain_day, diff --git a/lib/NDWeb/View/TT.pm b/lib/NDWeb/View/TT.pm index b0f8571..ac28c3f 100644 --- a/lib/NDWeb/View/TT.pm +++ b/lib/NDWeb/View/TT.pm @@ -3,11 +3,16 @@ package NDWeb::View::TT; use strict; use base 'Catalyst::View::TT'; +use NDWeb::Include; + __PACKAGE__->config({ INCLUDE_PATH => [ NDWeb->path_to( 'root', 'src' ), NDWeb->path_to( 'root', 'lib' ) ], + FILTERS => { + commify => \&comma_value, + }, PRE_PROCESS => 'config/main.tt2', WRAPPER => 'site/wrapper.tt2', ERROR => 'error.tt2', diff --git a/root/lib/inc/stats.tt2 b/root/lib/inc/stats.tt2 index 6ff6e0b..29223ec 100644 --- a/root/lib/inc/stats.tt2 +++ b/root/lib/inc/stats.tt2 @@ -27,15 +27,15 @@ [% g.xprank %] [% g.xprankimg %] [% g.x %]:[% g.y %] [% g.planetsimg = (g.planets_gain_day == 0 ? 'stay' : (g.planets_gain_day > 0 ? 'up' : 'down')) %] - [% comma(g.planets) %] [% g.planetsimg %] + [% g.planets | commify %] [% g.planetsimg %] [% g.sizeimg = (g.size_gain_day == 0 ? 'stay' : (g.size_gain_day > 0 ? 'up' : 'down')) %] - [% comma(g.size) %] [% g.sizeimg %] + [% g.size | commify %] [% g.sizeimg %] [% g.scoreimg = (g.score_gain_day == 0 ? 'stay' : (g.score_gain_day > 0 ? 'up' : 'down')) %] - [% comma(g.score) %] [% g.scoreimg %] + [% g.score | commify %] [% g.scoreimg %] [% g.valueimg = (g.value_gain_day == 0 ? 'stay' : (g.value_gain_day > 0 ? 'up' : 'down')) %] - [% comma(g.value) %] [% g.valueimg %] + [% g.value | commify %] [% g.valueimg %] [% g.xpimg = (g.xp_gain_day == 0 ? 'stay' : (g.xp_gain_day > 0 ? 'up' : 'down')) %] - [% comma(g.xp) %] [% g.xpimg %] + [% g.xp | commify %] [% g.xpimg %] [% g.ticks_roided %] [% g.ticks_roiding %] @@ -66,13 +66,13 @@ [% p.ruler %] OF [% p.planet %] [% p.race %] [% p.sizeimg = (p.size_gain_day == 0 ? 'stay' : (p.size_gain_day > 0 ? 'up' : 'down')) %] - [% comma(p.size) %] [% p.sizeimg %] + [% p.size | commify %] [% p.sizeimg %] [% p.scoreimg = (p.score_gain_day == 0 ? 'stay' : (p.score_gain_day > 0 ? 'up' : 'down')) %] - [% comma(p.score) %] [% p.scoreimg %] + [% p.score | commify %] [% p.scoreimg %] [% p.valueimg = (p.value_gain_day == 0 ? 'stay' : (p.value_gain_day > 0 ? 'up' : 'down')) %] - [% comma(p.value) %] [% p.valueimg %] + [% p.value | commify %] [% p.valueimg %] [% p.xpimg = (p.xp_gain_day == 0 ? 'stay' : (p.xp_gain_day > 0 ? 'up' : 'down')) %] - [% comma(p.xp) %] [% p.xpimg %] + [% p.xp | commify %] [% p.xpimg %] [% IF details %] [% p.gov %] [% p.fleetvalue %] ([% p.resvalue %]) diff --git a/root/src/alliances/list.tt2 b/root/src/alliances/list.tt2 index 28b9f99..75ad9b1 100644 --- a/root/src/alliances/list.tt2 +++ b/root/src/alliances/list.tt2 @@ -23,18 +23,18 @@ [% a.name %] [% a.kmem %] [% a.members %] - [% comma(a.score) %] - [% comma(a.kscore) %] - [% comma(a.scavg) %] - [% comma(a.kscavg) %] - [% comma(a.size) %] - [% comma(a.ksize) %] - [% comma(a.siavg) %] - [% comma(a.ksiavg) %] - [% comma(a.kxp) %] - [% comma(a.kxpavg) %] - [% comma(a.kvalue) %] - [% comma(a.kvalavg) %] + [% a.score | commify %] + [% a.kscore | commify %] + [% a.scavg | commify %] + [% a.kscavg | commify %] + [% a.size | commify %] + [% a.ksize | commify %] + [% a.siavg | commify %] + [% a.ksiavg | commify %] + [% a.kxp | commify %] + [% a.kxpavg | commify %] + [% a.kvalue | commify %] + [% a.kvalavg | commify %] [% END %] diff --git a/root/src/alliances/resources.tt2 b/root/src/alliances/resources.tt2 index 20c642d..a9ce498 100644 --- a/root/src/alliances/resources.tt2 +++ b/root/src/alliances/resources.tt2 @@ -17,15 +17,15 @@ [% a.name %] [% a.relationship %] [% a.members %] ([% a.planets %]) - [% comma(a.score) %] - [% comma(a.size) %] - [% comma(a.resources) %] - [% comma(a.hidden) %] - [% comma(a.resplanet) %] - [% comma(a.hidplanet) %] - [% comma(a.nscore) %] ([% a.nscore - a.score %]) - [% comma(a.nscore2) %] ([% a.nscore2 - a.score %]) - [% comma(a.nscore3) %] ([% a.nscore3 - a.score %]) + [% a.score | commify %] + [% a.size | commify %] + [% a.resources | commify %] + [% a.hidden | commify %] + [% a.resplanet | commify %] + [% a.hidplanet | commify %] + [% a.nscore | commify %] ([% a.nscore - a.score %]) + [% a.nscore2 | commify %] ([% a.nscore2 - a.score %]) + [% a.nscore3 | commify %] ([% a.nscore3 - a.score %]) [% END %] diff --git a/root/src/members/index.tt2 b/root/src/members/index.tt2 index 902c541..6d9c50b 100644 --- a/root/src/members/index.tt2 +++ b/root/src/members/index.tt2 @@ -41,13 +41,13 @@ [% p.ruler %] OF [% p.planet %] [% p.race %] [% p.sizeimg = (p.size_gain_day == 0 ? 'stay' : (p.size_gain_day > 0 ? 'up' : 'down')) %] - [% comma(p.size) %] [% p.sizeimg %] + [% p.size | commify %] [% p.sizeimg %] [% p.scoreimg = (p.score_gain_day == 0 ? 'stay' : (p.score_gain_day > 0 ? 'up' : 'down')) %] - [% comma(p.score) %] [% p.scoreimg %] + [% p.score | commify %] [% p.scoreimg %] [% p.valueimg = (p.value_gain_day == 0 ? 'stay' : (p.value_gain_day > 0 ? 'up' : 'down')) %] - [% comma(p.value) %] [% p.valueimg %] + [% p.value | commify %] [% p.valueimg %] [% p.xpimg = (p.xp_gain_day == 0 ? 'stay' : (p.xp_gain_day > 0 ? 'up' : 'down')) %] - [% comma(p.xp) %] [% p.xpimg %] + [% p.xp | commify %] [% p.xpimg %] [% END %] diff --git a/root/src/raids/targetlist.tt2 b/root/src/raids/targetlist.tt2 index 9c906b9..96c2384 100644 --- a/root/src/raids/targetlist.tt2 +++ b/root/src/raids/targetlist.tt2 @@ -32,12 +32,12 @@ [% p.coords %] [% p.alliance %] [% p.race %] - [% comma(p.score) %] - [% comma(p.value) %] - [% comma(p.xp) %] - [% comma(p.size) %] - [% comma(p.nfvalue) %] - [% comma(p.nfvalue2) %] + [% p.score | commify %] + [% p.value | commify %] + [% p.xp | commify %] + [% p.size | commify %] + [% p.nfvalue | commify %] + [% p.nfvalue2 | commify %] [% IF x != p.x OR y != p.y %] [% x = p.x; y = p.y; %] diff --git a/root/src/raids/view.tt2 b/root/src/raids/view.tt2 index f076c8f..94244af 100644 --- a/root/src/raids/view.tt2 +++ b/root/src/raids/view.tt2 @@ -33,7 +33,7 @@
  • Race: [% t.race %]
  • Cap: [% t.cap * 100 | format('%.02f') %]
  • [% FOR r IN t.roids %] -
  • Roids wave [% r.wave %]: [% r.roids %] ([% comma(r.xp) %] xp)
  • +
  • Roids wave [% r.wave %]: [% r.roids %] ([% r.xp | commify %] xp)
  • [% END %] [% IF t.comment %] @@ -45,15 +45,15 @@ MetalCrystalEonium Roids - [% comma(t.metal_roids) %] - [% comma(t.crystal_roids) %] - [% comma(t.eonium_roids) %] + [% t.metal_roids | commify %] + [% t.crystal_roids | commify %] + [% t.eonium_roids | commify %] Resources - [% comma(t.metal) %] - [% comma(t.crystal) %] - [% comma(t.eonium) %] + [% t.metal | commify %] + [% t.crystal | commify %] + [% t.eonium | commify %] @@ -102,7 +102,7 @@ [% FOR s IN m.ships %] - + [% END %]
    [% s.ship %][% comma(s.amount) %][% s.ship %][% s.amount | commify %]
    diff --git a/root/src/rankings/alliances.tt2 b/root/src/rankings/alliances.tt2 index 6e5e89b..5ea227f 100644 --- a/root/src/rankings/alliances.tt2 +++ b/root/src/rankings/alliances.tt2 @@ -25,13 +25,13 @@ [% a.membersimg = (a.members_gain_day == 0 ? 'stay' : (a.members_gain_day > 0 ? 'up' : 'down')) %] [% a.members %] [% a.membersimg %] [% a.sizeimg = (a.size_gain_day == 0 ? 'stay' : (a.size_gain_day > 0 ? 'up' : 'down')) %] - [% comma(a.size) %] [% a.sizeimg %] + [% a.size | commify %] [% a.sizeimg %] [% a.scoreimg = (a.score_gain_day == 0 ? 'stay' : (a.score_gain_day > 0 ? 'up' : 'down')) %] - [% comma(a.score) %] [% a.scoreimg %] + [% a.score | commify %] [% a.scoreimg %] [% a.avgsizeimg = (a.avgsize_gain_day == 0 ? 'stay' : (a.avgsize_gain_day > 0 ? 'up' : 'down')) %] - [% comma(a.avgsize) %] [% a.avgsizeimg %] + [% a.avgsize | commify %] [% a.avgsizeimg %] [% a.avgscoreimg = (a.avgscore_gain_day == 0 ? 'stay' : (a.avgscore_gain_day > 0 ? 'up' : 'down')) %] - [% comma(a.avgscore) %] [% a.avgscoreimg %] + [% a.avgscore | commify %] [% a.avgscoreimg %] [% END %] diff --git a/root/src/rankings/galaxies.tt2 b/root/src/rankings/galaxies.tt2 index 5b96de2..c5edc2c 100644 --- a/root/src/rankings/galaxies.tt2 +++ b/root/src/rankings/galaxies.tt2 @@ -29,15 +29,15 @@ [% g.xprank %] [% g.xprankimg %] [% g.x %]:[% g.y %] [% g.planetsimg = (g.planets_gain_day == 0 ? 'stay' : (g.planets_gain_day > 0 ? 'up' : 'down')) %] - [% comma(g.planets) %] [% g.planetsimg %] + [% g.planets | commify %] [% g.planetsimg %] [% g.sizeimg = (g.size_gain_day == 0 ? 'stay' : (g.size_gain_day > 0 ? 'up' : 'down')) %] - [% comma(g.size) %] [% g.sizeimg %] + [% g.size | commify %] [% g.sizeimg %] [% g.scoreimg = (g.score_gain_day == 0 ? 'stay' : (g.score_gain_day > 0 ? 'up' : 'down')) %] - [% comma(g.score) %] [% g.scoreimg %] + [% g.score | commify %] [% g.scoreimg %] [% g.valueimg = (g.value_gain_day == 0 ? 'stay' : (g.value_gain_day > 0 ? 'up' : 'down')) %] - [% comma(g.value) %] [% g.valueimg %] + [% g.value | commify %] [% g.valueimg %] [% g.xpimg = (g.xp_gain_day == 0 ? 'stay' : (g.xp_gain_day > 0 ? 'up' : 'down')) %] - [% comma(g.xp) %] [% g.xpimg %] + [% g.xp | commify %] [% g.xpimg %] [% END %] diff --git a/root/src/rankings/planets.tt2 b/root/src/rankings/planets.tt2 index b55b625..b0829a2 100644 --- a/root/src/rankings/planets.tt2 +++ b/root/src/rankings/planets.tt2 @@ -38,13 +38,13 @@ [% p.ruler %] OF [% p.planet %] [% p.race %] [% p.sizeimg = (p.size_gain_day == 0 ? 'stay' : (p.size_gain_day > 0 ? 'up' : 'down')) %] - [% comma(p.size) %] [% p.sizeimg %] + [% p.size | commify %] [% p.sizeimg %] [% p.scoreimg = (p.score_gain_day == 0 ? 'stay' : (p.score_gain_day > 0 ? 'up' : 'down')) %] - [% comma(p.score) %] [% p.scoreimg %] + [% p.score | commify %] [% p.scoreimg %] [% p.valueimg = (p.value_gain_day == 0 ? 'stay' : (p.value_gain_day > 0 ? 'up' : 'down')) %] - [% comma(p.value) %] [% p.valueimg %] + [% p.value | commify %] [% p.valueimg %] [% p.xpimg = (p.xp_gain_day == 0 ? 'stay' : (p.xp_gain_day > 0 ? 'up' : 'down')) %] - [% comma(p.xp) %] [% p.xpimg %] + [% p.xp | commify %] [% p.xpimg %] [% IF extracolumns %] [% p.nick %]([% p.planet_stats %]) diff --git a/root/src/stats/planet.tt2 b/root/src/stats/planet.tt2 index 1c10eb2..b139081 100644 --- a/root/src/stats/planet.tt2 +++ b/root/src/stats/planet.tt2 @@ -12,15 +12,15 @@ TypeRoidsResources Metal [% planetscan.metal_roids %] - [% comma(planetscan.metal) %] + [% planetscan.metal | commify %] Crystal [% planetscan.crystal_roids %] - [% comma(planetscan.crystal) %] + [% planetscan.crystal | commify %] Eonium [% planetscan.eonium_roids %] - [% comma(planetscan.eonium) %] + [% planetscan.eonium | commify %] AgentsGuards [% planetscan.agents %] @@ -31,7 +31,7 @@ [% planetscan.light %] [% planetscan.medium %][% planetscan.heavy %] - Hidden:[% comma(planetscan.hidden) %] + Hidden:[% planetscan.hidden | commify %] [% END %] [% IF devscan.tick %]