Skip to content

Commit

Permalink
making the Action::Link more generic
Browse files Browse the repository at this point in the history
  • Loading branch information
Stevan Little committed Jan 23, 2010
1 parent e0e7909 commit ff96dc4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 34 deletions.
2 changes: 1 addition & 1 deletion lib/OX/View/Nib/Action.pm
Expand Up @@ -7,7 +7,7 @@ our $AUTHORITY = 'cpan:STEVAN';
has 'binding' => (
init_arg => 'bind_to',
is => 'ro',
isa => 'Str | HashRef',
isa => 'HashRef',
required => 1,
);

Expand Down
30 changes: 1 addition & 29 deletions lib/OX/View/Nib/Action/Link.pm
Expand Up @@ -14,36 +14,8 @@ has 'body' => (

sub resolve {
my ($self, $nib, $request) = @_;

my ($full_name, $controller, $action);

my $additional = {};

my $binding = $self->binding;

if (ref $binding) {
($full_name) = keys %{ $binding };
($additional) = values %{ $binding };
}
else {
$full_name = $binding;
}

if ( $full_name =~ /\// ) {
($controller, $action) = split /\// => $full_name;
}
else {
$action = $full_name;
}

my $route = {
controller => $controller,
action => $action,
%$additional
};

return '<a href="'
. $request->uri_for( $route )
. $request->uri_for( $self->binding )
. '">'
. $self->body
. '</a>';
Expand Down
8 changes: 4 additions & 4 deletions t/apps/Counter-Over-Engineered/root/templates/index.tmpl
Expand Up @@ -3,17 +3,17 @@
<body>
<h1>[% outlet({ type => 'text', bind_to => 'model/count' }) %]</h1>
<hr/>
[% action({ type => 'link', bind_to => 'inc', body => '++' }) %]
[% action({ type => 'link', bind_to => { controller => 'root', action => 'inc' }, body => '++' }) %]
&nbsp;&nbsp;|&nbsp;&nbsp;
[% action({ type => 'link', bind_to => 'dec', body => '--' }) %]
[% action({ type => 'link', bind_to => { controller => 'root', action => 'dec' }, body => '--' }) %]
&nbsp;&nbsp;|&nbsp;&nbsp;
[% action({ type => 'link', bind_to => 'reset', body => 'reset' }) %]
[% action({ type => 'link', bind_to => { controller => 'root', action => 'reset' }, body => 'reset' }) %]
<hr/>
[% FOREACH num IN [ 100, 200, 1000 ] %]
[%
action({
type => 'link',
bind_to => { 'set' => { number => num } },
bind_to => { controller => 'root', action => 'set', number => num },
body => 'set to ' _ num
})
%]<br/>
Expand Down

0 comments on commit ff96dc4

Please sign in to comment.