Commit | Line | Data |
03297637 |
1 | package Gitalist::Model::ContentMangler; |
2 | use Moose; |
b2e0fe31 |
3 | use MooseX::Types::Moose qw/HashRef/; |
7c781a87 |
4 | use MooseX::Types::Common::String qw/NonEmptySimpleStr/; |
5 | use Gitalist::ContentMangler::Resolver; |
03297637 |
6 | use namespace::autoclean; |
7 | |
8 | extends 'Catalyst::Model'; |
9 | |
7c781a87 |
10 | has resolver_class => ( |
11 | isa => NonEmptySimpleStr, |
12 | is => 'ro', |
13 | required => 1, |
14 | default => 'Gitalist::ContentMangler::Resolver::Default', |
15 | ); |
16 | |
17 | has resolver_config => ( |
b2e0fe31 |
18 | isa => HashRef, |
19 | is => 'ro', |
20 | default => sub { {} }, |
7c781a87 |
21 | ); |
22 | |
23 | has _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); |
b2e0fe31 |
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 | |
42 | sub process { |
bfa60830 |
43 | my ($self, $c) = @_; |
44 | |
45 | # Find appropriate mangler based on filename,action,config |
46 | # Mangler should provide a transform e.g what part of the stash to mangle |
47 | # Then call the transform with the appropriate mangling |
48 | |
49 | my($transformer, $config) = $self->resolve({ |
50 | filename => $c->stash->{filename} || '', |
51 | config => Gitalist->config->{'Model::ContentMangler'}, |
52 | action => $c->action->name, |
53 | }); |
54 | |
55 | return |
56 | unless $transformer; |
57 | |
58 | Class::MOP::load_class($transformer); |
59 | $transformer->new($config)->transform($c, $config); |
b2e0fe31 |
60 | } |
61 | |
03297637 |
62 | __PACKAGE__->meta->make_immutable; |