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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
#!/usr/bin/perl
use warnings;
use strict;
BEGIN {
foreach my $module (qw(Image::Magick)) {
eval qq{use $module};
if ($@) {
eval qq{
use Test::More skip_all => "$module not available"
}
}
}
}
use Test::More 'no_plan';
BEGIN { use_ok("IkiWiki"); }
my $blob;
ok(! system("rm -rf t/tmp"));
ok(mkdir("t/tmp"));
ok(mkdir("t/tmp/in"));
ok(mkdir("t/tmp/in/myalbum"));
my $image = Image::Magick->new;
$image->Set(size => '640x480');
$image->Read('canvas:red');
$image->Draw(fill => 'yellow', primitive => 'rectangle',
points => '0,0 100,100');
$image->Write('t/tmp/in/myalbum/r.jpg');
$image = Image::Magick->new;
$image->Set(size => '480x640');
$image->Read('canvas:green');
$image->Draw(fill => 'yellow', primitive => 'rectangle',
points => '0,0 100,100');
$image->Write('t/tmp/in/myalbum/g.png');
$image = Image::Magick->new;
$image->Set(size => '640x640');
$image->Read('canvas:blue');
$image->Draw(fill => 'yellow', primitive => 'rectangle',
points => '0,0 100,100');
$image->Write('t/tmp/in/myalbum/b.gif');
writefile("myalbum.mdwn", "t/tmp/in", <<END);
## Section: green
[[!albumsection filter="*/g"]]
## Assorted
[[!album sort="title"]]
END
writefile("myalbum/page.mdwn", "t/tmp/in", "not an image");
writefile("style.css", "t/tmp/in", readfile("doc/style.css"));
ok(! system("make -s ikiwiki.out"));
my $command = "perl -Iblib/lib ./ikiwiki.out -set usedirs=0 -plugin album -url=http://example.com -cgiurl=http://example.com/ikiwiki.cgi -underlaydir=underlays/basewiki -set underlaydirbase=underlays -templatedir=templates t/tmp/in t/tmp/out -verbose";
ok(! system($command));
# make sure subsequent changes will have a newer mtime
sleep(1);
# myalbum is an album and a trail
# the album's members are inlined into it
# the albumsection displays all matching pages (only myalbum/g)
# the album displays the rest
$blob = readfile("t/tmp/out/myalbum.html");
like($blob, qr{
^<h2[^>]*>Section:\s+green</h2>$
.*?
<a\s+href="\./myalbum/g\.html">
.*?
<img\s+src="\./myalbum/g/96x96-g\.png"
.*?
^<h2[^>]*>Assorted</h2>$
.*?
<a\s+href="\./myalbum/b\.html">
.*?
<img\s+src="\./myalbum/b/96x96-b\.gif"
.*?
<a\s+href="\./myalbum/r\.html">
.*?
<img\s+src="\./myalbum/r/96x96-r\.jpg"
}msx);
unlike($blob, qr{myalbum/page\.html});
# myalbum/b is part of the trail defined by myalbum
$blob = readfile("t/tmp/out/myalbum/b.html");
like($blob, qr{
<link\s+rel="prev"\s+href="\./g\.html"
.*?
<link\s+rel="up"\s+href="\.\./myalbum\.html"
.*?
<link\s+rel="next"\s+href="\./r\.html"
}msx);
# myalbum/b shows the full-size image
like($blob, qr{
<div\s+id="album-img">
.*?
<img\s+src="\./b\.gif"
}msx);
# change some stuff and refresh
$blob = readfile("t/tmp/in/.ikiwiki/transient/myalbum/b.mdwn");
like($blob, qr{\[\[!albumimage\s.*\]\]}msx);
$blob =~ s/^(\s*)title="+$/${1}title="a blue box"/msx;
writefile("myalbum/b.mdwn", "t/tmp/in", "hello, world!\n\n$blob");
# make sure subsequent changes take effect
ok(! system("$command -refresh"));
# myalbum is an album and a trail
# the album's members are inlined into it
# the albumsection displays all matching pages (only myalbum/g)
# the album displays the rest
$blob = readfile("t/tmp/out/myalbum.html");
like($blob, qr{
^<h2[^>]*>Section:\s+green</h2>$
.*?
<a\s+href="\./myalbum/g\.html">
.*?
<img\s+src="\./myalbum/g/96x96-g\.png"
.*?
^<h2[^>]*>Assorted</h2>$
.*?
<a\s+href="\./myalbum/b\.html">
.*?
<img\s+src="\./myalbum/b/96x96-b\.gif"
.*?
<a\s+href="\./myalbum/r\.html">
.*?
<img\s+src="\./myalbum/r/96x96-r\.jpg"
}msx);
unlike($blob, qr{myalbum/page\.html});
# myalbum/b is part of the trail defined by myalbum
$blob = readfile("t/tmp/out/myalbum/b.html");
like($blob, qr{
<link\s+rel="prev"\s+href="\./g\.html"
.*?
<link\s+rel="up"\s+href="\.\./myalbum\.html"
.*?
<link\s+rel="next"\s+href="\./r\.html"
}msx);
# myalbum/b shows the full-size image, now with title and additional text
like($blob, qr{<title>a blue box</title>});
like($blob, qr{
<p>hello,\s+world!</p>
.*?
<div\s+id="album-img">
.*?
<img\s+src="\./b\.gif"
}msx);
|