Added first cut of /shortlog action and simplified the parse_rev_list() method.
[catagits/Gitalist.git] / lib / Gitalist / View / SyntaxHighlight.pm
1 package Gitalist::View::SyntaxHighlight;
2 use Moose;
3 use Gitalist; # ->path_to
4 use namespace::autoclean;
5
6 extends 'Catalyst::View';
7
8 use Syntax::Highlight::Engine::Kate ();
9 use Syntax::Highlight::Engine::Kate::Perl ();
10
11 use HTML::Entities qw(encode_entities);
12
13 sub process {
14     my($self, $c) = @_;
15
16     # If we're not going to highlight the blob unsure that it's ready to go
17     # into HTML at least.
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     }
53
54     $c->forward('View::Default');
55 }
56
57 __PACKAGE__->meta->make_immutable;