From: Tomas Doran Date: Tue, 27 Sep 2011 14:50:03 +0000 (+0100) Subject: Add a view for testing with X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalystX-HelpText.git;a=commitdiff_plain;h=c8c4f0560e53738b970d397bfd5a7428ef4adeaa Add a view for testing with --- diff --git a/Makefile.PL b/Makefile.PL index a80495a..6a35fb9 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -14,6 +14,7 @@ requires 'Moose::Autobox'; requires 'MooseX::Types'; build_requires 'Catalyst::Runtime' => '5.80015'; +build_requires 'Catalyst::View::TT' => '0.37'; build_requires 'Test::WWW::Mechanize::Catalyst'; build_requires 'Test::More' => '0.88'; diff --git a/lib/CatalystX/HelpText/ViewRole.pm b/lib/CatalystX/HelpText/ViewRole.pm new file mode 100644 index 0000000..d56182d --- /dev/null +++ b/lib/CatalystX/HelpText/ViewRole.pm @@ -0,0 +1,43 @@ +package CatalystX::HelpText::ViewRole; +use Moose::Role; +use Try::Tiny; + +requires 'expose_methods'; + +around expose_methods => sub { + my ($orig, $self, @args) = @_; + my @m = $self->$orig(@args)->flatten; + [ @m, 'help_text' ]; +}; + +sub help_text { + my ($self, $c, $key) = @_; + try { + return $c->model('Help')->get_help_text_for($c, $key); + } + catch { + $c->log->warn("Error retrieving help_text: ".$_); + return ''; + }; +} + +1; + +=head1 NAME + +CatalystX::HelpText::ViewRole - Role to be applied to Views + +=head1 SYNOPSIS + + package MyApp::View::HTML; + use Moose; + + extends 'Catalyst::View::TT'; + with 'CatalystX::HelpText::ViewRole'; + + ... then, in your template code ... + + [% helptext('SomeHelpTopic') %] + +=cut + diff --git a/t/lib/TestApp/View/HTML.pm b/t/lib/TestApp/View/HTML.pm new file mode 100644 index 0000000..7b636a2 --- /dev/null +++ b/t/lib/TestApp/View/HTML.pm @@ -0,0 +1,10 @@ +package TestApp::View::HTML; +use Moose; +use namespace::autoclean; + +extends 'Catalyst::View::TT'; + +with 'CatalystX::HelpText::ViewRole'; + +1; +