From f8fcd22c76635c0210b4e1ea9dda0c8cab627d62 Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Fri, 20 Jun 2008 17:25:43 +0200 Subject: Add plugins copyright, license and varioki, and graphicsmagick wrapper for Image::Magick. --- perl/IkiWiki/Plugin/copyright.pm | 69 ++++++++++++++ perl/IkiWiki/Plugin/license.pm | 69 ++++++++++++++ perl/IkiWiki/Plugin/varioki.pm | 190 +++++++++++++++++++++++++++++++++++++++ perl/Image/Magick.pm | 69 ++++++++++++++ 4 files changed, 397 insertions(+) create mode 100644 perl/IkiWiki/Plugin/copyright.pm create mode 100644 perl/IkiWiki/Plugin/license.pm create mode 100644 perl/IkiWiki/Plugin/varioki.pm create mode 100644 perl/Image/Magick.pm diff --git a/perl/IkiWiki/Plugin/copyright.pm b/perl/IkiWiki/Plugin/copyright.pm new file mode 100644 index 0000000..0eda81c --- /dev/null +++ b/perl/IkiWiki/Plugin/copyright.pm @@ -0,0 +1,69 @@ +# A plugin for ikiwiki to implement adding a footer with copyright information +# based on a default value taken out of a file. + +# Copyright © 2007 Thomas Schwinge +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2, or (at your option) any later +# version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +# A footer with copyright information will be added to every rendered page if +# (a) such a footer isn't present already (see the `meta' plugin's +# ``copyright'' facility) and (b) a file `copyright.html' is found (using the +# same rules as for the sidebar plugin). +# +# The state which page's copyright text was gathered from which source is not +# tracked, so you'll need a full wiki-rebuild if (b)'s files are changed. +# +# You can use wiki links in `copyright.html'. + +package IkiWiki::Plugin::copyright; + +use warnings; +use strict; +use IkiWiki 2.00; + +sub import +{ + hook (type => "pagetemplate", id => "copyright", call => \&pagetemplate, + # Run last, as to have the `meta' plugin do its work first. + last => 1); +} + +sub pagetemplate (@) +{ + my %params = @_; + my $page = $params{page}; + my $destpage = $params{destpage}; + + my $template = $params{template}; + + if ($template->query (name => "copyright") && + ! defined $template->param ('copyright')) + { + my $content; + my $copyright_page = bestlink ($page, "copyright") || return; + my $copyright_file = $pagesources{$copyright_page} || return; + #my $pagetype = pagetype ($copyright_file); + # Check if ``$pagetype eq 'html'''? + $content = readfile (srcfile ($copyright_file)); + + if (defined $content && length $content) + { + $template->param (copyright => + IkiWiki::linkify ($page, $destpage, $content)); + } + } +} + +1 diff --git a/perl/IkiWiki/Plugin/license.pm b/perl/IkiWiki/Plugin/license.pm new file mode 100644 index 0000000..2375c22 --- /dev/null +++ b/perl/IkiWiki/Plugin/license.pm @@ -0,0 +1,69 @@ +# A plugin for ikiwiki to implement adding a footer with licensing information +# based on a default value taken out of a file. + +# Copyright © 2007 Thomas Schwinge +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2, or (at your option) any later +# version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +# A footer with licensing information will be added to every rendered page if +# (a) such a footer isn't present already (see the `meta' plugin's ``license'' +# facility) and (b) a file `license.html' is found (using the same rules as for +# the sidebar plugin). +# +# The state which page's license text was gathered from which source is not +# tracked, so you'll need a full wiki-rebuild if (b)'s files are changed. +# +# You can use wiki links in `license.html'. + +package IkiWiki::Plugin::license; + +use warnings; +use strict; +use IkiWiki 2.00; + +sub import +{ + hook (type => "pagetemplate", id => "license", call => \&pagetemplate, + # Run last, as to have the `meta' plugin do its work first. + last => 1); +} + +sub pagetemplate (@) +{ + my %params = @_; + my $page = $params{page}; + my $destpage = $params{destpage}; + + my $template = $params{template}; + + if ($template->query (name => "license") && + ! defined $template->param ('license')) + { + my $content; + my $license_page = bestlink ($page, "license") || return; + my $license_file = $pagesources{$license_page} || return; + #my $pagetype = pagetype ($license_file); + # Check if ``$pagetype eq 'html'''? + $content = readfile (srcfile ($license_file)); + + if (defined $content && length $content) + { + $template->param (license => + IkiWiki::linkify ($page, $destpage, $content)); + } + } +} + +1 diff --git a/perl/IkiWiki/Plugin/varioki.pm b/perl/IkiWiki/Plugin/varioki.pm new file mode 100644 index 0000000..0132aad --- /dev/null +++ b/perl/IkiWiki/Plugin/varioki.pm @@ -0,0 +1,190 @@ +#!/usr/bin/perl +# -*- Mode: Cperl -*- +# varioki.pm --- +# Author : Manoj Srivastava ( srivasta@glaurung.internal.golden-gryphon.com ) +# Created On : Wed Dec 6 22:25:44 2006 +# Created On Node : glaurung.internal.golden-gryphon.com +# Last Modified By : Manoj Srivastava +# Last Modified On : Thu Dec 7 13:07:36 2006 +# Last Machine Used: glaurung.internal.golden-gryphon.com +# Update Count : 127 +# Status : Unknown, Use with caution! +# HISTORY : +# Description : +# +# arch-tag: 6961717b-156f-4ab2-980f-0d6a973aea21 +# +# Copyright (c) 2006 Manoj Srivastava +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +require 5.002; + +package IkiWiki::Plugin::varioki; + +use warnings; +use strict; +use IkiWiki '1.00'; + +our $VERSION = "0.1"; +my $file = __FILE__; + + +=head1 NAME + +varioki - Add variables for use in ikiwiki templates + +=cut + +=head1 DESCRIPTION + +This plugin attempts to provide a means to add templates for use in +ikiwiki templates, based on a hash variable set in the ikiwiki +configuration file. The motivation for this plugin was to provide an +easy way for end users to add information to be used in templates -- +for example, my C blog entry template does fancy things with +the date components of the entry, and there was no easy way to get +that information into the template. Or if one wants to have a +different page template for the top level index page than for the rest +of the pages in the wiki (for example, to only put special content, +like, say, C play lists, only on the front page). + +This plugin hooks itsef into the C hook, and adds +parameters to the appropriate templates based on the type. For +example, the following inseted into C creates +C, C, C and C which can +then be used in your templates. The array and hash variables are only +for completeness; I suspect that the first two forms are all that are +really required. + + varioki => { + 'motto' => '"Manoj\'s musings"', + 'toplvl' => 'sub {return $page eq "index"}', + 'arrayvar' => '[0, 1, 2, 3]', + 'hashvar' => '{1, 1, 2, 2}' + }, + +Please note that the values in the hash must be simple strings which +are then eval'd, so a string value has to be double quoted, as above +(the eval strips off the outer quotes). + +=cut + + +sub import { #{{{ + hook(type => "pagetemplate", id => "varioki", call => \&pagetemplate); +} # }}} + + +=pod + +For every key in the configured hash, the corresponding value is +evaluated. Based on whether the value was a stringified scalar, code, +array, or hash, the value of the template parameter is generated on +the fly. The available variables are whatever is available to +C hook scripts, namely, C<$page>, C<$destpage>, and +C<$template>. Additionally, the global variables and functions as +defined in the Ikiwiki documentation +(L) may be used. + +=cut + +sub pagetemplate (@) { #{{{ + my %params=@_; + my $page=$params{page}; + my $template=$params{template}; + + return unless defined $config{varioki}; + for my $var (keys %{$config{varioki}}) { + my $value; + my $foo; + eval "\$foo=$config{varioki}{$var}"; + if (ref($foo) eq "CODE") { + $value = $foo->(); + } + elsif (ref($foo) eq "SCALAR") { + $value = $foo; + } + elsif (ref($foo) eq "ARRAY") { + $value = join ' ', @$foo; + } + elsif (ref($foo) eq "HASH") { + for my $i (values %$foo ) { + $value .= ' ' . "$i"; + } + } + else { + $value = $foo; + } +# warn "$page $var $value\n"; + if ($template->query(name => "$var")) { + $template->param("$var" =>"$value"); + } + } +} # }}} + +1; + +=head1 CAVEATS + +This is very inchoate, at the moment, and needs testing. Also, there +is no good way to determine how to handle hashes as values -- +currently, the code just joins all hash values with spaces, but it +would be easier for the user to just use an anonymous sub instead of +passing in a hash or an array. + +=cut + +=head1 BUGS + +Since C evals the configuration file, the values have to all +on a single physical line. This is the reason we need to use strings +and eval, instead of just passing in real anonymous sub references, +since the eval pass converts the coderef into a string of the form +"(CODE 12de345657)" which can't be dereferenced. + +=cut + +=head1 AUTHOR + +Manoj Srivastava + +=head1 COPYRIGHT AND LICENSE + +This script is a part of the Devotee package, and is + +Copyright (c) 2002 Manoj Srivastava + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +=cut + +1; + +__END__ + diff --git a/perl/Image/Magick.pm b/perl/Image/Magick.pm new file mode 100644 index 0000000..e850691 --- /dev/null +++ b/perl/Image/Magick.pm @@ -0,0 +1,69 @@ +# - ImageMagick compatibility wrapper for GraphicsMagick +# +# This package exports GraphicsMagick Perl bindings in the traditional +# ImageMagick/PerlMagick namespace, which allows Perl scripts to change +# from ImageMagick to GraphicsMagick without any code changes. +# +# Copyright (c) 2006 Daniel Kobras +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, +# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package Image::Magick; + +use vars (@ISA); + +require Graphics::Magick; + +@ISA = qw(Graphics::Magick); + +1; +__END__ + +=head1 NAME + +Image::Magick - call GraphicsMagick routines with ImageMagick interface + +=head1 SYNOPSIS + +use Image::Magick + +=head1 DESCRIPTION + +This Perl wrapper provides GraphicsMagick bindings in the namespace +traditionally used by ImageMagick's PerlMagick extension. It is used +to turn GraphicsMagick into a drop-in replacement for ImageMagick in +Perl scripts. It is recommended that scripts are ported to use +GraphicsMagick natively instead of using this compatibility wrapper. + +GraphicsMagick was forked from ImageMagick version 5.5.2, and has since been +developed with an emphasis on interface stability. Therefore, Perl scripts +supporting ImageMagick version 5.5.2 can usually be ported to GraphicsMagick +with little effort. + +=head1 AUTHOR + +Daniel Kobras + +=head1 SEE ALSO + +Graphics::Magick(3pm), perl(1). + +=cut -- cgit v1.2.3