]> sipb.mit.edu Git - ikiwiki.git/commitdiff
localstyle: New plugin, allows overrding the toplevel local.css with one that is...
authorJoey Hess <joey@gnu.kitenet.net>
Mon, 9 Nov 2009 18:32:08 +0000 (13:32 -0500)
committerJoey Hess <joey@gnu.kitenet.net>
Mon, 9 Nov 2009 18:39:05 +0000 (13:39 -0500)
I chose not to have it override style.css, because style.css is not really
intended to be edited; the one from the underlay is intended to be used as
a base that local.css overrides.

I chose to use a plugin rather than changing the default behavior, both
because I didn't want to have to worry about possibly breaking backwards
compatability (though this seems unlikely), and because it seemed cleaner
to not include style template parameters in the main page template code.

I suppose someone might want a way to not override the toplevel
local.css, but instead include it as well as foo/local.css. Probably the
best way to do that would be to have foo/local.css @import ../local.css
(modulo browser compatability issues). Alternatively, edit page.tmpl
to always include the toplevel local.css, or swap out this plugin for
another one.

IkiWiki/Plugin/localstyle.pm [new file with mode: 0644]
debian/changelog
doc/css.mdwn
doc/plugins/localstyle.mdwn [new file with mode: 0644]
templates/page.tmpl

diff --git a/IkiWiki/Plugin/localstyle.pm b/IkiWiki/Plugin/localstyle.pm
new file mode 100644 (file)
index 0000000..111f4dc
--- /dev/null
@@ -0,0 +1,35 @@
+#!/usr/bin/perl
+
+package IkiWiki::Plugin::localstyle;
+
+use warnings;
+use strict;
+use IkiWiki 3.00;
+
+sub import {
+       hook(type => "getsetup", id => "localstyle", call => \&getsetup);
+       hook(type => "pagetemplate", id => "localstyle", call => \&pagetemplate);
+}
+
+sub getsetup () {
+       return
+               plugin => {
+                       safe => 1,
+                       rebuild => 1,
+               },
+}
+
+sub pagetemplate (@) {
+       my %params=@_;
+       
+       my $template=$params{template};
+       
+       if ($template->query(name => "local_css")) {
+               my $best=bestlink($params{page}, 'local.css');
+               if ($best) {
+                       $template->param(local_css => $best);
+               }
+       }
+}
+
+1
index 6a5ae30abdd526a3c9543e22ba19a17cf40e080a..4ab63f175c28ab7ddf399924829ac8c155fad46d 100644 (file)
@@ -8,6 +8,8 @@ ikiwiki (3.20091032) UNRELEASED; urgency=low
     the template is filled out. This improves the search plugin's indexing,
     since it will not include navigational elements from the page template
     or sidebar.
+  * localstyle: New plugin, allows overrding the toplevel local.css
+    with one that is closer to a page.
 
  -- Joey Hess <joeyh@debian.org>  Fri, 06 Nov 2009 12:04:29 -0500
 
index 20790b3d191ab0ebdd95a66bb918f3db66e7b920..29a3355965d5cc9762e5752dcbb104351f5578ba 100644 (file)
@@ -16,3 +16,6 @@ files.
 
 The [[plugins/meta]] plugin can be used to add additional style sheets to a
 page.
+
+The [[plugins/localstyle]] plugin can be used to override the toplevel
+[[local.css]] for a whole section of the wiki.
diff --git a/doc/plugins/localstyle.mdwn b/doc/plugins/localstyle.mdwn
new file mode 100644 (file)
index 0000000..70a909d
--- /dev/null
@@ -0,0 +1,12 @@
+[[!template id=plugin name=localstyle author="[[Joey]]"]]
+[[!tag type/chrome]]
+
+This plugin allows styling different sections of a wiki using different
+versions of the local.css [[CSS]] file. Normally this file is read from the
+top level of the wiki, but with this plugin enabled, standard
+[[ikiwiki/subpage/LinkingRules]] are used to find the closest local.css
+file to each page.
+
+So, for example, to use different styling for page `foo`, as well as all
+of its [[SubPages|ikiwiki/subpage]], such as `foo/bar`, create a
+`foo/local.css`.
index e71ba316db79a3492db66ddb2299d9f905c807c8..0e73463ec0260c0caab856f1293f0db28c9275a0 100644 (file)
@@ -7,8 +7,13 @@
 <TMPL_IF NAME="FAVICON">
 <link rel="icon" href="<TMPL_VAR BASEURL><TMPL_VAR FAVICON>" type="image/x-icon" />
 </TMPL_IF>
+<TMPL_IF NAME="STYLE_CSS">
 <link rel="stylesheet" href="<TMPL_VAR BASEURL>style.css" type="text/css" />
+<TMPL_IF NAME="LOCAL_CSS">
+<link rel="stylesheet" href="<TMPL_VAR BASEURL><TMPL_VAR LOCAL_CSS>" type="text/css" />
+<TMPL_ELSE>
 <link rel="stylesheet" href="<TMPL_VAR BASEURL>local.css" type="text/css" />
+</TMPL_IF>
 <TMPL_IF NAME="EDITURL">
 <link rel="alternate" type="application/x-wiki" title="Edit this page" href="<TMPL_VAR EDITURL>" />
 </TMPL_IF>