From bd0120cdb2e371e620999d749cba741287da3094 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Mon, 28 Feb 2011 20:02:49 +0100 Subject: Make HTML document title configurable via -t/--title option --- Changelog | 1 + bin/dthumb | 9 +++++++-- lib/App/Dthumb.pm | 33 +++++++++++++++++---------------- lib/App/Dthumb/Data.pm.PL | 14 ++++++++++++++ share/html_start | 3 ++- share/main.css | 11 +++++++++++ 6 files changed, 52 insertions(+), 19 deletions(-) create mode 100644 share/main.css diff --git a/Changelog b/Changelog index a80e9c0..ea5e415 100644 --- a/Changelog +++ b/Changelog @@ -3,6 +3,7 @@ git HEAD * Add progressbar, introduces new dependency Time::Progress * Switch from lightbox to shadowbox * Show filename in lightbox + * The HTML title is now configurable, it defaults to the current directory dthumb 0.1 - Sun Feb 27 2011 diff --git a/bin/dthumb b/bin/dthumb index dcf82cf..fa3f975 100755 --- a/bin/dthumb +++ b/bin/dthumb @@ -20,11 +20,12 @@ GetOptions( $opt, qw{ help|h - size|d=i - spacing|s=f no-lightbox|L no-names|n quality|q=i + size|d=i + spacing|s=f + title|t=s version|v }, ) or die("Please see perldoc -F $0\n"); @@ -114,6 +115,10 @@ no border at all, etc. Defaults to 1.1 +=item B<-t>, B<--title> I + +Set HTML document title. Defaults to the basename of the current directory + =item B<-q>, B<--quality> I Set thumbnail quality. diff --git a/lib/App/Dthumb.pm b/lib/App/Dthumb.pm index 952eaaa..5cb8fa6 100755 --- a/lib/App/Dthumb.pm +++ b/lib/App/Dthumb.pm @@ -114,9 +114,10 @@ sub new { my ($obj, $conf) = @_; my $ref = {}; - $conf->{size} //= 200; - $conf->{spacing} //= 1.1; - $conf->{quality} //= 75; + $conf->{size} //= 200; + $conf->{spacing} //= 1.1; + $conf->{quality} //= 75; + $conf->{title} //= (split(qr{/}, cwd()))[-1]; $conf->{lightbox} = !$conf->{'no-lightbox'}; $conf->{names} = !$conf->{'no-names'}; @@ -124,14 +125,18 @@ sub new { $ref->{data} = App::Dthumb::Data->new(); - $ref->{html} = $ref->{data}->get('html_start'); - - $ref->{current_file_id} = 0; + $ref->{data}->set_vars( + title => $conf->{title}, + width => $conf->{size} * $conf->{spacing} . 'px', + height => $conf->{size} * $conf->{spacing} . 'px', + ); $ref->{config}->{file_index} = 'index.xhtml'; $ref->{config}->{dir_thumbs} = '.thumbs'; $ref->{config}->{dir_data} = '.dthumb'; + $ref->{html} = $ref->{data}->get('html_start'); + return bless($ref, $obj); } @@ -230,8 +235,8 @@ sub create_files { mkdir($datadir); } - for my $file (qw(close.png loading.gif next.png pause.png play.png - previous.png shadowbox.css shadowbox.js)) { + for my $file (qw(close.png loading.gif main.css next.png pause.png + play.png previous.png shadowbox.css shadowbox.js)) { open(my $fh, '>', "${datadir}/${file}"); print {$fh} $self->{data}->get($file); close($fh); @@ -284,14 +289,8 @@ sub create_thumbnail_html { my $div_width = $self->{config}->{size} * $self->{config}->{spacing}; my $div_height = $div_width + ($self->{config}->{names} ? 10 : 0); - $self->{html} .= sprintf( - "
\n", - 'text-align: center', - 'font-size: 80%', - 'float: left', - $div_width, - $div_height, - ); + $self->{html} .= "
\n"; + $self->{html} .= sprintf( "\t\n" . "\t\t\"%s\"\n", @@ -299,6 +298,7 @@ sub create_thumbnail_html { $self->{config}->{dir_thumbs}, ($file) x 2, ); + if ($self->{config}->{names}) { $self->{html} .= sprintf( "\t
\n" @@ -307,6 +307,7 @@ sub create_thumbnail_html { ($file) x 2, ); } + $self->{html} .= "
\n"; } diff --git a/lib/App/Dthumb/Data.pm.PL b/lib/App/Dthumb/Data.pm.PL index c1f1ed2..a686c6d 100644 --- a/lib/App/Dthumb/Data.pm.PL +++ b/lib/App/Dthumb/Data.pm.PL @@ -54,6 +54,11 @@ sub new { return bless($ref, $obj); } +sub set_vars { + my ($self, %vars) = @_; + $self->{replace} = \%vars; +} + sub get { my ($self, $name) = @_; my $data = $self->section_data($name); @@ -65,6 +70,15 @@ sub get { if ($name =~ qr{ \. (png | gif) $ }ox) { return decode_base64(${$data}); } + + while (my ($key, $value) = each %{$self->{replace}}) { + ${$data} =~ s{ + ( \<\!-- | /\* ) + \s+ \$ $key \s+ + ( --\> | \*/ ) + }{$value}gx; + } + return ${$data}; } diff --git a/share/html_start b/share/html_start index f628c2c..baf8167 100644 --- a/share/html_start +++ b/share/html_start @@ -2,8 +2,9 @@ "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> - dthumb + <!-- $title --> +