diff options
author | joey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071> | 2006-11-22 02:28:42 +0000 |
---|---|---|
committer | joey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071> | 2006-11-22 02:28:42 +0000 |
commit | a405b46c3b6020e1fa3631bfe5fd982f315c977f (patch) | |
tree | e3c073a2ac07f9fb6686d105f542bae1815a145d /IkiWiki | |
parent | 538a7a487b2872a82721322dd1333c2e0381b8c7 (diff) | |
download | ikiwiki-a405b46c3b6020e1fa3631bfe5fd982f315c977f.tar ikiwiki-a405b46c3b6020e1fa3631bfe5fd982f315c977f.tar.gz |
* Add toggle plugin.
* Introduce the nicebundle. This is a kind of plugin, that just enables
many other plugins. It's an easy way to boost ikiwiki from its default,
basic wiki, to a full-featured wiki, without manually picking the right
set of plugins. New plugins will be added to the nicebundle from time to
time.
Diffstat (limited to 'IkiWiki')
-rw-r--r-- | IkiWiki/Plugin/inline.pm | 5 | ||||
-rw-r--r-- | IkiWiki/Plugin/nicebundle.pm | 29 | ||||
-rw-r--r-- | IkiWiki/Plugin/toggle.pm | 94 | ||||
-rw-r--r-- | IkiWiki/UserInfo.pm | 4 |
4 files changed, 132 insertions, 0 deletions
diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm index e65b8ae71..937bd281d 100644 --- a/IkiWiki/Plugin/inline.pm +++ b/IkiWiki/Plugin/inline.pm @@ -352,6 +352,9 @@ sub pingurl (@) { #{{{ setsid() or error("Can't start a new session: $!"); open STDERR, '>&STDOUT' or error("Can’t dup stdout: $!"); + # Don't need to keep a lock on the wiki as a daemon. + IkiWiki::unlockwiki(); + foreach my $page (keys %toping) { my $title=pagetitle(basename($page)); my $url="$config{url}/".htmlpage($page); @@ -375,6 +378,8 @@ sub pingurl (@) { #{{{ } } } + + exit 0; # daemon done } #}}} 1 diff --git a/IkiWiki/Plugin/nicebundle.pm b/IkiWiki/Plugin/nicebundle.pm new file mode 100644 index 000000000..7139a2af8 --- /dev/null +++ b/IkiWiki/Plugin/nicebundle.pm @@ -0,0 +1,29 @@ +#!/usr/bin/perl +package IkiWiki::Plugin::nicebundle; + +use warnings; +use strict; +use IkiWiki; + +my @bundle=qw{ + brokenlinks + img + map + meta + orphans + pagecount + pagestats + shortcut + smiley + tag + template + toc + toggle + otl +}; + +sub import { #{{{ + IkiWiki::loadplugin($_) foreach @bundle; +} # }}} + +1 diff --git a/IkiWiki/Plugin/toggle.pm b/IkiWiki/Plugin/toggle.pm new file mode 100644 index 000000000..7981d3701 --- /dev/null +++ b/IkiWiki/Plugin/toggle.pm @@ -0,0 +1,94 @@ +#!/usr/bin/perl +package IkiWiki::Plugin::toggle; + +use warnings; +use strict; +use IkiWiki; + +# Here's the javascript that makes this possible. A key feature is the use +# of css to hide toggleables, to avoid any flashing on page load. The css +# is only emitted after the javascript tests that it's going to be able to +# show the toggleables. +my $javascript=<<'EOF'; +<script type="text/javascript"> +<!-- +if (document.getElementById && document.getElementsByTagName && document.createTextNode) { + document.write('<style type="text/css">div.toggleable { display: none; }</style>'); + window.onload = inittoggle; +} + +function inittoggle() { + var as = getElementsByClass('toggle'); + for (var i = 0; i < as.length; i++) { + var id = as[i].href.match(/#(\w.+)/)[1]; + document.getElementById(id).style.display="none"; + as[i].onclick = function() { + toggle(this); + return false; + } + } +} + +function toggle(s) { + var id = s.href.match(/#(\w.+)/)[1]; + style = document.getElementById(id).style; + if (style.display == "none") + style.display = "block"; + else + style.display = "none"; +} + +function getElementsByClass(class) { + var ret = new Array(); + var pattern = new RegExp("(^|\\s)"+class+"(\\s|$)"); + var els = document.getElementsByTagName('*'); + for (i = 0, j = 0; i < els.length; i++) { + if ( pattern.test(els[i].className) ) { + ret[j] = els[i]; + j++; + } + } + return ret; +} +//--> +</script> +EOF + +sub import { #{{{ + hook(type => "preprocess", id => "toggle", + call => \&preprocess_toggle); + hook(type => "preprocess", id => "toggleable", + call => \&preprocess_toggleable, scan => 1); + hook(type => "format", id => "toggle", call => \&format); +} # }}} + +sub preprocess_toggle (@) { #{{{ + my %params=(id => "default", text => "more", @_); + + return "<a class=\"toggle\" href=\"#$params{page}.$params{id}\">$params{text}</a>"; +} # }}} + +sub preprocess_toggleable (@) { #{{{ + my %params=(id => "default", text => "", @_); + + # Preprocess the text to expand any preprocessor directives + # embedded inside it. This is why scan is set for this preprocessor + # directive, since it could expand to something with a link in it. + $params{text}=IkiWiki::preprocess($params{page}, $params{destpage}, $params{text}); + + # Should really be a postprocessor directive, oh well. Work around + # markdown's dislike of markdown inside a <div>. + return "<div class=\"toggleable\" id=\"$params{page}.$params{id}\"></div>\n\n$params{text}<div class=\"toggleableend\"></div>"; +} # }}} + +sub format (@) { #{{{ + my %params=@_; + + if ($params{content}=~s!(<div class="toggleable" id="[^"]+">)</div>!$1!g) { + $params{content}=~s/<div class="toggleableend">//g; + $params{content}=~s!^<\/body>!$javascript</body>!m; + } + return $params{content}; +} # }}} + +1 diff --git a/IkiWiki/UserInfo.pm b/IkiWiki/UserInfo.pm index 34f05203a..fd823c963 100644 --- a/IkiWiki/UserInfo.pm +++ b/IkiWiki/UserInfo.pm @@ -150,6 +150,8 @@ sub send_commit_mails ($$$@) { #{{{ setsid() or error("Can't start a new session: $!"); open STDERR, '>&STDOUT' or error("Can’t dup stdout: $!"); + unlockwiki(); # don't need to keep a lock on the wiki + eval q{use Mail::Sendmail}; error($@) if $@; foreach my $email (@email_recipients) { @@ -160,6 +162,8 @@ sub send_commit_mails ($$$@) { #{{{ Message => $template->output, ) or error("Failed to send update notification mail"); } + + exit 0; # daemon process done } } #}}} |