summaryrefslogtreecommitdiff
path: root/lib/VNDB/Handler/Docs.pm
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2019-09-25 18:37:29 +0200
committerYorhel <git@yorhel.nl>2019-09-25 18:49:19 +0200
commitd735e66d7d9b2d8c9a965ec96753864ff8c306c2 (patch)
treece0214b9e3cc819252b9192e7518f7768e568c77 /lib/VNDB/Handler/Docs.pm
parentc7642c03d99ed0255614a43fb82e55a1dde66753 (diff)
v2rw: Add Elm & db_edit framework + Convert doc page editing
Most of this is copied from v3. I did improve on a few aspects: - db_edit() and db_entry() use VNDB::Schema rather than dynamically querying the DB. This has the minor advantage of a faster startup. - The Elm code generator now writes to multiple files, this avoids the namespace pollution seen in v3's Lib.Gen and makes the dependency graph a bit more lean (i.e. faster incremental builds). - The Elm code generator doesn't update the timestamp of files that haven't been modified. This also speeds up incremental builds, the elm compiler can now skip rebuilding unmodified files. - The Elm API response generator code now uses plain functions rather than code references and all possible responses are now defined in Elm.pm. Turns out most API responses were used from more than a single place, so it makes sense to have them centrally defined. The doc page preview function is also much nicer; I'd like to apply this to all BBCode textareas as well. (Elm.pm itself is ugly as hell though. And we will prolly need some HTML form generation functions in Elm to make that part less verbose)
Diffstat (limited to 'lib/VNDB/Handler/Docs.pm')
-rw-r--r--lib/VNDB/Handler/Docs.pm78
1 files changed, 0 insertions, 78 deletions
diff --git a/lib/VNDB/Handler/Docs.pm b/lib/VNDB/Handler/Docs.pm
deleted file mode 100644
index 4fabf1d3..00000000
--- a/lib/VNDB/Handler/Docs.pm
+++ /dev/null
@@ -1,78 +0,0 @@
-
-package VNDB::Handler::Docs;
-
-
-use strict;
-use warnings;
-use TUWF ':html';
-use VNDB::Func;
-use Text::MultiMarkdown 'markdown';
-use VNWeb::Docs::Lib;
-
-
-TUWF::register(
- qr{d([1-9]\d*)(?:\.([1-9]\d*))?/edit} => \&edit,
-);
-
-
-sub edit {
- my($self, $id, $rev) = @_;
-
- my $d = $self->dbDocGetRev(id => $id, rev => $rev)->[0];
- return $self->resNotFound if !$d->{id};
- $rev = undef if $d->{lastrev};
-
- return $self->htmlDenied if !$self->authCan('dbmod');
-
- my %b4 = map { $_ => $d->{$_} } qw|title content ihid ilock|;
- my $frm;
-
- if($self->reqMethod eq 'POST') {
- return if !$self->authCheckCode;
- $frm = $self->formValidate(
- { post => 'title', maxlength => 200 },
- { post => 'content', },
- { post => 'editsum', template => 'editsum' },
- { post => 'ihid', required => 0 },
- { post => 'ilock', required => 0 },
- { post => 'preview', required => 0 },
- );
- if(!$frm->{_err} && !$frm->{preview}) {
- $frm->{ihid} = $frm->{ihid}?1:0;
- $frm->{ilock} = $frm->{ilock}?1:0;
-
- return $self->resRedirect("/d$id", 'post') if !form_compare(\%b4, $frm);
- my $nrev = $self->dbItemEdit(d => $id, $d->{rev}, %$frm);
- return $self->resRedirect("/d$nrev->{itemid}.$nrev->{rev}", 'post');
- }
- }
-
- !defined $frm->{$_} && ($frm->{$_} = $b4{$_}) for keys %b4;
- $frm->{editsum} = sprintf 'Reverted to revision d%d.%d', $id, $rev if $rev && !defined $frm->{editsum};
- delete $frm->{_err} if $frm->{preview};
-
- my $title = "Edit $d->{title}";
- $self->htmlHeader(title => $title, noindex => 1);
- $self->htmlMainTabs('d', $d, 'edit');
-
- if($frm->{preview}) {
- div class => 'mainbox';
- h1 'Preview';
- div class => 'docs';
- lit md2html $frm->{content};
- end;
- end;
- }
-
- $self->htmlForm({ frm => $frm, action => "/d$id/edit", editsum => 1, preview => 1 }, dedit => [ $title,
- [ input => name => 'Title', short => 'title', width => 300 ],
- [ static => nolabel => 1, content => q{
- <br>Contents (HTML and MultiMarkdown supported, which is
- <a href="https://daringfireball.net/projects/markdown/basics">Markdown</a>
- with some <a href="http://fletcher.github.io/MultiMarkdown-5/syntax.html">extensions</a>).} ],
- [ textarea => short => 'content', name => 'Content', rows => 50, cols => 90, nolabel => 1 ],
- ]);
- $self->htmlFooter;
-}
-
-1;