[Jifty-commit] r4269 - in jifty/trunk: . examples/ShrinkURL
examples/ShrinkURL/lib/ShrinkURL
examples/ShrinkURL/lib/ShrinkURL/Action
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Fri Oct 19 23:38:02 EDT 2007
Author: sartak
Date: Fri Oct 19 23:37:59 2007
New Revision: 4269
Modified:
jifty/trunk/ (props changed)
jifty/trunk/examples/ShrinkURL/Makefile.PL
jifty/trunk/examples/ShrinkURL/lib/ShrinkURL/Action/CreateShrunkenURL.pm
jifty/trunk/examples/ShrinkURL/lib/ShrinkURL/Dispatcher.pm
jifty/trunk/examples/ShrinkURL/lib/ShrinkURL/Model/ShrunkenURL.pm
jifty/trunk/examples/ShrinkURL/lib/ShrinkURL/View.pm
Log:
r43909 at onn: sartak | 2007-10-19 23:37:52 -0400
More comments
Modified: jifty/trunk/examples/ShrinkURL/Makefile.PL
==============================================================================
--- jifty/trunk/examples/ShrinkURL/Makefile.PL (original)
+++ jifty/trunk/examples/ShrinkURL/Makefile.PL Fri Oct 19 23:37:59 2007
@@ -3,5 +3,6 @@
name 'ShrinkURL';
version '0.01';
requires 'Jifty' => '0.70824';
+requires 'Number::RecordLocator';
WriteAll;
Modified: jifty/trunk/examples/ShrinkURL/lib/ShrinkURL/Action/CreateShrunkenURL.pm
==============================================================================
--- jifty/trunk/examples/ShrinkURL/lib/ShrinkURL/Action/CreateShrunkenURL.pm (original)
+++ jifty/trunk/examples/ShrinkURL/lib/ShrinkURL/Action/CreateShrunkenURL.pm Fri Oct 19 23:37:59 2007
@@ -15,15 +15,25 @@
$shrunkenurl->load_by_cols(url => $url);
if ($shrunkenurl->id) {
+
+ # for the benefit of report_success
$self->record($shrunkenurl);
+
+ # for the benefit of the template that displays new shrunken URLs
+ # this is called in a superclass which we bypass
$self->result->content(id => $shrunkenurl->id);
+
+ # this too is called in a superclass
$self->report_success;
+
+ # Create actions return object's ID
return $shrunkenurl->id;
}
return $self->SUPER::take_action(@_);
}
+# display a nice little message for the user
sub report_success {
my $self = shift;
$self->result->message(_("URL shrunked to %1", $self->record->shrunken));
Modified: jifty/trunk/examples/ShrinkURL/lib/ShrinkURL/Dispatcher.pm
==============================================================================
--- jifty/trunk/examples/ShrinkURL/lib/ShrinkURL/Dispatcher.pm (original)
+++ jifty/trunk/examples/ShrinkURL/lib/ShrinkURL/Dispatcher.pm Fri Oct 19 23:37:59 2007
@@ -7,7 +7,7 @@
# visiting / will let users create new shrunken URLs
on '/' => show 'shrink';
-# any other URL is potentially a shrunken URL
+# any other URL (that has no path separator) is potentially a shrunken URL
on '*' => run {
my $url = $1;
Modified: jifty/trunk/examples/ShrinkURL/lib/ShrinkURL/Model/ShrunkenURL.pm
==============================================================================
--- jifty/trunk/examples/ShrinkURL/lib/ShrinkURL/Model/ShrunkenURL.pm (original)
+++ jifty/trunk/examples/ShrinkURL/lib/ShrinkURL/Model/ShrunkenURL.pm Fri Oct 19 23:37:59 2007
@@ -9,8 +9,7 @@
use Jifty::Record schema {
column url =>
is distinct,
- is varchar(1000),
- is indexed;
+ is varchar(1000);
};
# shrunken URL is just an encoding of ID
Modified: jifty/trunk/examples/ShrinkURL/lib/ShrinkURL/View.pm
==============================================================================
--- jifty/trunk/examples/ShrinkURL/lib/ShrinkURL/View.pm (original)
+++ jifty/trunk/examples/ShrinkURL/lib/ShrinkURL/View.pm Fri Oct 19 23:37:59 2007
@@ -5,10 +5,14 @@
use Jifty::View::Declare -base;
template 'shrink' => page {
+
+ # render the "shrink a URL" widget, which we can put on any page of the app
render_region(
name => 'new_shrink',
path => '/misc/new_shrink',
);
+
+ # render an empty region that we push results onto
render_region(
name => 'new_shrinks',
);
@@ -19,16 +23,18 @@
form {
Jifty->web->form->register_action($action);
render_action($action => ['url']);
+
form_submit(
submit => $action,
label => _('Shrink it!'),
+
onclick => [
{ submit => $action },
{
+ # prepend this result onto the empty region above
region => 'new_shrinks',
prepend => '/misc/shrunk_region',
args => {
- foo => "bar",
id => { result_of => $action, name => 'id' },
},
},
@@ -41,6 +47,7 @@
my $id = get 'id';
my $shrunken = ShrinkURL::Model::ShrunkenURL->new;
$shrunken->load($id);
+
if ($shrunken->id) {
div {
strong { a { attr { href => $shrunken->shrunken } $shrunken->shrunken } };
More information about the Jifty-commit
mailing list