Aaaaaand the logic (such as it is) for syntax stuff is pretty much is where I wanted it.
[catagits/Gitalist.git] / lib / Gitalist / Model / ContentMangler.pm
1 package Gitalist::Model::ContentMangler;
2 use Moose;
3 use MooseX::Types::Moose qw/HashRef/;
4 use namespace::autoclean;
5
6 extends 'Catalyst::Model';
7
8 # FIXME - Never cleared!!
9 has _languages => (
10     isa => HashRef,
11     is => 'ro',
12     default => sub { {} },
13     traits => ['Hash'],
14     handles => {
15         _add_language => 'set',
16         languages => 'keys',
17         css => 'values',
18     },
19 );
20
21 # FIXME This method is a gross hack.
22 #
23 # We need to work out what types of content mangles we have for various things based on hit type
24 # file name and mime type, and perform the appropriate bits..
25
26 # We need to support multiple languages, and we also want to be able to do HTMLizing (for e.g. Pod)
27
28 sub process {
29     my ($self, $c) = @_;
30
31     # XXX Hack hack hack
32     my $language = $c->stash->{language} || '';
33     $language = 'Perl' if $c->stash->{filename} =~ /\.p[lm]$/i;
34     # FIXME - MOAR..
35
36     $self->_add_language($language, $c->uri_for('/static/css/syntax/' . $language . '.css')) if $language;
37     
38     if ($c->stash->{blobs} || $c->stash->{blob}) {
39         for($c->stash->{blobs} ? @{$c->stash->{blobs}} : $c->stash->{blob}) {
40             $_ = $c->view('SyntaxHighlight')->render($c, $_, { language => $language });
41         }
42     }
43 }
44
45 __PACKAGE__->meta->make_immutable;