File: image.t

package info (click to toggle)
libtemplate-perl 2.24-1.2
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 8,676 kB
  • ctags: 1,427
  • sloc: perl: 14,535; makefile: 15; sh: 5
file content (102 lines) | stat: -rw-r--r-- 2,274 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#============================================================= -*-perl-*-
#
# t/image.t
#
# Tests the Image plugin.
#
# Written by Andy Wardley <abw@wardley.org>
#
# Copyright (C) 2002 Andy Wardley. All Rights Reserved.
#
# This is free software; you can redistribute it and/or modify it
# under the same terms as Perl itself.
#
# $Id$
#
#========================================================================

use strict;
use lib qw( ./lib ../lib );
use Template::Test;
use Cwd;
use File::Spec;
$^W = 1;

eval "use Image::Info";
if ($@) {
    eval "use Image::Size";
    skip_all('Neither Image::Info nor Image::Size installed') if $@;
}

my $dir  = -d 't' ? 'images' : File::Spec->catfile(File::Spec->updir(), 'images');
my $vars = {
    dir  => $dir,
    file => {
        logo  => File::Spec->catfile($dir, 'ttdotorg.gif'),
        power => File::Spec->catfile($dir, 'tt2power.gif'),
        lname => 'ttdotorg.gif',
    },
};


test_expect(\*DATA, undef, $vars);

__DATA__
-- test --
[% USE Image(file.logo) -%]
file: [% Image.file %]
size: [% Image.size.join(', ') %]
width: [% Image.width %]
height: [% Image.height %]
-- expect --
-- process --
file: [% file.logo %]
size: 110, 60
width: 110
height: 60

-- test --
[% USE image( name = file.power) -%]
name: [% image.name %]
file: [% image.file %]
width: [% image.width %]
height: [% image.height %]
size: [% image.size.join(', ') %]
-- expect --
-- process --
name: [% file.power %]
file: [% file.power %]
width: 78
height: 47
size: 78, 47

-- test --
[% USE image file.logo -%]
attr: [% image.attr %]
-- expect --
attr: width="110" height="60"

-- test --
[% USE image file.logo -%]
tag: [% image.tag %]
tag: [% image.tag(class="myimage", alt="image") %]
-- expect --
-- process --
tag: <img src="[% file.logo %]" width="110" height="60" alt="" />
tag: <img src="[% file.logo %]" width="110" height="60" alt="image" class="myimage" />


# test "root"
-- test --
[% USE image( root=dir name=file.lname ) -%]
[% image.tag %]
-- expect --
-- process --
<img src="[% file.lname %]" width="110" height="60" alt="" />

# test separate file and name
-- test --
[% USE image( file= file.logo  name = "other.jpg" alt="myfile") -%]
[% image.tag %]
-- expect --
<img src="other.jpg" width="110" height="60" alt="myfile" />