From: Barijaona Ramaholimihaso Date: Thu, 13 Sep 2007 02:26:12 +0000 (+0000) Subject: corrects the $recurse_into_story feature in XML flavours ; clarify documentation X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=4c2e9de90b0039a5617e61d1e1c457d9f011c1da;p=matthijs%2Fupstream%2Fblosxom-plugins.git corrects the $recurse_into_story feature in XML flavours ; clarify documentation --- diff --git a/general/interpolate_fancy b/general/interpolate_fancy index 05ea9a4..a288808 100644 --- a/general/interpolate_fancy +++ b/general/interpolate_fancy @@ -1,7 +1,8 @@ # Blosxom Plugin: interpolate_fancy # Author: Rael Dornfest , # Modified by: Matthijs Kooijman -# Version: 2006-01-14 +# and Barijaona Ramaholimihaso +# Version: 2007-09-13 # Documentation: See the bottom of this file or type: # perldoc interpolate_fancy @@ -19,6 +20,9 @@ our $recurse_into_story = 0; # -------------------------------- +my $parsing_story = 0 ; + + sub start { 1; } @@ -59,7 +63,7 @@ sub _resolve_nested { # we're done. } - $displayitem = $display; + my $displayitem = $display; if ($displayitem) { # Don't care about these tests if we're not displayed anyway. my $negated = ($var =~ s/^\!//); # Remove negation mark if ($negated || !$attr) { @@ -106,16 +110,22 @@ sub interpolate { my $template = shift; # Backward Compatibility with core Blosxom style interpolation - $template =~ s#(?#gs; + unless ($parsing_story) + {$template =~ s#(?#gs; }; # # Conditional inclusion - # - # e.g. stuff + # Defined + # e.g. display if defined + # Undefined + # e.g. display if not defined + # Tests + # eq (eq), ne (ne), lt (<), gt (>), like (=~), unlike (!~) + # e.g. display if $var less than 123 $template = interpolate_fancy::_resolve_nested($template, 1); # - # Variable expansion + # Variable expansion (unconditional, recursive) # # e.g. <$var /> while( $template =~ s/<\$([a-zA-Z?]\w+(?:::)?\w*)\s+?\/>/"defined \$$1 ? \$$1 : undef"/gsee ) { } @@ -154,12 +164,13 @@ sub _test { sub _action { my($plugin, $action, $attr, $content) = @_; + my $result; $content =~ s#<\@(\w+?)\.(\w+?)\s+?(.+?)?(?:>(.*?)<\/\@\1\.\2>|\s+?\/>)#&interpolate_fancy::_action($1,$2,$3,$4)#gse; my $attributes = interpolate_fancy::_attributes($attr); - $blosxom::plugins{$plugin} + $blosxom::plugins{$plugin} > 0 and $plugin->can($action) and $result = $plugin->$action($attributes, $content); @@ -177,6 +188,18 @@ sub _attributes { return $attributes; } +sub story { + my($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_; + + if ($recurse_into_story) { + $parsing_story = 1; + $$title_ref =&$blosxom::interpolate($$title_ref); + $$body_ref =&$blosxom::interpolate($$body_ref); + $parsing_story = 0; + } + return 1; +} + 1; __END__ @@ -187,135 +210,110 @@ Blosxom Plug-in: interpolate_fancy =head1 SYNOPSIS -Overrides Blosxom's far simpler to use, but more limited, default interpolate() -subroutine. - -Include bits of text and template variable values in templates, either -conditionally or unconditionally: +Overrides Blosxom's far simpler to use, but more limited, default interpolate() subroutine. -Perform actions (i.e. call plug-in subroutines) at any point in your page, -whether to act on current content and return results or no. +* Include bits of text and template variable values in templates, either conditionally or unconditionally; -=head2 Variable expansion - This syntax will expand to the value of the referenced variable and can be - used to include dynamic content in your pages. +* Perform actions (i.e. call plug-in subroutines) at any point in your page, whether to act on current content and return results or not. - * Unconditionally and recursively +=head2 Inclusions of bits of text and variables + +This syntax will expand to the value of the referenced variable and can be used to include dynamic content in your pages. - e.g. include a link to the story's path using various template variables. +=over 2 - <$path /> +=item Unconditionally and recursively - Limited by the $recurse_into_story configuration directive (see - the CONFIGURATION below). +e.g. include a link to the story's path using various template variables. - * Unconditionally and recursively (backward compatibility with Blosxom's standard interpolation) +<$path /> - e.g. include a link to the story's path using various template variables. +Limited by the $recurse_into_story configuration directive (see the CONFIGURATION below). - $path +=item Unconditionally (backward compatibility with Blosxom's standard interpolation) - Limited by the $recurse_into_story configuration directive (see - the CONFIGURATION below). +e.g. include a link to the story's path using various template variables (non-recursive, and only inside templates). -==head2 Conditional inclusion - These tags will each have a certain condition attached to them, depending on - what syntax is used exactly. All text between the opening and closing tags - will only be included in the final output of the page if the given condition - is true, it will be discarded otherwise. +$path - Note that as of 2006-01-11 conditional tags can be nested, which effectively - allows you to specify the logical and of two (or more) conditions. There is - no way yet to specify the logical or, though. If you're using nested - conditions and they won't work properly, check your error log, since the - plugin puts warnings about incorrect nestings there. +=item If the template variable has a value (i.e. is defined) - * The template variable has a value (i.e. is defined) +e.g. include a hyperlink to the story's path if it has a path (i.e. $path is defined). - e.g. include a hyperlink to the story's path if it has a path (i.e. - $path is defined). +<$path /> - <$path /> +=item If the template variable doesn't have a value (i.e. is NOT defined) - * The template variable doesn't have a value (i.e. is NOT defined) +e.g. include a hyperlink to home if path is undefined. - e.g. include a hyperlink to home if path is undefined. +home - home +=item If the template variable is equal (=) to a particular value - * The template variable is equal (=) to a particular value +e.g. include "1 writeback" (singular) if the value of writeback count is 1 - e.g. include "1 writeback" (singular) if the value of writeback count is 1 +<$writeback::count /> writeback - <$writeback::count /> writeback +=item If the template variable is not equal (!=) to a particular value - * The template variable is not equal (!=) to a particular value +e.g. include "x writebacks" (plural) if the value of Writeback count (x) is not 1 - e.g. include "x writebacks" (plural) if the value of writeback - count (x) is not 1 +<$writeback::count /> writebacks - <$writeback::count /> writebacks +=item If the template variable is less than (<) a particular value - * The template variable is less than (<) a particular value +e.g. include "no writebacks" if the value of writeback count is < 1 - e.g. include "no writebacks" if the value of writeback count is < 1 +no writebacks - no writebacks +=item If the template variable is greater than (>) a particular value - * The template variable is greater than (>) a particular value +e.g. include "oodles of writebacks" if the value of writeback count is > 50 - e.g. include "oodles of writebacks" if the value of writeback count is > 50 +oodles of writebacks - oodles of writebacks +=item If the template variable is like (=~) a particular regular expression - * The template variable is like (=~) a particular regular expression +e.g. Greet a visitor properly, depending on their courtesy title - e.g. Greet a visitor properly, depending on their courtesy title +Howdy, +Sir +M'am - Howdy, - Sir - M'am +=item If the template variable is unlike (!~) a particular regular expression - * The template variable is unlike (!~) a particular regular expression +e.g. The posting is neither a film nor a book - e.g. The posting is neither a film nor a book +no review - no review +=back =head2 Actions -Perform an action (i.e. call a plug-in's subroutine) at any point in your page. -Optionally pass arguments as key/value pairs stated as XML-style attributes. +Performs an action (i.e. calls a plug-in's subroutine) at any point in your page. Optionally passes arguments as key/value pairs stated as XML-style attributes. + For example: - <@plugin.subroutine arg1="a" arg2="bee" /> +<@thePlugin.subroutine arg1="a" arg2="bee" /> -calls &plugin::subroutine( {'arg1'=>'a', 'arg2'=>'bee' } ). +calls &Blosxom::Plugin::ThePlugin::subroutine( {'arg1'=>'a', 'arg2'=>'bee' } ). -Specify that results should be sent to the browser using the output="yes" -attribute like so: - - <@plugin.subroutine arg1="a" arg2="bee" output="yes" /> +Specify that results should be sent to the browser using the output="yes" attribute like so: +<@thePlugin.subroutine arg1="a" arg2="bee" output="yes" /> -Otherwise, subroutines will still have their effect, but the results will -be tossed out. +Otherwise, subroutines will still have their effect, but the results will be tossed out. -Content wrapped in the action call is sent as another argument to the -subroutine: +Content wrapped in the action call is sent as another argument to the subroutine: - <@plugin.subroutine encoding="Latin1" output="yes"> + <@thePlugin.subroutine encoding="Latin1" output="yes"> pass this content - + -This calls &plugin::subroutine( {'encoding'=>'Latin1', 'output'=>'yes' }, "pass this content" ). +This calls &thePlugin::subroutine( {'encoding'=>'Latin1', 'output'=>'yes' }, "pass this content" ). -Actions are recursive, meaning that you can embed an action inside another, -and so on and so on and so on. Actions are unfolded from the inside out, -with the most deeply embedded first, second deepest second, and so forth until -the outermost action is performed last. +Actions are recursive, meaning that you can embed an action inside another, and so on and so on and so on. Actions are unfolded from the inside out, with the most deeply embedded first, second deepest second, and so forth until the outermost action is performed last. -Recursion is limited by the $recurse_into_story configuration directive (see -the CONFIGURATION below). +Recursion is limited by the $recurse_into_story configuration directive (see the CONFIGURATION below). =head3 An Example @@ -325,22 +323,22 @@ sample actions: -- -# For the sake of this example, assume these actions live in a "myplugin" -# plugin +# For the sake of this example, assume these actions live in a "myplugin" plugin # This action strips HTML from its content + sub strip_html { my($self, $attributes, $content) = @_; $content =~ s!!!g; return $content; } -# This action foreshortens its content to a length specified in the call to -# action's length attribute +# This action foreshortens its content to a length specified in the call to action's length attribute + sub foreshorten { my($self, $attributes, $content) = @_; my $default_length = 144; - return substr($content, 0, $attributes{'length'}||$default_length); + return substr($content, 0, $attributes->{'length'}||$default_length); } -- @@ -348,30 +346,26 @@ sub foreshorten { Calling these individually in a Blosxom flavour template looks something like: The following bit of text is devoid of HTML: + <@myplugin.strip_html output="Yes"> Silly me, I plumb forgot to remove the HTML. The following bit of text is only 20 characters in length: -<@myplugin.foreshorten output="Yes"> -This text is far longer than 20 characters on the page, -but will only appear as "This text is far lon" in the + +<@myplugin.foreshorten length="20" output="Yes">This text is far longer than 20 characters on the page, but will only appear as "This text is far lon" in the resulting page. And in combination, stripping the HTML _before_ foreshortening (notice the strip_html action is embedded inside the foreshorten action and -thus is run first): +thus is run first). The following bit of text is only 20 characters in length and devoid of HTML: -<@myplugin.foreshorten output="Yes"> -<@myplugin.strip_html output="Yes"> -Silly me, I plumb + +<@myplugin.foreshorten length="20" output="Yes"><@myplugin.strip_html output="Yes">Silly me, I plumb forgot to remove the HTML. -This text is far longer than 20 characters on the page, -but will only appear as "This text is far lon" in the -resulting page. @@ -413,7 +407,7 @@ run your templates through the interpolate2fancy utility =head1 VERSION -2006-01-11 +2007-09-13 : corrects the $recurse_into_story feature in XML flavours =head1 AUTHOR