aboutsummaryrefslogtreecommitdiff
path: root/lib/WebCoso/Common.pm
diff options
context:
space:
mode:
authordakkar <dakkar@luxion>2008-01-03 20:35:26 +0000
committerdakkar <dakkar@luxion>2008-01-03 20:35:26 +0000
commit2969fd3ef2ac1004ff4594198e84b31c60adb0c5 (patch)
treeef168964514cf84eca489683cbd00e4f58888fcb /lib/WebCoso/Common.pm
parentrefactoring: xslt (diff)
downloadWebCoso-2969fd3ef2ac1004ff4594198e84b31c60adb0c5.tar.gz
WebCoso-2969fd3ef2ac1004ff4594198e84b31c60adb0c5.tar.bz2
WebCoso-2969fd3ef2ac1004ff4594198e84b31c60adb0c5.zip
refactoring: ReST
git-svn-id: svn://luxion/repos/WebCoso/trunk@328 fcb26f47-9200-0410-b104-b98ab5b095f3
Diffstat (limited to 'lib/WebCoso/Common.pm')
-rw-r--r--lib/WebCoso/Common.pm59
1 files changed, 59 insertions, 0 deletions
diff --git a/lib/WebCoso/Common.pm b/lib/WebCoso/Common.pm
index e6e5ac9..6dbeeae 100644
--- a/lib/WebCoso/Common.pm
+++ b/lib/WebCoso/Common.pm
@@ -1,12 +1,14 @@
package WebCoso::Common;
use strict;
use warnings;
+use File::Next;
use Path::Class;
use XML::LibXML::XPathContext;
our $SRCPATH='src';
our $DSTPATH='dst';
our $DSTBASEURL='/';
+our @TMPLPATH=('common/');
my $xpath=XML::LibXML::XPathContext->new();
$xpath->registerNs('x', 'http://www.w3.org/1999/xhtml');
@@ -92,4 +94,61 @@ sub getTags {
return \%tagged;
}
+sub fromTo {
+ my ($base,$opts)=@_;
+ my $iter=File::Next::files(
+ {
+ file_filter=>$opts->{files},
+ descend_filter=>$opts->{dirs},
+ },
+ $base);
+ my (@ret,$file);
+ if (defined $opts->{transform}) {
+ push @ret,$opts->{transform}->($file) while $file=$iter->();
+ }
+ else {
+ push @ret,$file while $file=$iter->();
+ }
+ return @ret;
+}
+
+{
+my %order=(
+ 'rest.tt'=>0,
+ 'rest.txt'=>1,
+ 'du.xml'=>2,
+);
+sub earliest {
+ my ($a,$b)=@_;
+ return $a unless $b;
+ return $order{$a} < $order{$b}
+ ? $a
+ : $b;
+}
+
+sub keepEarliest {
+ my %dirs;
+ for my $f (@_) {
+ my $c=file($f);
+ my $lang=langOf($c->basename);
+ my $type=typeOf($c->basename);
+ if (!defined $lang or !defined $type) {
+ die "Weird document name <$f>";
+ }
+ $dirs{$c->parent}->{$lang}=earliest($type,$dirs{$c->parent}->{$lang});
+ }
+ my @ret;
+ while (my ($d,$langs)=each %dirs) {
+ while (my ($lang,$type)=each %$langs) {
+ push @ret,file($d,"document.$lang.$type")->stringify;
+ }
+ }
+ return @ret;
+}
+}
+
+our %docfiles=(
+ files=>sub{m{^document\.}},
+ dirs=>sub{!m{^(tags|_webcoso|\.svn)$}});
+
1;