search spec components factored out of T365
[catagits/Reaction.git] / lib / Reaction / UI / Widget / URI.pm
1 package Reaction::UI::Widget::URI;
2
3 use Reaction::UI::WidgetClass;
4 use namespace::clean -except => [ qw(meta) ];
5
6 before fragment widget {
7   arg uri => $_{viewport}->uri;
8 };
9
10 implements fragment display_fragment {
11   my $vp = $_{viewport};
12   return unless $vp->has_display;
13   my $display = $vp->display;
14   if( blessed($display) && $display->isa('Reaction::UI::ViewPort')){
15     arg '_' => $display;
16     render 'viewport';
17   } else {
18     arg string_value => $display;
19     render 'display_string';
20   }
21 };
22
23 __PACKAGE__->meta->make_immutable;
24
25
26 1;
27
28 __END__;
29
30 =head1 NAME
31
32 Reaction::UI::Widget::URI - A hyperlink reference by URI value
33
34 =head1 DESCRIPTION
35
36 This widget allows a layout template to render a hyperlink with either a
37 simple string or another viewport as the contents of the link.
38
39 =head1 FRAGMENTS
40
41 =head2 widget
42
43 Before the C<widget> fragment is rendered, the C<uri> argument will be set
44 to the return value of the C<uri> method on the viewport. The layout
45 will render a hyperlink with the C<uri> as value of the C<href> attribute and
46 the C<display_fragment> fragment as content of the element.
47
48 =head2 display_fragment
49
50 This will render nothing if the viewport doesn't return true when C<has_display>
51 is called on it. If it has a C<display> defined and it is a viewport, the C<_>
52 argument will be set to it and the C<viewport> fragment (inherited from
53 L<Reaction::UI::Widget> will be rendered. If the C<display> is not a viewport,
54 the C<string_value> argument will be set and the C<display_string> layout
55 will be rendered.
56
57 C<display_fragment> is only implemented in the widget class.
58
59 =head2 display_string
60
61 Only implemented in the layout set. This will simply output the value of the
62 C<string_value> argument as content of the hyperlink element.
63
64 =head1 LAYOUT SET
65
66   share/skin/base/layout/uri.tt
67
68 This layout set will look for a widget called C<URI> in the 
69 C<widget_search_path>.
70
71 =head1 AUTHORS
72
73 See L<Reaction::Class> for authors.
74
75 =head1 LICENSE
76
77 See L<Reaction::Class> for the license.
78
79 =cut