diff options
author | dakkar <dakkar@thenautilus.net> | 2015-09-05 16:21:29 +0100 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2015-09-05 16:21:29 +0100 |
commit | 4078424b9105dba16c50087347b3a607cd75d4d1 (patch) | |
tree | bd81983e27be76dcb28254f26c5359be47a8aa8d /lib | |
parent | more tests (diff) | |
download | WebCoso-p6-4078424b9105dba16c50087347b3a607cd75d4d1.tar.gz WebCoso-p6-4078424b9105dba16c50087347b3a607cd75d4d1.tar.bz2 WebCoso-p6-4078424b9105dba16c50087347b3a607cd75d4d1.zip |
first maker test
Diffstat (limited to 'lib')
-rw-r--r-- | lib/WebCoso.pm | 9 | ||||
-rw-r--r-- | lib/WebCoso/Doc/Base.pm | 13 | ||||
-rw-r--r-- | lib/WebCoso/Maker.pm | 15 | ||||
-rw-r--r-- | lib/WebCoso/Maker/HTML.pm | 7 | ||||
-rw-r--r-- | lib/WebCoso/Maker/RST.pm | 7 | ||||
-rw-r--r-- | lib/WebCoso/Maker/TT.pm | 7 | ||||
-rw-r--r-- | lib/WebCoso/Maker/XHTML.pm | 7 |
7 files changed, 50 insertions, 15 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"; + } +} |