From 1cad72ceecfdd03fed63c7424cf0a04a8aa3d5a4 Mon Sep 17 00:00:00 2001 From: dakkar Date: Sat, 5 Sep 2015 13:50:48 +0100 Subject: first attempt --- lib/WebCoso.pm | 38 ++++++++++++++++++++++++++++++++++++++ lib/WebCoso/Doc/Base.pm | 14 ++++++++++++++ lib/WebCoso/Doc/Feed.pm | 4 ++++ lib/WebCoso/Doc/Page.pm | 4 ++++ lib/WebCoso/Maker.pm | 21 +++++++++++++++++++++ 5 files changed, 81 insertions(+) create mode 100644 lib/WebCoso.pm create mode 100644 lib/WebCoso/Doc/Base.pm create mode 100644 lib/WebCoso/Doc/Feed.pm create mode 100644 lib/WebCoso/Doc/Page.pm create mode 100644 lib/WebCoso/Maker.pm (limited to 'lib') diff --git a/lib/WebCoso.pm b/lib/WebCoso.pm new file mode 100644 index 0000000..5202745 --- /dev/null +++ b/lib/WebCoso.pm @@ -0,0 +1,38 @@ +# -*- mode: perl6 -*- +class WebCoso { + has $.srcdir; + has $.destdir; + has $!tmpdir = $*SPEC.tmpdir.child('abcde'); + has @!docs; + + method get-files($dir,$basename,$ext) { + my %files = gather { + for my $base ($.srcdir,$!tmpdir) { + my @files = $base.child($dir).dir( + test => /$basename \. .+? \. $ext/, + ); + take map { + (.name ~~ /$basename \. (.+?) \. $ext/)[0] + => + $_ + } @files; + } + } + return %files; + } + + method put-file($dir,$basename,$lang,$ext,$contents) { + $!tmpdir.child($dir).child("${basename}.${lang}.${ext}").spurt($contents); + return; + } + + method new-doc(:$dir) { + @!docs.push(Document.new(:$dir,wc=>self); + } + method new-feed(:$dir) { + @!docs.push(Feed.new(:$dir,wc=>self); + } + method run() { + .make() for @!docs; + } +} diff --git a/lib/WebCoso/Doc/Base.pm b/lib/WebCoso/Doc/Base.pm new file mode 100644 index 0000000..1b74427 --- /dev/null +++ b/lib/WebCoso/Doc/Base.pm @@ -0,0 +1,14 @@ +# -*- mode: perl6 -*- +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); + + method make() { + .html.get-files(); + } +} diff --git a/lib/WebCoso/Doc/Feed.pm b/lib/WebCoso/Doc/Feed.pm new file mode 100644 index 0000000..2b36c1e --- /dev/null +++ b/lib/WebCoso/Doc/Feed.pm @@ -0,0 +1,4 @@ +# -*- mode: perl6 -*- +use WebCoso::Doc::Base; +class WebCoso::Doc::Feed does WebCoso::Doc::Base['feed'] { +} diff --git a/lib/WebCoso/Doc/Page.pm b/lib/WebCoso/Doc/Page.pm new file mode 100644 index 0000000..be92d8c --- /dev/null +++ b/lib/WebCoso/Doc/Page.pm @@ -0,0 +1,4 @@ +# -*- mode: perl6 -*- +use WebCoso::Doc::Base; +class WebCoso::Doc::Page does WebCoso::Doc::Base['document'] { +} diff --git a/lib/WebCoso/Maker.pm b/lib/WebCoso/Maker.pm new file mode 100644 index 0000000..e9564fa --- /dev/null +++ b/lib/WebCoso/Maker.pm @@ -0,0 +1,21 @@ +# -*- mode: perl6 -*- +role Maker[:$from,:$to] { + has $!wc; + has $.basename; + has $.dir; + + method process-contents(:$from-contents) { ... } + + method get-files() { + my %dsts = $!wc.get-files($.dir,$.basename,$from); + my %srcs = $!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, + $processed-contents) + } + } +} -- cgit v1.2.3