summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2015-09-05 16:21:29 +0100
committerdakkar <dakkar@thenautilus.net>2015-09-05 16:21:29 +0100
commit4078424b9105dba16c50087347b3a607cd75d4d1 (patch)
treebd81983e27be76dcb28254f26c5359be47a8aa8d
parentmore tests (diff)
downloadWebCoso-p6-4078424b9105dba16c50087347b3a607cd75d4d1.tar.gz
WebCoso-p6-4078424b9105dba16c50087347b3a607cd75d4d1.tar.bz2
WebCoso-p6-4078424b9105dba16c50087347b3a607cd75d4d1.zip
first maker test
-rw-r--r--lib/WebCoso.pm9
-rw-r--r--lib/WebCoso/Doc/Base.pm13
-rw-r--r--lib/WebCoso/Maker.pm15
-rw-r--r--lib/WebCoso/Maker/HTML.pm7
-rw-r--r--lib/WebCoso/Maker/RST.pm7
-rw-r--r--lib/WebCoso/Maker/TT.pm7
-rw-r--r--lib/WebCoso/Maker/XHTML.pm7
-rw-r--r--t/lib/Test/WebCoso.pm19
-rw-r--r--t/tests/maker.t34
-rw-r--r--t/tests/webcoso.t18
10 files changed, 105 insertions, 31 deletions
diff --git a/lib/WebCoso.pm b/lib/WebCoso.pm
index 5fe9a07..66fbf5f 100644
--- a/lib/WebCoso.pm
+++ b/lib/WebCoso.pm
@@ -16,7 +16,7 @@ class WebCoso {
CATCH {
when X::IO { }
}
- $base.child($dir).dir(
+ ( $dir ?? $base.child($dir) !! $base ).dir(
test => /$basename \. .+? \. $ext/,
);
} // ();
@@ -30,10 +30,11 @@ class WebCoso {
}
method put-file($dir,$basename,$lang,$ext,$contents) {
- my $t = $!tmpdir.child($dir);
+ my $t = ($dir ?? $!tmpdir.child($dir) !! $!tmpdir);
$t.mkdir;
- $t.child("{$basename}.{$lang}.{$ext}").spurt($contents);
- return;
+ my $f = $t.child("{$basename}.{$lang}.{$ext}");
+ $f.spurt($contents);
+ return $f;
}
method new-doc(:$dir) {
diff --git a/lib/WebCoso/Doc/Base.pm b/lib/WebCoso/Doc/Base.pm
index 2d6bb1a..9ceefa1 100644
--- a/lib/WebCoso/Doc/Base.pm
+++ b/lib/WebCoso/Doc/Base.pm
@@ -1,12 +1,17 @@
# -*- mode: perl6 -*-
+use WebCoso::Maker::TT;
+use WebCoso::Maker::RST;
+use WebCoso::Maker::XHTML;
+use WebCoso::Maker::HTML;
+
role WebCoso::Doc::Base[$basename] {
has $!wc;
has $.dir;
- has $.tt = Maker::TT.new(:$basename,:$!dir,:$!wc);
- has $.rst = Maker::RST.new(:$basename,:$!dir,:$!wc);
- has $.xhtml = Maker::XHTML.new(:$basename,:$!dir,:$!wc);
- has $.html = Maker::HTML.new(:$basename,:$!dir,:$!wc);
+ has $.tt = WebCoso::Maker::TT.new(:$basename,:$!dir,:$!wc);
+ has $.rst = WebCoso::Maker::RST.new(:$basename,:$!dir,:$!wc);
+ has $.xhtml = WebCoso::Maker::XHTML.new(:$basename,:$!dir,:$!wc);
+ has $.html = WebCoso::Maker::HTML.new(:$basename,:$!dir,:$!wc);
method make() {
.html.get-files();
diff --git a/lib/WebCoso/Maker.pm b/lib/WebCoso/Maker.pm
index e9564fa..5aae4f8 100644
--- a/lib/WebCoso/Maker.pm
+++ b/lib/WebCoso/Maker.pm
@@ -1,21 +1,22 @@
# -*- mode: perl6 -*-
-role Maker[:$from,:$to] {
- has $!wc;
+role WebCoso::Maker[$from,$to] {
+ has $.wc;
has $.basename;
has $.dir;
- method process-contents(:$from-contents) { ... }
+ method process-contents($from-contents) { ... }
method get-files() {
- my %dsts = $!wc.get-files($.dir,$.basename,$from);
- my %srcs = $!wc.get-files($.dir,$.basename,$to);
+ my %srcs = $.wc.get-files($.dir,$.basename,$from);
+ my %dsts = $.wc.get-files($.dir,$.basename,$to);
for %srcs.keys -> $lang {
my $src = %srcs{$lang};
next if %dsts{$lang} and
%dsts{$lang}.modified after $src.modified;
- my $processed-contents = .process-contents($src.slurp);
- %dsts{$lang} = $!wc.put-file($.dir,$.basename,$lang,$to,
+ my $processed-contents = self.process-contents($src.slurp);
+ %dsts{$lang} = $.wc.put-file($.dir,$.basename,$lang,$to,
$processed-contents)
}
+ return %dsts;
}
}
diff --git a/lib/WebCoso/Maker/HTML.pm b/lib/WebCoso/Maker/HTML.pm
new file mode 100644
index 0000000..1003cbc
--- /dev/null
+++ b/lib/WebCoso/Maker/HTML.pm
@@ -0,0 +1,7 @@
+# -*- mode: perl6 -*-
+use WebCoso::Maker;
+class WebCoso::Maker::HTML does WebCoso::Maker['xhtml','html'] {
+ method process-contents($xhtml) {
+ return "{$xhtml} decorated";
+ }
+}
diff --git a/lib/WebCoso/Maker/RST.pm b/lib/WebCoso/Maker/RST.pm
new file mode 100644
index 0000000..bf75ab1
--- /dev/null
+++ b/lib/WebCoso/Maker/RST.pm
@@ -0,0 +1,7 @@
+# -*- mode: perl6 -*-
+use WebCoso::Maker;
+class WebCoso::Maker::RST does WebCoso::Maker['rest.txt','du.xml'] {
+ method process-contents($rst) {
+ return "{$rst} parsed";
+ }
+}
diff --git a/lib/WebCoso/Maker/TT.pm b/lib/WebCoso/Maker/TT.pm
new file mode 100644
index 0000000..eb5e390
--- /dev/null
+++ b/lib/WebCoso/Maker/TT.pm
@@ -0,0 +1,7 @@
+# -*- mode: perl6 -*-
+use WebCoso::Maker;
+class WebCoso::Maker::TT does WebCoso::Maker['tt','rest.txt'] {
+ method process-contents($tt) {
+ return "{$tt} expanded";
+ }
+}
diff --git a/lib/WebCoso/Maker/XHTML.pm b/lib/WebCoso/Maker/XHTML.pm
new file mode 100644
index 0000000..d33c447
--- /dev/null
+++ b/lib/WebCoso/Maker/XHTML.pm
@@ -0,0 +1,7 @@
+# -*- mode: perl6 -*-
+use WebCoso::Maker;
+class WebCoso::Maker::XHTML does WebCoso::Maker['du.xml','xhtml'] {
+ method process-contents($du) {
+ return "{$du} converted";
+ }
+}
diff --git a/t/lib/Test/WebCoso.pm b/t/lib/Test/WebCoso.pm
new file mode 100644
index 0000000..1f54c92
--- /dev/null
+++ b/t/lib/Test/WebCoso.pm
@@ -0,0 +1,19 @@
+# -*- mode: perl6 -*-
+unit module Test::WebCoso;
+use Test;
+
+sub cmp-files($a,$b,$msg) is export {
+ ok(
+ ($a.defined and $b.defined and $a.keys eqv $b.keys and
+ [and] map {
+ my $cmp = $b{$_};
+ if $cmp ~~ Callable {
+ $cmp.($a{$_})
+ }
+ else {
+ $a{$_}.abspath eq $cmp.abspath
+ }
+ }, $a.keys),
+ $msg,
+ );
+}
diff --git a/t/tests/maker.t b/t/tests/maker.t
new file mode 100644
index 0000000..38fbfd8
--- /dev/null
+++ b/t/tests/maker.t
@@ -0,0 +1,34 @@
+# -*- mode: perl6 -*-
+use Test;
+use lib 't/lib';
+use Test::WebCoso;
+use File::Temp;
+use WebCoso;
+use WebCoso::Maker::TT;
+
+my $testdir = tempdir.IO;
+my $srcdir = $testdir.child('src');
+my $destdir = $testdir.child('dst');
+
+$srcdir.mkdir;
+$destdir.mkdir;
+
+$srcdir.child('document.it.tt').spurt('it');
+$srcdir.child('document.en.tt').spurt('en');
+
+my $wc = WebCoso.new(:$srcdir,:$destdir);
+
+my $m = WebCoso::Maker::TT.new(basename=>'document',dir=>Nil,:$wc);
+
+my %output = $m.get-files();
+
+cmp-files(
+ %output,
+ {
+ en => { $^x.slurp eq 'en expanded' },
+ it => { $^x.slurp eq 'it expanded' },
+ },
+ 'made the files',
+);
+
+done-testing;
diff --git a/t/tests/webcoso.t b/t/tests/webcoso.t
index 6712eff..6676ded 100644
--- a/t/tests/webcoso.t
+++ b/t/tests/webcoso.t
@@ -2,22 +2,8 @@
use Test;
use File::Temp;
use WebCoso;
-
-sub cmp-files($a,$b,$msg) {
- ok(
- ($a.defined and $b.defined and $a.keys eqv $b.keys and
- [and] map {
- my $cmp = $b{$_};
- if $cmp ~~ Callable {
- $cmp.($a{$_})
- }
- else {
- $a{$_}.abspath eq $cmp.abspath
- }
- }, $a.keys),
- $msg,
- );
-}
+use lib 't/lib';
+use Test::WebCoso;
my $testdir = tempdir.IO;
my $srcdir = $testdir.child('src');