From ad69fc565fe01e18bca7d3ad975156d6a2c8a604 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Tue, 15 Mar 2011 18:00:30 +0100 Subject: Only place lightbox html links when lightbox is enabled --- Changelog | 5 +++++ lib/App/Dthumb.pm | 6 ++++++ lib/App/Dthumb/Data.pm.PL | 5 ++++- share/html_lightbox.dthumb | 2 ++ share/html_start.dthumb | 3 +-- t/21-app-dthumb.files.t | 33 ++++++++++++++++++++++++++++++++- t/cmp/index.lightbox | 1 + t/cmp/index.names | 5 +++-- t/cmp/index.no-lightbox | 25 +++++++++++++++++++++++++ t/cmp/index.no-names | 5 +++-- 10 files changed, 82 insertions(+), 8 deletions(-) create mode 100644 share/html_lightbox.dthumb create mode 120000 t/cmp/index.lightbox create mode 100644 t/cmp/index.no-lightbox diff --git a/Changelog b/Changelog index daf2295..805a4d2 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,8 @@ +git HEAD + + * Do not put lightbox links into HTML when lightbox is disabled + ( -> no more 404s for dthumb --no-lightbox) + dthumb 0.2 - Fri Mar 04 2011 * Add progressbar, introduces new dependency Time::Progress diff --git a/lib/App/Dthumb.pm b/lib/App/Dthumb.pm index 8d71383..f7b6d86 100755 --- a/lib/App/Dthumb.pm +++ b/lib/App/Dthumb.pm @@ -146,6 +146,12 @@ sub new { height => $conf{size} * $conf{spacing} . 'px', ); + if ($conf{lightbox}) { + $ref->{data}->set_vars( + lightbox => $ref->{data}->get('html_lightbox.dthumb'), + ); + } + $ref->{html} = $ref->{data}->get('html_start.dthumb'); return bless($ref, $obj); diff --git a/lib/App/Dthumb/Data.pm.PL b/lib/App/Dthumb/Data.pm.PL index eaf914e..a0fb4f5 100644 --- a/lib/App/Dthumb/Data.pm.PL +++ b/lib/App/Dthumb/Data.pm.PL @@ -103,7 +103,10 @@ B function, dthumb will replace occurences of "" or "/* $key sub set_vars { my ($self, %vars) = @_; - $self->{replace} = \%vars; + + while (my ($key, $value) = each(%vars)) { + $self->{replace}->{$key} = $value; + } } diff --git a/share/html_lightbox.dthumb b/share/html_lightbox.dthumb new file mode 100644 index 0000000..253deda --- /dev/null +++ b/share/html_lightbox.dthumb @@ -0,0 +1,2 @@ + + diff --git a/share/html_start.dthumb b/share/html_start.dthumb index 2ffbf55..e273b76 100644 --- a/share/html_start.dthumb +++ b/share/html_start.dthumb @@ -5,7 +5,6 @@ <!-- $title --> - - +
diff --git a/t/21-app-dthumb.files.t b/t/21-app-dthumb.files.t index da2cbbe..83879e9 100755 --- a/t/21-app-dthumb.files.t +++ b/t/21-app-dthumb.files.t @@ -9,7 +9,7 @@ use Test::More; eval "use File::Slurp"; plan skip_all => 'File::Slurp required' if $@; -plan tests => 12; +plan tests => 14; use_ok('App::Dthumb'); @@ -50,6 +50,37 @@ unlink('t/out/index'); +$conf{names} = 1; +$conf{lightbox} = 1; +$dthumb = App::Dthumb->new(%conf); + +for my $file (qw(one.png two.png)) { + $dthumb->create_thumbnail_html($file); +} +$dthumb->write_out_html(); + +is(read_file('t/out/index'), read_file('t/cmp/index.lightbox'), + 'create_Thumbnail_html / write_out_html with lightbox = 1'); + +unlink('t/out/index'); + + + +$conf{lightbox} = 0; +$dthumb = App::Dthumb->new(%conf); + +for my $file (qw(one.png two.png)) { + $dthumb->create_thumbnail_html($file); +} +$dthumb->write_out_html(); + +is(read_file('t/out/index'), read_file('t/cmp/index.no-lightbox'), + 'create_Thumbnail_html / write_out_html with lightbox = 0'); + +unlink('t/out/index'); + + + $dthumb = App::Dthumb->new(dir_images => 't/out'); $dthumb->create_files(); diff --git a/t/cmp/index.lightbox b/t/cmp/index.lightbox new file mode 120000 index 0000000..122ada1 --- /dev/null +++ b/t/cmp/index.lightbox @@ -0,0 +1 @@ +index.names \ No newline at end of file diff --git a/t/cmp/index.names b/t/cmp/index.names index c682ae1..72e0e94 100644 --- a/t/cmp/index.names +++ b/t/cmp/index.names @@ -5,8 +5,9 @@ dthumb - - + + +
diff --git a/t/cmp/index.no-lightbox b/t/cmp/index.no-lightbox new file mode 100644 index 0000000..93869ca --- /dev/null +++ b/t/cmp/index.no-lightbox @@ -0,0 +1,25 @@ + + + + dthumb + + + + +
+
+ + one.png +
+ one.png +
+
+ + two.png +
+ two.png +
+
+ + diff --git a/t/cmp/index.no-names b/t/cmp/index.no-names index 5022b19..cdc6311 100644 --- a/t/cmp/index.no-names +++ b/t/cmp/index.no-names @@ -5,8 +5,9 @@ dthumb - - + + +
-- cgit v1.2.3