summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2015-09-05 13:50:48 +0100
committerdakkar <dakkar@thenautilus.net>2015-09-05 13:50:48 +0100
commit1cad72ceecfdd03fed63c7424cf0a04a8aa3d5a4 (patch)
tree0f372bd0b06b621244473e07cd36621b73a8d39b
downloadWebCoso-p6-1cad72ceecfdd03fed63c7424cf0a04a8aa3d5a4.tar.gz
WebCoso-p6-1cad72ceecfdd03fed63c7424cf0a04a8aa3d5a4.tar.bz2
WebCoso-p6-1cad72ceecfdd03fed63c7424cf0a04a8aa3d5a4.zip
first attempt
-rw-r--r--.gitignore2
-rw-r--r--lib/WebCoso.pm38
-rw-r--r--lib/WebCoso/Doc/Base.pm14
-rw-r--r--lib/WebCoso/Doc/Feed.pm4
-rw-r--r--lib/WebCoso/Doc/Page.pm4
-rw-r--r--lib/WebCoso/Maker.pm21
-rw-r--r--run.p613
7 files changed, 96 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..d69566e
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+*~
+/t/data/dst/*
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)
+ }
+ }
+}
diff --git a/run.p6 b/run.p6
new file mode 100644
index 0000000..a041423
--- /dev/null
+++ b/run.p6
@@ -0,0 +1,13 @@
+#!perl6
+use WebCoso;
+
+my $wc = WebCoso.new(
+ srcdir => '/tmp/src',
+ destdir => '/tmp/dest',
+);
+
+
+$wc.new-doc(dir => $_) for «one one/two three/four»;
+$wc.new-feed(dir => $_) for «tags/one tags/two»;
+
+$wc.run;