Bug fix for merge diffs and a test.
[catagits/Gitalist.git] / lib / Gitalist / Model / ContentMangler.pm
CommitLineData
6573774f 1package Gitalist::Model::ContentMangler;
2use Moose;
cea75f84 3use MooseX::Types::Moose qw/HashRef/;
dbfbfe18 4use MooseX::Types::Common::String qw/NonEmptySimpleStr/;
5use Gitalist::ContentMangler::Resolver;
6573774f 6use namespace::autoclean;
7
8extends 'Catalyst::Model';
9
dbfbfe18 10has resolver_class => (
11 isa => NonEmptySimpleStr,
12 is => 'ro',
13 required => 1,
14 default => 'Gitalist::ContentMangler::Resolver::Default',
15);
16
17has resolver_config => (
cea75f84 18 isa => HashRef,
19 is => 'ro',
20 default => sub { {} },
dbfbfe18 21);
22
23has _resolver => (
24 does => 'Gitalist::ContentMangler::Resolver',
25 handles => ['resolve'],
26 is => 'bare', lazy => 1,
27 default => sub {
28 my $self = shift;
29 my $class = $self->resolver_class;
30 Class::MOP::load_class($class);
31 return $class->new($self->resolver_config);
cea75f84 32 },
33);
34
35# FIXME This method is a gross hack.
36#
37# We need to work out what types of content mangles we have for various things based on hit type
38# file name and mime type, and perform the appropriate bits..
39
40# We need to support multiple languages, and we also want to be able to do HTMLizing (for e.g. Pod)
41
42sub process {
43 my ($self, $c) = @_;
44
dbfbfe18 45 my @steps = $self->resolve({ filename => $c->stash->{filename} });
46 my @css = map { $_->[1]->{css} } grep { exists $_->[1] && exists $_->[1]->{css} && defined $_->[1]->{css} && length $_->[1]->{css} } @steps;
1064e5b8 47 $c->stash(
48 syntax_css => [ map { $c->uri_for('/static/css/syntax/' . $_ . '.css') } @css ],
49 mangled => scalar @steps,
50 );
cea75f84 51
52 if ($c->stash->{blobs} || $c->stash->{blob}) {
dbfbfe18 53 foreach my $step (@steps) {
54 for ($c->stash->{blobs} ? @{$c->stash->{blobs}} : $c->stash->{blob}) {
55 $_ = $c->view($step->[0])->render($c, $_, $step->[1]);
56 }
cea75f84 57 }
58 }
59}
60
6573774f 61__PACKAGE__->meta->make_immutable;