From 4ad1eed3fe0f8a90080c63ec474e4634376f0f95 Mon Sep 17 00:00:00 2001 From: groditi Date: Sat, 11 Jul 2009 22:59:02 +0000 Subject: wire layout_args, which was somehow never connected to the mix --- Changes | 1 + lib/ComponentUI/Controller/Root.pm | 11 ++++++++++- lib/ComponentUI/UI/Widget/Index.pm | 15 +++++++++++++++ lib/Reaction/UI/View.pm | 3 ++- lib/Reaction/UI/ViewPort.pm | 10 ++++++++++ share/skin/componentui/layout/index.tt | 6 ++++-- share/skin/defaults.conf | 1 + 7 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 lib/ComponentUI/UI/Widget/Index.pm diff --git a/Changes b/Changes index 01d8ba4..e2e42f2 100644 --- a/Changes +++ b/Changes @@ -10,6 +10,7 @@ Revision history for Reaction - Adapt widget and layout to changes - Add example of explicitly stating action to ComponentUI - Don't override custom location in push_viewport + - Wire layout_args, which was forgotten + example of how to use it 0.002000 - 29 Apr 2008 - Update CheckUniques role to use around instead of overrides - Stop using ACCEPT_CONTEXT, use InstancePerContext instead diff --git a/lib/ComponentUI/Controller/Root.pm b/lib/ComponentUI/Controller/Root.pm index e0935d9..9a2017f 100644 --- a/lib/ComponentUI/Controller/Root.pm +++ b/lib/ComponentUI/Controller/Root.pm @@ -33,7 +33,16 @@ sub base :Chained('/') :PathPart('') :CaptureArgs(0) { sub root :Chained('base') :PathPart('') :Args(0) { my ($self, $c) = @_; - $self->push_viewport(ViewPort, layout => 'index'); + $self->push_viewport( + ViewPort, ( + layout => 'index', + layout_args => { + user_agent => $c->request->user_agent, + message_to_layout => 'I hate programming.', + }, + ), + ); + $c->log->debug('remote', $c->request->remote_user ); } sub bye :Chained('base') :PathPart('bye') :Args(0) { diff --git a/lib/ComponentUI/UI/Widget/Index.pm b/lib/ComponentUI/UI/Widget/Index.pm new file mode 100644 index 0000000..5421d7d --- /dev/null +++ b/lib/ComponentUI/UI/Widget/Index.pm @@ -0,0 +1,15 @@ +package ComponentUI::UI::Widget::Index; + +use Reaction::UI::WidgetClass; +use namespace::clean -except => [ qw(meta) ]; + +after fragment widget { + $_{viewport}->ctx->log->debug('widget'); + arg message_to_layout => $_{layout_message}; +}; + +__PACKAGE__->meta->make_immutable; + +1; + +__END__ diff --git a/lib/Reaction/UI/View.pm b/lib/Reaction/UI/View.pm index bdd04a2..f81929d 100644 --- a/lib/Reaction/UI/View.pm +++ b/lib/Reaction/UI/View.pm @@ -65,7 +65,8 @@ sub render_viewport_args { my ($self, $vp) = @_; my $layout_set = $self->layout_set_for($vp); my $widget = $self->widget_for($vp, $layout_set); - return ($widget, { viewport => $vp }); + my %layout_args = (%{ $vp->layout_args }, viewport => $vp); + return ($widget, \%layout_args); }; sub widget_for { my ($self, $vp, $layout_set) = @_; diff --git a/lib/Reaction/UI/ViewPort.pm b/lib/Reaction/UI/ViewPort.pm index c86c793..ed9722e 100644 --- a/lib/Reaction/UI/ViewPort.pm +++ b/lib/Reaction/UI/ViewPort.pm @@ -250,6 +250,16 @@ The layout attribute can either be specifically passed when calling C, or it will be determined using the last part of the ViewPorts classname. +=item layout_args + +This read-only hashref attribute will pass all it's keys as variables to the +layout at render time. They should be accessible from both the layout templates +and the widget, if applicable, through the C<%_> hash. + + $controller->push_viewport(VPName, layout => 'foo', layout_args => { bar => 'bar'}); + $_{bar} #in widget + [% bar %] in template + =item column_order This is generally used by more specialised ViewPorts such as the diff --git a/share/skin/componentui/layout/index.tt b/share/skin/componentui/layout/index.tt index 9a9bc9c..787d850 100644 --- a/share/skin/componentui/layout/index.tt +++ b/share/skin/componentui/layout/index.tt @@ -1,5 +1,7 @@ +=widget Index + =for layout widget -

I hate programming.

+

[% user_agent %] sucks. [% message_to_layout %]

-=cut \ No newline at end of file +=cut diff --git a/share/skin/defaults.conf b/share/skin/defaults.conf index b7d630e..509e1b1 100644 --- a/share/skin/defaults.conf +++ b/share/skin/defaults.conf @@ -1 +1,2 @@ +widget_search_path ComponentUI::UI::Widget widget_search_path Reaction::UI::Widget -- cgit v1.2.3-54-g00ecf