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 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
|
Here's an idea with [[patch]] for extending inline in two directions:
1. Permit the content-fetching function to return undef to skip a page. The limiting of @list to a set size is performed after that filtering.
2. Permit other directive plugins to pass a function to generate content via an inliner_ parameter. The current patch doesn't try to remove that key from the parameters, so hilarity might ensue if someone is too clever. I suppose I should fix that... My *intent* is that other, custom directives can add inliner_.
The diff looks large because the first requires switching some loops.
I'm using this along with a custom BibTeX formatter (one item per file) to generate larger pages and tiny listings. I still need to hammer the templates for that, but I think that's possible without further patches.
(Setting up a git branch for a single plugin is a pain, but I can if necessary. I also could separate this into some sequence rather than all at once, but I won't have time for a week or two.)
-- [[JasonRiedy]]
<pre><code>
--- /home/ejr/src/git.ikiwiki.info/IkiWiki/Plugin/inline.pm 2011-03-05 14:18:30.261293808 -0500
+++ inline.pm 2011-03-06 21:44:18.887903638 -0500
@@ -185,6 +185,7 @@
}
my @list;
+ my $num = 0;
if (exists $params{pagenames}) {
foreach my $p (qw(sort pages)) {
@@ -213,23 +214,121 @@
if ($params{feedshow} && $num < $params{feedshow} && $num > 0) {
$num=$params{feedshow};
}
- if ($params{skip} && $num) {
- $num+=$params{skip};
- }
@list = pagespec_match_list($params{page}, $params{pages},
deptype => deptype($quick ? "presence" : "content"),
filter => sub { $_[0] eq $params{page} },
sort => exists $params{sort} ? $params{sort} : "age",
reverse => yesno($params{reverse}),
- ($num ? (num => $num) : ()),
);
}
if (exists $params{skip}) {
@list=@list[$params{skip} .. $#list];
}
+
+ if ($params{show} && $params{show} > $num) {
+ $num = $params{show}
+ }
+
+ my $ret="";
+ my @displist;
+ if ($feedonly) {
+ @displist = @list;
+ } else {
+ my $template;
+ if (! $raw) {
+ # cannot use wiki pages as templates; template not sanitized due to
+ # format hook hack
+ eval {
+ $template=template_depends($params{template}.".tmpl", $params{page},
+ blind_cache => 1);
+ };
+ if ($@) {
+ error sprintf(gettext("failed to process template %s"), $params{template}.".tmpl").": $@";
+ }
+ }
+ my $needcontent=$raw || (!($archive && $quick) && $template->query(name => 'content'));
+
+ foreach my $page (@list) {
+ last if ($num && scalar @displist >= $num);
+ my $file = $pagesources{$page};
+ my $type = pagetype($file);
+ if (! $raw) {
+ # Get the content before populating the
+ # template, since getting the content uses
+ # the same template if inlines are nested.
+ if ($needcontent) {
+ my $content;
+ if (exists $params{inliner_} && defined $params{inliner_}) {
+ $content = &{$params{inliner_}}($page, $template, %params);
+ } else {
+ $content=get_inline_content($page, $params{destpage});
+ }
+ next if !defined $content;
+ $template->param(content => $content);
+ push @displist, $page;
+ }
+ $template->param(pageurl => urlto($page, $params{destpage}));
+ $template->param(inlinepage => $page);
+ $template->param(title => pagetitle(basename($page)));
+ $template->param(ctime => displaytime($pagectime{$page}, $params{timeformat}, 1));
+ $template->param(mtime => displaytime($pagemtime{$page}, $params{timeformat}));
+ $template->param(first => 1) if $page eq $list[0];
+ $template->param(last => 1) if ($num && scalar @displist == $num);
+ $template->param(html5 => $config{html5});
+ if ($actions) {
+ my $file = $pagesources{$page};
+ my $type = pagetype($file);
+ if ($config{discussion}) {
+ if ($page !~ /.*\/\Q$config{discussionpage}\E$/i &&
+ (length $config{cgiurl} ||
+ exists $pagesources{$page."/".lc($config{discussionpage})})) {
+ $template->param(have_actions => 1);
+ $template->param(discussionlink =>
+ htmllink($page,
+ $params{destpage},
+ $config{discussionpage},
+ noimageinline => 1,
+ forcesubpage => 1));
+ }
+ }
+ if (length $config{cgiurl} &&
+ defined $type &&
+ IkiWiki->can("cgi_editpage")) {
+ $template->param(have_actions => 1);
+ $template->param(editurl => cgiurl(do => "edit", page => $page));
+
+ }
+ }
+
+ run_hooks(pagetemplate => sub {
+ shift->(page => $page, destpage => $params{destpage},
+ template => $template,);
+ });
+
+ $ret.=$template->output;
+ $template->clear_params;
+ }
+ else {
+ if (defined $type) {
+ $ret.="\n".
+ linkify($page, $params{destpage},
+ preprocess($page, $params{destpage},
+ filter($page, $params{destpage},
+ readfile(srcfile($file)))));
+ }
+ else {
+ $ret.="\n".
+ readfile(srcfile($file));
+ }
+ push @displist, $page;
+ }
+ }
+ }
+ @list = @displist;
+
my @feedlist;
if ($feeds) {
if (exists $params{feedshow} &&
@@ -241,10 +340,6 @@
}
}
- if ($params{show} && @list > $params{show}) {
- @list=@list[0..$params{show} - 1];
- }
-
if ($feeds && exists $params{feedpages}) {
@feedlist = pagespec_match_list(
$params{page}, "($params{pages}) and ($params{feedpages})",
@@ -302,8 +397,6 @@
}
}
- my $ret="";
-
if (length $config{cgiurl} && ! $params{preview} && (exists $params{rootpage} ||
(exists $params{postform} && yesno($params{postform}))) &&
IkiWiki->can("cgi_editpage")) {
@@ -355,91 +448,7 @@
}
$ret.=$linktemplate->output;
}
-
- if (! $feedonly) {
- my $template;
- if (! $raw) {
- # cannot use wiki pages as templates; template not sanitized due to
- # format hook hack
- eval {
- $template=template_depends($params{template}.".tmpl", $params{page},
- blind_cache => 1);
- };
- if ($@) {
- error sprintf(gettext("failed to process template %s"), $params{template}.".tmpl").": $@";
- }
- }
- my $needcontent=$raw || (!($archive && $quick) && $template->query(name => 'content'));
-
- foreach my $page (@list) {
- my $file = $pagesources{$page};
- my $type = pagetype($file);
- if (! $raw) {
- if ($needcontent) {
- # Get the content before populating the
- # template, since getting the content uses
- # the same template if inlines are nested.
- my $content=get_inline_content($page, $params{destpage});
- $template->param(content => $content);
- }
- $template->param(pageurl => urlto($page, $params{destpage}));
- $template->param(inlinepage => $page);
- $template->param(title => pagetitle(basename($page)));
- $template->param(ctime => displaytime($pagectime{$page}, $params{timeformat}, 1));
- $template->param(mtime => displaytime($pagemtime{$page}, $params{timeformat}));
- $template->param(first => 1) if $page eq $list[0];
- $template->param(last => 1) if $page eq $list[$#list];
- $template->param(html5 => $config{html5});
-
- if ($actions) {
- my $file = $pagesources{$page};
- my $type = pagetype($file);
- if ($config{discussion}) {
- if ($page !~ /.*\/\Q$config{discussionpage}\E$/i &&
- (length $config{cgiurl} ||
- exists $pagesources{$page."/".lc($config{discussionpage})})) {
- $template->param(have_actions => 1);
- $template->param(discussionlink =>
- htmllink($page,
- $params{destpage},
- $config{discussionpage},
- noimageinline => 1,
- forcesubpage => 1));
- }
- }
- if (length $config{cgiurl} &&
- defined $type &&
- IkiWiki->can("cgi_editpage")) {
- $template->param(have_actions => 1);
- $template->param(editurl => cgiurl(do => "edit", page => $page));
- }
- }
-
- run_hooks(pagetemplate => sub {
- shift->(page => $page, destpage => $params{destpage},
- template => $template,);
- });
-
- $ret.=$template->output;
- $template->clear_params;
- }
- else {
- if (defined $type) {
- $ret.="\n".
- linkify($page, $params{destpage},
- preprocess($page, $params{destpage},
- filter($page, $params{destpage},
- readfile(srcfile($file)))));
- }
- else {
- $ret.="\n".
- readfile(srcfile($file));
- }
- }
- }
- }
-
if ($feeds && ($emptyfeeds || @feedlist)) {
if ($rss) {
my $rssp=$feedbase."rss".$feednum;
</code></pre>
|