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
CommitLineData
6573774f 1package Gitalist::Model::ContentMangler;
2use Moose;
cea75f84 3use MooseX::Types::Moose qw/HashRef/;
6573774f 4use namespace::autoclean;
5
6extends 'Catalyst::Model';
7
cea75f84 8# FIXME - Never cleared!!
9has _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
28sub 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
6573774f 45__PACKAGE__->meta->make_immutable;