Commit | Line | Data |
f22d4e6f |
1 | package CatalystX::HelpText::Model; |
2 | use Moose; |
3 | use MooseX::Types::Moose qw/Str Undef/; |
4 | use MooseX::Types::Path::Class qw/ Dir /; |
5 | use Moose::Autobox; |
6 | use Carp qw/ croak confess/; |
7 | use namespace::autoclean; |
8 | |
9 | extends 'Catalyst::Model'; |
10 | |
11 | has help_files_path => ( |
12 | is => 'ro', |
13 | isa => Dir, |
14 | coerce => 1, |
15 | required => 1, |
16 | handles => { |
17 | _get_file => 'file', |
18 | } |
19 | ); |
20 | |
21 | has help_files_ext => ( |
22 | is => 'ro', |
23 | isa => Str|Undef, |
24 | default => 'html', |
25 | ); |
26 | |
69ca94ae |
27 | has wrapper_css_class => ( |
28 | is => 'ro', |
29 | isa => Str, |
30 | default => 'help_text', |
31 | ); |
32 | |
33 | has wrapper_tag => ( |
34 | is => 'ro', |
35 | isa => Str, |
36 | default => 'span', |
37 | ); |
38 | |
39 | |
f22d4e6f |
40 | sub 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 | |
61 | 1; |
62 | |