Commit | Line | Data |
89b70ba7 |
1 | package Reaction::UI::Controller::Root; |
7adfd53f |
2 | |
3 | use base qw/Reaction::UI::Controller/; |
4 | use Reaction::Class; |
5 | use Reaction::UI::Window; |
6 | |
7 | __PACKAGE__->config( |
8 | view_name => 'XHTML', |
9 | content_type => 'text/html', |
10 | ); |
11 | |
12 | has 'view_name' => (isa => 'Str', is => 'rw'); |
13 | has 'content_type' => (isa => 'Str', is => 'rw'); |
14 | has 'window_title' => (isa => 'Str', is => 'rw'); |
15 | |
16 | sub begin :Private { |
17 | my ($self, $ctx) = @_; |
1810d302 |
18 | $ctx->stash( |
19 | window => Reaction::UI::Window->new( |
20 | ctx => $ctx, |
21 | view_name => $self->view_name, |
22 | content_type => $self->content_type, |
23 | title => $self->window_title, |
24 | ) |
25 | ); |
26 | $ctx->stash(focus_stack => $ctx->stash->{window}->focus_stack); |
7adfd53f |
27 | } |
28 | |
29 | sub end :Private { |
1810d302 |
30 | my ($self, $ctx) = @_; |
31 | $ctx->stash->{window}->flush; |
7adfd53f |
32 | } |
33 | |
34 | 1; |
35 | |
36 | =head1 NAME |
37 | |
68f88d4e |
38 | Reaction::UI::Controller::Root - Base component for the Root Controller |
7adfd53f |
39 | |
40 | =head1 SYNOPSIS |
41 | |
42 | package MyApp::Controller::Root; |
68f88d4e |
43 | use base 'Reaction::UI::Controller::Root'; |
7adfd53f |
44 | |
c2bd9d41 |
45 | __PACKAGE__->config( |
46 | view_name => 'Site', |
47 | window_title => 'Reaction Test App', |
48 | namespace => '' |
49 | ); |
50 | |
7adfd53f |
51 | # Create UI elements: |
52 | $c->stash->{focus_stack}->push_viewport('Reaction::UI::ViewPort'); |
53 | |
54 | # Access the window title in a template: |
55 | [% window.title %] |
56 | |
57 | =head1 DESCRIPTION |
58 | |
59 | Using this module as a base component for your L<Catalyst> Root |
60 | Controller provides automatic creation of a L<Reaction::UI::Window> |
61 | object containing an empty L<Reaction::UI::FocusStack> for your UI |
62 | elements. The stack is also resolved and rendered for you in the |
63 | C<end> action. |
64 | |
bdc404da |
65 | At the C<begin> of each request, a L<Reaction::UI::Window> object is |
66 | created using the configured L</view_name>, L</content_type> and |
67 | L</window_title>. These thus should be directly changed on the stashed |
68 | window object at runtime, if needed. |
69 | |
7adfd53f |
70 | =head1 METHODS |
71 | |
72 | =head2 view_name |
73 | |
74 | =over |
75 | |
76 | =item Arguments: $viewname? |
77 | |
78 | =back |
79 | |
c2bd9d41 |
80 | Set or retrieve the classname of the view used to render the UI. Can |
81 | also be set by a call to config. Defaults to 'XHTML'. |
7adfd53f |
82 | |
83 | =head2 content_type |
84 | |
85 | =over |
86 | |
87 | =item Arguments: $contenttype? |
88 | |
89 | =back |
90 | |
c2bd9d41 |
91 | Set or retrieve the content type of the page created. Can also be set |
92 | by a call to config or in a config file. Defaults to 'text/html'. |
7adfd53f |
93 | |
94 | =head2 window_title |
95 | |
96 | =over |
97 | |
98 | =item Arguments: $windowtitle? |
99 | |
100 | =back |
101 | |
c2bd9d41 |
102 | Set or retrieve the title of the page created. Can also be set by a |
103 | call to config or in a config file. No default. |
7adfd53f |
104 | |
105 | =head1 AUTHORS |
106 | |
107 | See L<Reaction::Class> for authors. |
108 | |
109 | =head1 LICENSE |
110 | |
111 | See L<Reaction::Class> for the license. |
112 | |
113 | =cut |