Skip to content

Commit

Permalink
Item11808: perltidy them all, so people are not accidentally impacted…
Browse files Browse the repository at this point in the history
… by the new enforced rule -- Sorry Micha, could not find a way to define specific values within the file

git-svn-id: http://svn.foswiki.org/trunk/StylePlugin@14686 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
OlivierRaginel authored and OlivierRaginel committed May 4, 2012
1 parent 61ea518 commit 95665e8
Showing 1 changed file with 67 additions and 54 deletions.
121 changes: 67 additions & 54 deletions lib/TWiki/Plugins/StylePlugin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# 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, published at
# GNU General Public License for more details, published at
# http://www.gnu.org/copyleft/gpl.html
#
# =========================
Expand All @@ -29,24 +29,23 @@
# insidePREHandler ( $text )
# endRenderingHandler ( $text )
#
# initPlugin is required, all other are optional.
# initPlugin is required, all other are optional.
# For increased performance, all handlers except initPlugin are
# disabled. To enable a handler remove the leading DISABLE_ from
# the function name.
#
#
# NOTE: To interact with TWiki use the official TWiki functions
# in the &TWiki::Func module. Do not reference any functions or
# variables elsewhere in TWiki!!


# =========================
package TWiki::Plugins::StylePlugin; # change the package name!!!
package TWiki::Plugins::StylePlugin; # change the package name!!!

# =========================
use vars qw(
$web $topic $user $installWeb $VERSION $RELEASE $debug
$exampleCfgVar $skipskin
);
$web $topic $user $installWeb $VERSION $RELEASE $debug
$exampleCfgVar $skipskin
);

# This should always be $Rev$ so that TWiki can determine the checked-in
# status of the plugin. It is used by the build automation tools, so
Expand All @@ -58,86 +57,100 @@ $VERSION = '$Rev$';
# of the version number in PLUGINDESCRIPTIONS.
$RELEASE = 'Dakar';

$pstylebegin = '^\.(\w+)\s*$';
$pstylebegin = '^\.(\w+)\s*$';

