From 7e36a48bf664db42bf5b3784fe3879604ee3bf4b Mon Sep 17 00:00:00 2001 From: Luc Didry Date: Fri, 14 Feb 2014 15:08:47 +0100 Subject: [PATCH] Add template for displaying a twitter-card compliant page --- lib/Lutim.pm | 17 ++++++++++++++++- lib/Lutim/I18N/en.pm | 9 +++++---- lib/Lutim/I18N/fr.pm | 1 + templates/index.html.ep | 15 +++++++++------ templates/twitter.html.ep | 17 +++++++++++++++++ 5 files changed, 48 insertions(+), 11 deletions(-) create mode 100644 templates/twitter.html.ep diff --git a/lib/Lutim.pm b/lib/Lutim.pm index 59ba502..3a95fb0 100644 --- a/lib/Lutim.pm +++ b/lib/Lutim.pm @@ -202,6 +202,7 @@ sub startup { $r->get('/:short' => sub { my $c = shift; my $short = $c->param('short'); + my $touit = $c->param('t'); my $dl = (defined($c->param('dl'))) ? 'attachment' : 'inline'; my @images = LutimModel::Lutim->select('WHERE short = ? AND ENABLED = 1 AND path IS NOT NULL', $short); @@ -222,7 +223,21 @@ sub startup { ); return $c->redirect_to('/'); } - if($c->render_file($images[0]->filename, $images[0]->path, $images[0]->mediatype, $dl) != 500) { + + my $test; + if (defined($touit)) { + $test = 1; + $c->render( + template => 'twitter', + layout => undef, + short => $images[0]->short, + filename => $images[0]->filename + ); + } else { + $test = $c->render_file($images[0]->filename, $images[0]->path, $images[0]->mediatype, $dl); + } + + if ($test != 500) { # Update counter and check provisionning $c->on(finish => sub { # Log access diff --git a/lib/Lutim/I18N/en.pm b/lib/Lutim/I18N/en.pm index 409861c..728136c 100644 --- a/lib/Lutim/I18N/en.pm +++ b/lib/Lutim/I18N/en.pm @@ -24,13 +24,14 @@ my $inf_body = < 'License:', - 'fork-me' => 'Fork me on Github !', - 'share-twitter' => 'Share on Twitter', - 'informations' => 'Informations', + 'license' => 'License:', + 'fork-me' => 'Fork me on Github !', + 'share-twitter' => 'Share on Twitter', + 'informations' => 'Informations', 'informations-body' => $inf_body, 'view-link' => 'View link:', 'download-link' => 'Download link:', + 'twitter-link' => 'Link for put in a tweet:', 'some-bad' => 'Something bad happened', 'delete-first' => 'Delete at first view?', 'delete-day' => 'Delete after 24 hours?', diff --git a/lib/Lutim/I18N/fr.pm b/lib/Lutim/I18N/fr.pm index e090bed..aede187 100644 --- a/lib/Lutim/I18N/fr.pm +++ b/lib/Lutim/I18N/fr.pm @@ -31,6 +31,7 @@ our %Lexicon = ( 'informations-body' => $inf_body, 'view-link' => 'Lien d\'affichage :', 'download-link' => 'Lien de téléchargement :', + 'twitter-link' => 'Lien pour mettre dans un tweet :', 'some-bad' => 'Un problème est survenu', 'delete-first' => 'Supprimer au premier accès ?', 'delete-day' => 'Supprimer après 24 heures ?', diff --git a/templates/index.html.ep b/templates/index.html.ep index 0295449..c8ed8f5 100644 --- a/templates/index.html.ep +++ b/templates/index.html.ep @@ -7,6 +7,7 @@ % } @@ -71,8 +72,8 @@ %= javascript begin function link(url, dl) { - if (dl) { - url = url+'?dl'; + if (dl !== '') { + url = url+'?'+dl; } return '<%== url_for('index')->to_abs() %>'+url+''; } @@ -80,10 +81,12 @@ if(success) { return '
' +msg.filename - +'
  • view link ' - +link(msg.short, false) - +'
  • download link ' - +link(msg.short, true) + +'
    • <%=l 'view-link'%>' + +link(msg.short, '') + +'
    • <%=l 'download-link' %>' + +link(msg.short, 'dl') + +'
    • <%=l 'twitter-link' %>' + +link(msg.short, 't') +'
'; } else { return '
<%=l 'some-bad' %>
' diff --git a/templates/twitter.html.ep b/templates/twitter.html.ep new file mode 100644 index 0000000..1095313 --- /dev/null +++ b/templates/twitter.html.ep @@ -0,0 +1,17 @@ +% # vim:set sw=4 ts=4 sts=4 ft=html.epl expandtab: + + + + LUTIm + + + + + + + + <%= $filename %> + + + +