Added first cut of /shortlog action and simplified the parse_rev_list() method.
[catagits/Gitalist.git] / lib / Gitalist / View / SyntaxHighlight.pm
CommitLineData
7e54e579 1package Gitalist::View::SyntaxHighlight;
2use Moose;
3use Gitalist; # ->path_to
4use namespace::autoclean;
5
6extends 'Catalyst::View';
7
8use Syntax::Highlight::Engine::Kate ();
9use Syntax::Highlight::Engine::Kate::Perl ();
10
c8870bd3 11use HTML::Entities qw(encode_entities);
12
7e54e579 13sub process {
14 my($self, $c) = @_;
c8870bd3 15
47495599 16 # If we're not going to highlight the blob unsure that it's ready to go
17 # into HTML at least.
c8870bd3 18 if($c->stash->{filename} =~ /\.p[lm]$/) {
19 # via
20 # http://github.com/jrockway/angerwhale/blob/master/lib/Angerwhale/Format/Pod.pm#L136
21 eval {
22 no warnings 'redefine';
23 local *Syntax::Highlight::Engine::Kate::Template::logwarning
24 = sub { die @_ }; # i really don't care
25 my $hl = Syntax::Highlight::Engine::Kate->new(
26 language => 'Perl',
27 substitutions => {
28 "<" => "&lt;",
29 ">" => "&gt;",
30 "&" => "&amp;",
31 q{'} => "&apos;",
32 q{"} => "&quot;",
33 },
34 format_table => {
35 # convert Kate's internal representation into
36 # <span class="<internal name>"> value </span>
37 map {
38 $_ => [ qq{<span class="$_">}, '</span>' ]
39 }
40 qw/Alert BaseN BString Char Comment DataType
41 DecVal Error Float Function IString Keyword
42 Normal Operator Others RegionMarker Reserved
43 String Variable Warning/,
44 },
45 );
46
47 $c->stash->{blob} = $hl->highlightText($c->stash->{blob});
48 };
49 warn $@ if $@;
50 } else {
51 $c->stash->{blob} = encode_entities($c->stash->{blob});
52 }
7e54e579 53
54 $c->forward('View::Default');
55}
56
1ef8dc7d 57__PACKAGE__->meta->make_immutable;