# =========================
sub initPlugin
{
sub initPlugin {
( $topic, $web, $user, $installWeb ) = @_;

# check for Plugins.pm versions
if( $TWiki::Plugins::VERSION < 1 ) {
&TWiki::Func::writeWarning( "Version mismatch between StylePlugin and Plugins.pm" );
if ( $TWiki::Plugins::VERSION < 1 ) {
&TWiki::Func::writeWarning(
"Version mismatch between StylePlugin and Plugins.pm");
return 0;
}

# Get plugin preferences, the variable defined by: * Set EXAMPLE = ...
# $exampleCfgVar = &TWiki::Func::getPreferencesValue( "STYLEPLUGIN_EXAMPLE" ) || "default";
$skipskin = &TWiki::Func::getPreferencesValue( "STYLEPLUGIN_SKIPSKIN" ) || "";
# Get plugin preferences, the variable defined by: * Set EXAMPLE = ...
# $exampleCfgVar = &TWiki::Func::getPreferencesValue( "STYLEPLUGIN_EXAMPLE" ) || "default";
$skipskin = &TWiki::Func::getPreferencesValue("STYLEPLUGIN_SKIPSKIN") || "";

# Get plugin debug flag
$debug = &TWiki::Func::getPreferencesFlag( "STYLEPLUGIN_DEBUG" );
$styles = &TWiki::Func::getPreferencesValue( "STYLEPLUGIN_SITESTYLES" ) || ".sample {text-decoration:underline}"; # drb 3/9
$applied = 0;
$debug = &TWiki::Func::getPreferencesFlag("STYLEPLUGIN_DEBUG");
$styles = &TWiki::Func::getPreferencesValue("STYLEPLUGIN_SITESTYLES")
|| ".sample {text-decoration:underline}"; # drb 3/9
$applied = 0;

# Plugin correctly initialized
&TWiki::Func::writeDebug( "- TWiki::Plugins::StylePlugin::initPlugin( $web.$topic ) is OK" ) if $debug;
&TWiki::Func::writeDebug(
"- TWiki::Plugins::StylePlugin::initPlugin( $web.$topic ) is OK")
if $debug;
return 1;
}

sub startRenderingHandler
{
sub startRenderingHandler {
### my ( $text, $web ) = @_; # do not uncomment, use $_[0], $_[1] instead

&TWiki::Func::writeDebug( "- StylePlugin::startRenderingHandler( $_[1].$topic )" ) if $debug;
&TWiki::Func::writeDebug(
"- StylePlugin::startRenderingHandler( $_[1].$topic )")
if $debug;

# This handler is called by getRenderedVersion just before the line loop

my $cskin = &TWiki::Func::getSkin();
my $cskin = &TWiki::Func::getSkin();
my $skipit = 0;
foreach my $ss (split(/\s*,\s*/, $skipskin)) {
if ($cskin eq $ss) {
foreach my $ss ( split( /\s*,\s*/, $skipskin ) ) {
if ( $cskin eq $ss ) {
$skipit = 1;
}
}
return if ($skipit);

# do custom extension rule, like for example:
# $_[0] =~ s/old/new/go;
# emit the custom styles ...
$_[0] = "<style type=\"text/css\">$styles</style>\n$_[0]" if ! $applied;
# ... but only once
$applied = 1;
# emit the custom styles ...
$_[0] = "<style type=\"text/css\">$styles</style>\n$_[0]" if !$applied;

# ... but only once
$applied = 1;
}

# ------------------------=
sub outsidePREHandler
{
sub outsidePREHandler {
### my ( $text ) = @_; # do not uncomment, use $_[0] instead

# &TWiki::Func::writeDebug( "- StylePlugin::outsidePREHandler( $web.$topic )" ) if $debug;

# This handler is called by getRenderedVersion, in loop outside of <PRE> tag.
# This is the place to define customized rendering rules.
# Note: This is an expensive function to comment out.
# Consider startRenderingHandler instead
# blockquote begin: ---"(
$_[0] =~ s/^---\"\(\s*$/<blockquote>/go;
# blockquote end: ---")
$_[0] =~ s/^---\"\)\s*$/<\/blockquote>/go;
# pre style begin: ---{.style
$_[0] =~ s/^---\{\.(\w+)\s*$/<pre class=$1>/go;
# pre style end: ---}
$_[0] =~ s/^---\}\s*$/<\/pre>/go;
# div style begin: ---[.style
$_[0] =~ s/^---\[\.(\w+)\s*$/<div class=$1>/go;
# div style end: ---]
$_[0] =~ s/^---\]\s*$/<\/div>/go;
# paragraph style begin: .style
$_[0] =~ s/^\.(\w+)\s*$/<p class=$1>/go;
# acronym: ((acronym)(abbreviation)(text)) e.g. ((acronym)(RSS)(Rich Site Summary))
$_[0] =~ s/\(\(acronym\)\((\w+)\)\(([^\(\)]*)\)\)/<acronym title="$2">$1<\/acronym>/go;
# span: ((style)(text))
$_[0] =~ s/\(\((\w+)\)\(([^\(\)]*)\)\)/<span class=$1>$2<\/span>/go;
# This handler is called by getRenderedVersion, in loop outside of <PRE> tag.
# This is the place to define customized rendering rules.
# Note: This is an expensive function to comment out.
# Consider startRenderingHandler instead
# blockquote begin: ---"(
$_[0] =~ s/^---\"\(\s*$/<blockquote>/go;

# blockquote end: ---")
$_[0] =~ s/^---\"\)\s*$/<\/blockquote>/go;

# pre style begin: ---{.style
$_[0] =~ s/^---\{\.(\w+)\s*$/<pre class=$1>/go;

# pre style end: ---}
$_[0] =~ s/^---\}\s*$/<\/pre>/go;

# div style begin: ---[.style
$_[0] =~ s/^---\[\.(\w+)\s*$/<div class=$1>/go;

# div style end: ---]
$_[0] =~ s/^---\]\s*$/<\/div>/go;

# paragraph style begin: .style
$_[0] =~ s/^\.(\w+)\s*$/<p class=$1>/go;

# acronym: ((acronym)(abbreviation)(text)) e.g. ((acronym)(RSS)(Rich Site Summary))
$_[0] =~
s/\(\(acronym\)\((\w+)\)\(([^\(\)]*)\)\)/<acronym title="$2">$1<\/acronym>/go;

# span: ((style)(text))
$_[0] =~ s/\(\((\w+)\)\(([^\(\)]*)\)\)/<span class=$1>$2<\/span>/go;
}

1;

0 comments on commit 95665e8

Please sign in to comment.