[wellwell-devel] [wellwell] Add Template::Flute engine.

Stefan Hornburg wellwell-devel at rt.icdevgroup.org
Wed Mar 30 13:10:30 UTC 2011


commit f3ac7a6d68c72f7b70e6762ff65dd83be52b63c0
Author: Stefan Hornburg (Racke) <racke at linuxia.de>
Date:   Wed Mar 30 15:10:04 2011 +0200

    Add Template::Flute engine.

 lib/WellWell/Compose/Component/Flute.pm |   82 +++++++++++++++++++++++++++++++
 lib/WellWell/Compose/Engine/Flute.pm    |   62 +++++++++++++++++++++++
 2 files changed, 144 insertions(+), 0 deletions(-)
---
diff --git a/lib/WellWell/Compose/Component/Flute.pm b/lib/WellWell/Compose/Component/Flute.pm
new file mode 100644
index 0000000..eb22fc2
--- /dev/null
+++ b/lib/WellWell/Compose/Component/Flute.pm
@@ -0,0 +1,82 @@
+# WellWell::Compose::Component::Flute - Flute component class for WellWell
+#
+# Copyright (C) 2010 Stefan Hornburg (Racke) <racke at linuxia.de>.
+#
+# 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., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA.
+
+package WellWell::Compose::Component::Flute;
+
+use strict;
+use warnings;
+
+use Template::Flute;
+use Template::Flute::Specification::XML;
+use Template::Flute::HTML;
+
+use Template::Flute::Database::Rose;
+
+use WellWell::Filter::Link;
+
+sub new {
+	my ($class, @parms) = @_;
+
+	my $self = {@parms};
+
+	bless $self;
+
+	return $self;
+}
+
+sub process {
+	my ($self, $attributes) = @_;
+	my ($content, $xml_spec, $spec, $iter_name, $html_object, $flute);
+	my (%filters, $subname, $subref);
+
+	# parse specification
+	$xml_spec = new Template::Flute::Specification::XML;
+
+	unless ($spec = $xml_spec->parse_file($self->{specification})) {
+		die "$0: error parsing $self->{specification}: " . $xml_spec->error() . "\n";
+	}
+
+	$spec->set_iterator('cart', $Vend::Items);
+	$html_object = new Template::Flute::HTML;
+
+	$html_object->parse_file($self->{template}, $spec);
+
+	for my $list_object ($html_object->lists()) {
+		# seed and check input
+		$list_object->input($attributes);
+	}
+
+	# filters
+	$filters{link} = \&WellWell::Filter::Link::filter;
+		
+	$flute = new Template::Flute (template => $html_object, filters => \%filters,
+								database => $self->{database});
+
+	# call component load subroutine
+	$subname = "component_$self->{name}_load";
+	$subref = $Vend::Cfg->{Sub}{$subname} || $Global::GlobalSub->{$subname};
+
+	if ($subref) {
+		$subref->($self->{name}, $spec, $html_object, $flute);
+	}
+	
+	return $flute->process($attributes);
+}
+
+1;
diff --git a/lib/WellWell/Compose/Engine/Flute.pm b/lib/WellWell/Compose/Engine/Flute.pm
new file mode 100644
index 0000000..9f680a7
--- /dev/null
+++ b/lib/WellWell/Compose/Engine/Flute.pm
@@ -0,0 +1,62 @@
+# WellWell::Compose::Engine::Flute - Flute composing engine for WellWell
+#
+# Copyright (C) 2010 Stefan Hornburg (Racke) <racke at linuxia.de>.
+#
+# 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., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA.
+
+package WellWell::Compose::Engine::Flute;
+
+use strict;
+use warnings;
+
+use WellWell::Compose::Component::Flute;
+
+sub new {
+	my $class = shift;
+	my $self = {@_};
+
+	$self->{database} = new Template::Flute::Database::Rose(dbh => $self->{dbh});
+	
+	bless $self;
+	return $self;
+}	
+
+sub locate_component {
+	my ($self, $name) = @_;
+	my (%component_hash, $component, $component_dir);
+
+	$component_dir = "$::Variable->{MV_COMPONENT_DIR}";
+
+	if (-d "$component_dir/$name") {
+		# separate directory for component
+		$component_dir = "$component_dir/$name";
+	}
+
+	if (-f "$component_dir/$name.xml"
+		&& -f "$component_dir/$name.html") {
+		%component_hash = (database => $self->{database},
+						   name => $name,
+						   specification => "$component_dir/$name.xml",
+						   template => "$component_dir/$name.html");
+		
+		$component = new WellWell::Compose::Component::Flute(%component_hash);
+		return $component;
+	}
+	
+	return '';
+}
+
+1;



More information about the wellwell-devel mailing list