Add a view for testing with
Tomas Doran [Tue, 27 Sep 2011 14:50:03 +0000 (15:50 +0100)]
Makefile.PL
lib/CatalystX/HelpText/ViewRole.pm [new file with mode: 0644]
t/lib/TestApp/View/HTML.pm [new file with mode: 0644]

index a80495a..6a35fb9 100644 (file)
@@ -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 (file)
index 0000000..d56182d
--- /dev/null
@@ -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 (file)
index 0000000..7b636a2
--- /dev/null
@@ -0,0 +1,10 @@
+package TestApp::View::HTML;
+use Moose;
+use namespace::autoclean;
+
+extends 'Catalyst::View::TT';
+
+with 'CatalystX::HelpText::ViewRole';
+
+1;
+