aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordakkar <dakkar@luxion>2007-07-07 09:43:58 +0000
committerdakkar <dakkar@luxion>2007-07-07 09:43:58 +0000
commit4f41dd5b5338d82cb5849a21e4c8c3f59b900c6c (patch)
tree9a987f95e902f03fb875b885b1850f539d96d45e
parentnuovo progetto, qualche idea (diff)
downloadWebCoso-4f41dd5b5338d82cb5849a21e4c8c3f59b900c6c.tar.gz
WebCoso-4f41dd5b5338d82cb5849a21e4c8c3f59b900c6c.tar.bz2
WebCoso-4f41dd5b5338d82cb5849a21e4c8c3f59b900c6c.zip
r2490@narval: dakkar | 2007-07-07 11:44:04 +0200
roba buttata qua git-svn-id: svn://luxion/repos/WebCoso/trunk@255 fcb26f47-9200-0410-b104-b98ab5b095f3
-rw-r--r--idee-webcoso.rest.txt73
-rw-r--r--rtest.pl124
-rw-r--r--stest.pl131
3 files changed, 328 insertions, 0 deletions
diff --git a/idee-webcoso.rest.txt b/idee-webcoso.rest.txt
new file mode 100644
index 0000000..1020a6f
--- /dev/null
+++ b/idee-webcoso.rest.txt
@@ -0,0 +1,73 @@
+=====================
+ Idee sparse WebCoso
+=====================
+
+Generazione
+===========
+
+Roba tipo ``make`` (``Slay::Maker`` o simili?)
+
+Regole
+------
+
+``*.rest.txt``:
+ ``*.rest.tt`` (TT2)
+``*.docutils.xml``:
+ ``*.rest.txt`` (ReST)
+``categories.xml``:
+ all(``*.docutils.xml``) (dedicato)
+``changes.xml``:
+ all(``*.docutils.xml``) (dedicato)
+``*.xhtml``:
+ ``*.docutils.xml`` + ``categories.xml`` (XSLT+TT2?)
+``feed.rss``:
+ ``*.docutils.xml`` + ``categories.xml`` + ``changes.xml`` (XSLT+TT2?)
+
+Caching
+-------
+
+``$cache{nomefile}`` tiene il risultato del parse di ``nomefile``
+
+Casi particolari
+================
+
+Nomi delle categorie
+--------------------
+
+Le categorie *devono* avere un documento ciascuna, altrimenti non se
+ne cava le gambe. Lì dentro ci stanno i nomi (ovviamente un file per
+lingua etc.)
+
+Indici delle categorie
+----------------------
+
+Chiave speciale in docutils che viene espansa all'ultimo passo? (tanto
+abbiamo tutti i documenti in memoria…)
+
+Default e specifici
+-------------------
+
+Ogni documento ha, nella stessa directory, i template che gli
+servono. Di solito sono symlink.
+
+Per le pagine di indice delle categorie, possiamo avere un
+``.rest.tt`` che genera l'indice banale con 1 riga, o prende il path
+(e quindi è un symlink a un template uguale per tutte), oppure
+facciamo tutto all'ultimo passo (bruttino).
+
+Multilingua
+-----------
+
+Col trucco di ``mod_rewrite`` dovremmo farcela.
+
+Durante ciascun passo, bisogna sapere in che lingua è (dal nome del
+file, direi che basta), altrimenti i titoli e reference non vengono
+fuori nella lingua giusta.
+
+Link -> titoli
+--------------
+
+Al passo ultimo, abbiamo tutto.
+
+Non è chiaro come marcarli, ma ad esempio
+```</path/al/documento/>`_`` dovrebbe andare.
diff --git a/rtest.pl b/rtest.pl
new file mode 100644
index 0000000..df031fd
--- /dev/null
+++ b/rtest.pl
@@ -0,0 +1,124 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use XML::LibXML;
+use Text::Restructured;
+use YAML;
+
+my $input=<<'EOF';
+======
+ Test
+======
+:Author: dakkar
+
+paragrafo
+
+link
+
+mathml: :mathml:`x^2`
+
+.. mathml::
+
+ (x^2)/(y^2)
+
+pre::
+
+ gino pino
+ rino
+
+normale
+
+:titlink:`/path/al/doc/`
+
+EOF
+my $name='--inline--';
+
+my $opts={
+ D => {
+ generator => 0,
+ 'source-link' => 0,
+ 'time' => 0,
+ },
+};
+my $parser=Text::Restructured->new($opts,'gino');
+if (@ARGV) {
+ $name=$ARGV[0];
+ $input=do{open my $fh,'<',$name;local $/;<$fh>};
+}
+
+# bad MNODINE, no cookie
+# MY_ROLES gets re-inited before every Parse, so I have to change a
+# global variable
+$Text::Restructured::ROLES{titlink}={
+ tag => 'reference',
+ attr => {
+ refuri => '%s',
+ role => sub {
+ my ($parser,$attr,$text,$role)=@_;
+ $role;
+ }
+ },
+ text => 'dummy',
+};
+
+my $dudom=$parser->Parse($input,$name);
+
+my $xdoc=XML::LibXML->createDocument();
+
+my $MATHML='http://www.w3.org/1998/Math/MathML';
+sub mathml2xml {
+ my ($mnode)=@_;
+
+ if ($mnode->isText) {
+ return $xdoc->createTextNode($mnode->nodeValue);
+ }
+
+
+ my @children=map {mathml2xml($_)}
+ $mnode->childNodes();
+
+ my $elem=$xdoc->createElementNS($MATHML,$mnode->nodeName);
+ for my $attname ($mnode->attributeList) {
+ next if $attname eq 'xmlns';
+ $elem->setAttribute($attname,
+ $mnode->attribute($attname))
+ }
+
+ $elem->appendChild($_) for @children;
+
+ return $elem;
+}
+
+sub docutils2xml {
+ my ($dunode)=@_;
+
+ if ($dunode->{tag} eq '#PCDATA') {
+ return $xdoc->createTextNode($dunode->{text} || '');
+ }
+
+ if ($dunode->{tag} eq 'mathml') {
+ return mathml2xml($dunode->{attr}{mathml});
+ }
+
+ my @children=map {docutils2xml($_)}
+ @{ $dunode->{content} || [] };
+
+ my $elem=$xdoc->createElement($dunode->{tag});
+
+ if (defined $dunode->{attr}) {
+ while (my ($attname,$attval)=each %{$dunode->{attr}}) {
+ if (! defined $attval) {
+ $attval='';
+ }
+ elsif (ref($attval) eq 'ARRAY') {
+ $attval=join ' ',@$attval;
+ }
+ $elem->setAttribute($attname,$attval);
+ }
+ }
+ $elem->appendChild($_) for @children;
+
+ return $elem;
+}
+$xdoc->setDocumentElement(docutils2xml($dudom));
+print $xdoc->toString();
diff --git a/stest.pl b/stest.pl
new file mode 100644
index 0000000..c468c87
--- /dev/null
+++ b/stest.pl
@@ -0,0 +1,131 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use Slay::Maker;
+use File::Next;
+use Path::Class;
+
+sub expandTT {
+ my ($maker,$target,$deps,$matches)=@_;
+
+ print "TT: $target <- @$deps, @$matches\n";
+ open my $fh,'>',$target;
+}
+
+sub parseRST {
+ my ($maker,$target,$deps,$matches)=@_;
+
+ print "RST: $target <- @$deps, @$matches\n";
+ open my $fh,'>',$target;
+}
+
+sub du2html {
+ my ($maker,$target,$deps,$matches)=@_;
+
+ print "HTML: $target <- @$deps, @$matches\n";
+ open my $fh,'>',$target;
+}
+
+sub getTags {
+ my ($maker,$target,$deps,$matches)=@_;
+
+ print "tags: $target <- @$deps, @$matches\n";
+ open my $fh,'>',$target;
+}
+
+
+sub getChanges {
+ my ($maker,$target,$deps,$matches)=@_;
+
+ print "changes: $target <- @$deps, @$matches\n";
+ open my $fh,'>',$target;
+}
+
+sub ifExists {
+ my ($src)=@_;
+ return sub {
+ my ($maker,$target,$matches)=@_;
+ my $dep=Slay::MakerRule::var_expand_dep($src,$target,$matches);
+ return if -e $target and ! -e $dep;
+ return $dep;
+ }
+}
+
+sub fromTo {
+ my ($base,$opts)=@_;
+ my $iter=File::Next::files(
+ {
+ file_filter=>$opts->{files},
+ descend_filter=>$opts->{dirs},
+ },
+ $base);
+ my (@ret,$file);
+ if (defined $opts->{transform}) {
+ push @ret,$opts->{transform}->($file) while $file=$iter->();
+ }
+ else {
+ push @ret,$file while $file=$iter->();
+ }
+ return @ret;
+}
+
+{
+my %order=(
+ 'document.rest.tt'=>0,
+ 'document.rest.txt'=>1,
+ 'document.du.xml'=>2,
+);
+sub earliest {
+ my ($a,$b)=@_;
+ return $a unless $b;
+ return $order{$a} < $order{$b}
+ ? $a
+ : $b;
+}
+}
+
+sub keepEarliest {
+ my %dirs;
+ for my $f (@_) {
+ my $c=file($f);
+ $dirs{$c->parent}=earliest($c->basename,$dirs{$c->parent});
+ }
+ my @ret;
+ while (my ($d,$f)=each %dirs) {
+ push @ret,file($d,$f)->stringify;
+ }
+ return @ret;
+}
+
+my %files=(files=>sub{m{^document\.}});
+
+my $maker=Slay::Maker->new({
+ rules => [
+ ['src/(**)/document.rest.txt',':',ifExists('src/$1/document.rest.tt'),'=',\&expandTT],
+ ['src/(**)/document.du.xml',':',ifExists('src/$1/document.rest.txt'),'=',\&parseRST],
+ ['deps/tags.xml',':',fromTo('src/',{%files,transform=>sub{my $s=shift;$s=~s{\..*$}{.du.xml};$s}}),'=',\&getTags],
+ ['deps/changes.xml',':',keepEarliest(fromTo('src/',{%files})),'=',\&getChanges],
+ ['dst/(**)/document.xhtml',':','deps/tags.xml','deps/changes.xml',ifExists('src/$1/document.du.xml'),'=',\&du2html],
+ ],
+ options => {
+ auto_create_dirs => 1,
+ #detect_no_diffs => 1,
+ #detect_no_size_change => 1,
+ #debug => 1,
+ },
+});
+
+my @targets=fromTo('src/',
+ {
+ %files,
+ transform=>sub{
+ my $src=shift;
+ $src=~s{\..*$}{.xhtml};
+ $src=~s{^src/}{dst/};
+ return $src;
+ },
+ });
+
+print "targets: @targets\n";
+$maker->make(@targets);
+