[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb: [1027] branches/1.2-experimental/LedgerSMB



Revision: 1027
          http://svn.sourceforge.net/ledger-smb/?rev=1027&view=rev
Author:   einhverfr
Date:     2007-04-04 12:58:36 -0700 (Wed, 04 Apr 2007)

Log Message:
-----------
Adding template handling to this branch

Added Paths:
-----------
    branches/1.2-experimental/LedgerSMB/Template/
    branches/1.2-experimental/LedgerSMB/Template/HTML.pm
    branches/1.2-experimental/LedgerSMB/Template.pm

Added: branches/1.2-experimental/LedgerSMB/Template/HTML.pm
===================================================================
--- branches/1.2-experimental/LedgerSMB/Template/HTML.pm	                        (rev 0)
+++ branches/1.2-experimental/LedgerSMB/Template/HTML.pm	2007-04-04 19:58:36 UTC (rev 1027)
@@ -0,0 +1,57 @@
+=head1 NAME
+
+LedgerSMB::Template::HTML  Template support module for LedgerSMB
+
+=head1 METHODS
+
+=item get_template ()
+
+=item preprocess ($vars)
+This method returns a reference to a hash that contains a copy of the passed
+hashref's data with HTML entities converted to escapes. 
+
+=item postprocess ()
+
+=head1 Copyright (C) 2007, The LedgerSMB core team.
+
+# This work contains copyrighted information from a number of sources all used
+# with permission.  
+#
+# It is released under the GNU General Public License Version 2 or, at your 
+# option, any later version.  See COPYRIGHT file for details.  For a full list 
+# including contact information of contributors, maintainers, and copyright 
+# holders, see the CONTRIBUTORS file.
+=cut
+
+use Error qw(:try);
+use CGI;
+
+package LedgerSMB::Template::HTML;
+
+sub get_template {
+	my $name = shift;
+	return "${name}.html";
+}
+
+sub preprocess {
+	my $rawvars = shift;
+	my $vars;
+	my $type = ref $rawvars;
+
+#XXX fix escaping function
+	if ($type eq 'ARRAY') {
+	} elsif ($type eq 'HASH') {
+		for (keys %{$rawvars}) {
+			$vars->{$_} = preprocess($rawvars[$_]);
+		}
+	} else {
+		return CGI::escapeHTML($rawvars); 
+	}
+}
+
+sub postprocess {
+	my $parent = shift;
+	return;
+}
+
+1;


Property changes on: branches/1.2-experimental/LedgerSMB/Template/HTML.pm
___________________________________________________________________
Name: svn:executable
   + *

Added: branches/1.2-experimental/LedgerSMB/Template.pm
===================================================================
--- branches/1.2-experimental/LedgerSMB/Template.pm	                        (rev 0)
+++ branches/1.2-experimental/LedgerSMB/Template.pm	2007-04-04 19:58:36 UTC (rev 1027)
@@ -0,0 +1,87 @@
+#=====================================================================
+#
+# Template support module for LedgerSMB
+# LedgerSMB::Template
+#
+# LedgerSMB 
+# Small Medium Business Accounting software
+# http://www.ledgersmb.org/
+# 
+#
+# Copyright (C) 2007
+# This work contains copyrighted information from a number of sources all used
+# with permission.  It is released under the GNU General Public License 
+# Version 2 or, at your option, any later version.  See COPYRIGHT file for 
+# details.
+#
+#
+#======================================================================
+# This package contains template related functions:
+#
+#
+#====================================================================
+use Error qw(:try);
+use Template;
+use LedgerSMB::Sysconfig;
+
+package LedgerSMB::Template;
+
+sub new {
+	my $class = shift;
+	my $self = {};
+	$self->{myconfig} = shift;
+	$self->{template} = shift;
+	$self->{format} = shift;
+	$self->{language} = shift;
+	$self->{output} = '';
+	bless $self, $class;
+	return $self;
+}
+
+sub valid_language {
+	my $self = shift;
+	# XXX Actually perform validity checks
+	return 1;
+}
+
+sub render {
+	my $self = shift;
+	my $vars = shift;
+	my $template;
+
+	if (not defined $self->{language}) {
+		$template = Template->new({
+			INCLUDE_PATH => $self->{'myconfig'}->{'templates'},
+			START_TAG => quotemeta('<?lsmb'),
+			END_TAG => quotemeta('?>'),
+			DELIMITER => ';',
+			}) || throw Error::Simple Template->error(); 
+	} elsif ($self->valid_language()) {
+		$template = Template->new({
+			INCLUDE_PATH => "$self->{'myconfig'}->{'templates'}/$self->{language};$self->{'myconfig'}->{'templates'}",
+			START_TAG => quotemeta('<?lsmb'),
+			END_TAG => quotemeta('?>'),
+			DELIMITER => ';',
+			}) || throw Error::Simple Template->error();
+	} else {
+		throw Error::Simple 'Invalid language';
+	}
+
+	eval "require LedgerSMB::Template::$self->{format}";
+	if ($@) {
+		throw Error::Simple $@;
+	}
+
+	my $cleanvars = &{"LedgerSMB::Template::$self->{format}::preprocess"}($vars);
+	if (not $template->process(
+		&{"LedgerSMB::Template::$self->{format}::get_template"}($self->{template}), 
+			$cleanvars, \$self->{output}, binmode => ':utf8')) {
+		throw Error::Simple $template->error();
+	}
+
+	&{"LedgerSMB::Template::$self->{format}::postprocess"}($self);
+
+	return $self->{output};
+}
+
+1;


Property changes on: branches/1.2-experimental/LedgerSMB/Template.pm
___________________________________________________________________
Name: svn:executable
   + *


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.