added wrapper tag
[catagits/CatalystX-HelpText.git] / lib / CatalystX / HelpText / Model.pm
CommitLineData
f22d4e6f 1package CatalystX::HelpText::Model;
2use Moose;
3use MooseX::Types::Moose qw/Str Undef/;
4use MooseX::Types::Path::Class qw/ Dir /;
5use Moose::Autobox;
6use Carp qw/ croak confess/;
7use namespace::autoclean;
8
9extends 'Catalyst::Model';
10
11has help_files_path => (
12 is => 'ro',
13 isa => Dir,
14 coerce => 1,
15 required => 1,
16 handles => {
17 _get_file => 'file',
18 }
19);
20
21has help_files_ext => (
22 is => 'ro',
23 isa => Str|Undef,
24 default => 'html',
25);
26
69ca94ae 27has wrapper_css_class => (
28 is => 'ro',
29 isa => Str,
30 default => 'help_text',
31);
32
33has wrapper_tag => (
34 is => 'ro',
35 isa => Str,
36 default => 'span',
37);
38
39
f22d4e6f 40sub get_help_text_for {
41 my ($self, $help_key) = @_;
42 confess('No $help_key provided') unless $help_key;
43
44 my $fn = $help_key;
45 $fn .= "." . $self->help_files_ext if defined($self->help_files_ext);
46
47 my $file = $self->_get_file($fn);
48
69ca94ae 49 if ( -e $file ) {
50 return sprintf('<%s class="%s">%s</%s>',
51 $self->wrapper_tag,
52 $self->wrapper_css_class,
53 $file->slurp,
54 $self->wrapper_tag
55 );
56 }
f22d4e6f 57
58 croak "Cannot find help text '$help_key' in $file";
59}
60
611;
62