#
# WookeeBox module (BlockWikiBox class)
#
# (C) 2005-2007 Julian Mehnle <julian@mehnle.net>
# $Id$
#
# Provides block markup for boxes (HTML <div>s):
#
#   <box type=blue float=left width=20em>
#   A floating <div> of the CSS class "wookee-box-blue".
#   </box>
#
##############################################################################

package WookeeBox;

use version; our $VERSION = qv('1.103');

package BlockWikiBox;

use strict;
use warnings;

use Wookee;

use base 'BlockWiki';

# Constants:
##############################################################################

use constant TRUE   => (0 == 0);
use constant FALSE  => not TRUE;

# Interface:
##############################################################################

use constant propTag => 'box';

# Implementation:
##############################################################################

BlockWikiBox->register();

sub parseBlock {
    my ($self, $text) = @_;
    
    my $result = $self->SUPER::parseBlock($text);
    
    my $type = $self->{param}->{type};
    my $css_class = defined($type) ? "wookee-box-$type" : "wookee-box";
    
    my $css_style =
        defined($self->{param}->{style}) ?
            $self->{param}->{style} . '; '
        :   '';
    
    my $float = $self->{param}->{float};
    if (defined($float)) {
        $css_style .= "float: $float; ";
        if (defined($type) and $type ne '') {
            $css_style .= 'margin-right: 1em; ' if $float eq 'left';
            $css_style .=  'margin-left: 1em; ' if $float eq 'right';
        }
    }
    
    my $width = $self->{param}->{width};
    $css_style .= "width: $width; " if defined($width);
    
    my $css_attr = defined($css_style) ? "style=\"$css_style\"" : '';
    
    return "<div class=\"$css_class\" $css_attr>$result</div>";
}

TRUE;

