X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FGitalist%2FModel%2FContentMangler.pm;h=61823622b74dc21434718c57a76a967247a4f772;hb=52990a5805d5e56812ee53e52ec2b5fe96938335;hp=400f629c1a9b759d7a4ffb481afa83801843edd4;hpb=6573774fffb362733705a9ffc6f90d158b3a13e8;p=catagits%2FGitalist.git diff --git a/lib/Gitalist/Model/ContentMangler.pm b/lib/Gitalist/Model/ContentMangler.pm index 400f629..6182362 100644 --- a/lib/Gitalist/Model/ContentMangler.pm +++ b/lib/Gitalist/Model/ContentMangler.pm @@ -1,7 +1,62 @@ package Gitalist::Model::ContentMangler; use Moose; +use MooseX::Types::Moose qw/HashRef/; +use MooseX::Types::Common::String qw/NonEmptySimpleStr/; +use Gitalist::ContentMangler::Resolver; use namespace::autoclean; extends 'Catalyst::Model'; +has resolver_class => ( + isa => NonEmptySimpleStr, + is => 'ro', + required => 1, + default => 'Gitalist::ContentMangler::Resolver::Default', +); + +has resolver_config => ( + isa => HashRef, + is => 'ro', + default => sub { {} }, +); + +has _resolver => ( + does => 'Gitalist::ContentMangler::Resolver', + handles => ['resolve'], + is => 'bare', lazy => 1, + default => sub { + my $self = shift; + my $class = $self->resolver_class; + Class::MOP::load_class($class); + return $class->new($self->resolver_config); + }, +); + +# FIXME This method is a gross hack. +# +# We need to work out what types of content mangles we have for various things based on hit type +# file name and mime type, and perform the appropriate bits.. + +# We need to support multiple languages, and we also want to be able to do HTMLizing (for e.g. Pod) + +sub process { + my ($self, $c) = @_; + + # Find appropriate mangler based on filename,action,config + # Mangler should provide a transform e.g what part of the stash to mangle + # Then call the transform with the appropriate mangling + + my($transformer, $config) = $self->resolve({ + filename => $c->stash->{filename} || '', + config => Gitalist->config->{'Model::ContentMangler'}, + action => $c->action->name, + }); + + return + unless $transformer; + + Class::MOP::load_class($transformer); + $transformer->new($config)->transform($c, $config); +} + __PACKAGE__->meta->make_immutable;