| 1 | package Silki::Help::File; | ||
| 2 | { | ||
| 3 | $Silki::Help::File::VERSION = '0.29'; | ||
| 4 | } | ||
| 5 | |||
| 6 | use strict; | ||
| 7 | use warnings; | ||
| 8 | use namespace::autoclean; | ||
| 9 | |||
| 10 | use File::Slurp qw( read_file ); | ||
| 11 | use HTML::Entities qw( encode_entities ); | ||
| 12 | use HTML::Mason::Interp; | ||
| 13 | use Silki::Types qw( ArrayRef File HashRef Str ); | ||
| 14 | |||
| 15 | use Moose; | ||
| 16 | use MooseX::SemiAffordanceAccessor; | ||
| 17 | |||
| 18 | has file => ( | ||
| 19 | is => 'ro', | ||
| 20 | isa => File, | ||
| 21 | required => 1, | ||
| 22 | ); | ||
| 23 | |||
| 24 | has locale_code => ( | ||
| 25 | is => 'ro', | ||
| 26 | isa => Str, | ||
| 27 | required => 1, | ||
| 28 | ); | ||
| 29 | |||
| 30 | has content => ( | ||
| 31 | is => 'ro', | ||
| 32 | isa => Str, | ||
| 33 | init_arg => undef, | ||
| 34 | lazy => 1, | ||
| 35 | builder => '_build_content', | ||
| 36 | ); | ||
| 37 | |||
| 38 | sub _build_content { | ||
| 39 | my $self = shift; | ||
| 40 | |||
| 41 | my $config = Silki::Config->instance(); | ||
| 42 | |||
| 43 | my %config = ( | ||
| 44 | comp_root => $self->file()->dir()->stringify(), | ||
| 45 | data_dir => | ||
| 46 | $config->cache_dir() | ||
| 47 | ->subdir( 'mason', 'help', $self->locale_code() )->stringify(), | ||
| 48 | error_mode => 'fatal', | ||
| 49 | in_package => 'Silki::Mason::Help', | ||
| 50 | default_escape_flags => 'h', | ||
| 51 | ); | ||
| 52 | |||
| 53 | if ( $config->is_production() ) { | ||
| 54 | $config{static_source} = 1; | ||
| 55 | $config{static_source_touch_file} | ||
| 56 | = $config->etc_dir()->file('mason-touch')->stringify(); | ||
| 57 | } | ||
| 58 | |||
| 59 | my $body = q{}; | ||
| 60 | my $interp = HTML::Mason::Interp->new( | ||
| 61 | out_method => \$body, | ||
| 62 | %config, | ||
| 63 | ); | ||
| 64 | |||
| 65 | $interp->exec( q{/} . $self->file()->basename() ); | ||
| 66 | |||
| 67 | return $body; | ||
| 68 | } | ||
| 69 | |||
| 70 | __PACKAGE__->meta()->make_immutable(); | ||
| 71 | |||
| 72 | 1; | ||
| 73 | |||
| 74 | # ABSTRACT: A single help file | ||
| 75 | |||
| 76 | __END__ |