summaryrefslogtreecommitdiff
path: root/lib/WebCoso
diff options
context:
space:
mode:
Diffstat (limited to 'lib/WebCoso')
-rw-r--r--lib/WebCoso/File.pm31
-rw-r--r--lib/WebCoso/Maker.pm28
-rw-r--r--lib/WebCoso/Maker/HTML.pm4
-rw-r--r--lib/WebCoso/Maker/RST.pm4
-rw-r--r--lib/WebCoso/Maker/TT.pm4
-rw-r--r--lib/WebCoso/Maker/XHTML.pm5
6 files changed, 59 insertions, 17 deletions
diff --git a/lib/WebCoso/File.pm b/lib/WebCoso/File.pm
new file mode 100644
index 0000000..764cf2f
--- /dev/null
+++ b/lib/WebCoso/File.pm
@@ -0,0 +1,31 @@
+# -*- mode: perl6 -*-
+class WebCoso::File {
+ has Str $.path;
+ has $.lang;
+ has $!contents;
+
+ multi method new($self: $path) {
+ $self.bless(:$path);
+ }
+
+ submethod BUILD(Str(Cool) :$!lang, Str(Cool) :$!path) {}
+
+ multi method contents() {
+ return $!contents //= $.parse();
+ }
+ multi method contents($new_contents) {
+ return $!contents = $.serialise($new_contents);
+ }
+
+ method parse() {
+ return $.path.IO.slurp();
+ }
+ method serialise($contents) {
+ $.path.IO.spurt($contents);
+ return $contents;
+ }
+
+ method modified() {
+ return $.path.IO.modified;
+ }
+}
diff --git a/lib/WebCoso/Maker.pm b/lib/WebCoso/Maker.pm
index 91ceb03..b64c9cf 100644
--- a/lib/WebCoso/Maker.pm
+++ b/lib/WebCoso/Maker.pm
@@ -4,7 +4,7 @@ role WebCoso::Maker[$from,$to] {
has $.basename;
has $.dir;
- method process-contents(:$src,:@deps) { ... }
+ method process-contents($src) { ... }
method dest-files() {
say "Maker[$from,$to]($.dir/$.basename)::dest-files";
@@ -16,8 +16,16 @@ role WebCoso::Maker[$from,$to] {
return $.wc.get-files($.dir,$.basename,$from);
}
+ method get-file($path) {
+ return $.wc.get-file($.dir,$path);
+ }
+
method dep-files() {
- return Hash;
+ return $.wc.load-deps($.dir,$.basename,$to);
+ }
+
+ method set-deps(%deps) {
+ $.wc.save-deps($.dir,$.basename,$to,%deps);
}
method make() {
@@ -34,20 +42,22 @@ role WebCoso::Maker[$from,$to] {
my @deps = %deps{$lang} // ();
say "Maker[$from,$to]($.dir/$.basename)::make lang $lang";
say "Maker[$from,$to]($.dir/$.basename)::make dst modified {$dst ?? $dst.modified !! 'not-there'} src modified {$src.modified}";
- next if $dst and $dst.modified after
+ next if $dst and not $dst.modified before
all($src.modified,@depsĀ».modified.flat);
say "Maker[$from,$to]($.dir/$.basename)::make processing $lang";
- my $processed-contents = self.process-contents(
- src => $src.slurp,
- deps => @depsĀ».slurp,
+ my ($processed-contents,@new_deps) = self.process-contents(
+ $src,
);
- # that .Str.IO is a hack to work around
- # https://rt.perl.org/Public/Bug/Display.html?id=126006
%dsts{$lang} = $.wc.put-file($.dir,$.basename,$lang,$to,
- $processed-contents).Str.IO;
+ $processed-contents);
+ %deps{$lang} = @new_deps
+ if @new_deps;
}
+
+ $.set-deps(%deps);
+
return %dsts;
}
}
diff --git a/lib/WebCoso/Maker/HTML.pm b/lib/WebCoso/Maker/HTML.pm
index 414fe2b..d2803af 100644
--- a/lib/WebCoso/Maker/HTML.pm
+++ b/lib/WebCoso/Maker/HTML.pm
@@ -1,7 +1,7 @@
# -*- mode: perl6 -*-
use WebCoso::Maker;
class WebCoso::Maker::HTML does WebCoso::Maker['xhtml','html'] {
- method process-contents(:src($xhtml),:@deps) {
- return "{$xhtml} decorated";
+ method process-contents($xhtml) {
+ return "{$xhtml.contents} decorated";
}
}
diff --git a/lib/WebCoso/Maker/RST.pm b/lib/WebCoso/Maker/RST.pm
index 76bc127..8f11817 100644
--- a/lib/WebCoso/Maker/RST.pm
+++ b/lib/WebCoso/Maker/RST.pm
@@ -1,7 +1,7 @@
# -*- mode: perl6 -*-
use WebCoso::Maker;
class WebCoso::Maker::RST does WebCoso::Maker['rest.txt','du.xml'] {
- method process-contents(:src($rst),:@deps) {
- return "{$rst} parsed";
+ method process-contents($rst) {
+ return "{$rst.contents} parsed";
}
}
diff --git a/lib/WebCoso/Maker/TT.pm b/lib/WebCoso/Maker/TT.pm
index 256cf54..39ba283 100644
--- a/lib/WebCoso/Maker/TT.pm
+++ b/lib/WebCoso/Maker/TT.pm
@@ -1,7 +1,7 @@
# -*- mode: perl6 -*-
use WebCoso::Maker;
class WebCoso::Maker::TT does WebCoso::Maker['tt','rest.txt'] {
- method process-contents(:src($tt),:@deps) {
- return "{$tt} expanded";
+ method process-contents($tt) {
+ return "{$tt.contents} expanded";
}
}
diff --git a/lib/WebCoso/Maker/XHTML.pm b/lib/WebCoso/Maker/XHTML.pm
index c2b1d9e..ea50ec5 100644
--- a/lib/WebCoso/Maker/XHTML.pm
+++ b/lib/WebCoso/Maker/XHTML.pm
@@ -1,7 +1,8 @@
# -*- mode: perl6 -*-
use WebCoso::Maker;
class WebCoso::Maker::XHTML does WebCoso::Maker['du.xml','xhtml'] {
- method process-contents(:src($du),:@deps) {
- return "{$du} converted";
+ method process-contents($du) {
+ my $stylesheet = $.get-file('du2xhtml.xsl');
+ return ("{$du.contents} converted",$stylesheet);
}
}