Thread preview; fix robots.txt; comment something that confused myself
This commit is contained in:
parent
91588bd816
commit
1f75b4a47e
|
@ -5,37 +5,45 @@ use Date::Format;
|
||||||
use XML::RSS;
|
use XML::RSS;
|
||||||
|
|
||||||
sub create($self) {
|
sub create($self) {
|
||||||
my $v;
|
my ($v, $draft);
|
||||||
|
|
||||||
$v = $self->validation if $self->req->method eq 'POST';
|
$v = $self->validation if $self->req->method eq 'POST';
|
||||||
|
|
||||||
if ($v && $v->has_data) {
|
if ($v && $v->has_data) {
|
||||||
$v->required('author')->size(1, 63);
|
$v->required('author' )->size(1, 63);
|
||||||
$v->required('title' )->size(1, 127);
|
$v->required('title' )->size(1, 127);
|
||||||
$v->required('body' )->size(2, 4000);
|
$v->required('body' )->size(2, 4000);
|
||||||
|
$v->optional('preview');
|
||||||
|
|
||||||
if ($v->has_error) {
|
if ($v->has_error) {
|
||||||
$self->stash(status => 400)
|
$self->stash(status => 400)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
my $thread_author = $v->param('author');
|
my $thread_author = $v->param('author' );
|
||||||
my $thread_title = $v->param('title' );
|
my $thread_title = $v->param('title' );
|
||||||
my $thread_body = $v->param('body' );
|
my $thread_body = $v->param('body' );
|
||||||
|
my $preview = $v->param('preview');
|
||||||
my $new_thread_id = $self->thread->create(
|
|
||||||
$thread_author,
|
|
||||||
$thread_title,
|
|
||||||
$thread_body
|
|
||||||
);
|
|
||||||
|
|
||||||
$self->session(author => $thread_author);
|
$self->session(author => $thread_author);
|
||||||
|
|
||||||
return $self->redirect_to(
|
unless ($preview) {
|
||||||
single_thread => {thread_id => $new_thread_id}
|
my $new_thread_id = $self->thread->create(
|
||||||
);
|
$thread_author,
|
||||||
|
$thread_title,
|
||||||
|
$thread_body
|
||||||
|
);
|
||||||
|
|
||||||
|
return $self->redirect_to(
|
||||||
|
single_thread => {thread_id => $new_thread_id}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$draft = $thread_body;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$self->stash(draft => $draft);
|
||||||
|
|
||||||
return $self->render;
|
return $self->render;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,8 @@ sub create($self, $author, $title, $body, $hidden = 0, $flagged = 0) {
|
||||||
)
|
)
|
||||||
VALUES (?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?)
|
||||||
RETURNING thread_id;
|
RETURNING thread_id;
|
||||||
END_SQL
|
END_SQL
|
||||||
|
# The indented heredoc got a little confused by this one...
|
||||||
}
|
}
|
||||||
|
|
||||||
sub by_page($self, $this_page = 1) {
|
sub by_page($self, $this_page = 1) {
|
||||||
|
|
|
@ -3,8 +3,6 @@ Disallow: /cursors/
|
||||||
Disallow: /images/
|
Disallow: /images/
|
||||||
Disallow: /fonts/
|
Disallow: /fonts/
|
||||||
Disallow: /moderator/
|
Disallow: /moderator/
|
||||||
Disallow: /thread/bump/
|
|
||||||
Disallow: /thread/flag/
|
|
||||||
Disallow: /remark/flag/
|
|
||||||
Disallow: /login
|
Disallow: /login
|
||||||
Disallow: /logout
|
Disallow: /logout
|
||||||
|
Disallow: /human/
|
||||||
|
|
23
t/preview.t
23
t/preview.t
|
@ -4,12 +4,13 @@ use Test::Mojo;
|
||||||
|
|
||||||
my $t = Test::Mojo->new('PostText');
|
my $t = Test::Mojo->new('PostText');
|
||||||
|
|
||||||
#my %preview_thread = (
|
my %preview_thread = (
|
||||||
# author => 'Anonymous',
|
author => 'Anonymous',
|
||||||
# title => 'hi',
|
title => 'hi',
|
||||||
# body => 'ayy... lmao',
|
body => 'ayy... lmao',
|
||||||
# preview => 1
|
preview => 1
|
||||||
# );
|
);
|
||||||
|
|
||||||
my %preview_remark = (
|
my %preview_remark = (
|
||||||
author => 'Anonymous',
|
author => 'Anonymous',
|
||||||
body => 'ayy... lmao',
|
body => 'ayy... lmao',
|
||||||
|
@ -20,8 +21,8 @@ subtest 'Check the form + button', sub {
|
||||||
$t->get_ok('/remark/post/1')->status_is(200)
|
$t->get_ok('/remark/post/1')->status_is(200)
|
||||||
->element_exists('input[id="preview"]');
|
->element_exists('input[id="preview"]');
|
||||||
|
|
||||||
#$t->get_ok('/thread/post')->status_is(200)
|
$t->get_ok('/thread/post')->status_is(200)
|
||||||
# ->element_exists('input[id="preview"]');
|
->element_exists('input[id="preview"]');
|
||||||
};
|
};
|
||||||
|
|
||||||
subtest 'Submit input', sub {
|
subtest 'Submit input', sub {
|
||||||
|
@ -29,9 +30,9 @@ subtest 'Submit input', sub {
|
||||||
->status_is(200)
|
->status_is(200)
|
||||||
->text_like(p => qr/ayy\.\.\. lmao/);
|
->text_like(p => qr/ayy\.\.\. lmao/);
|
||||||
|
|
||||||
#$t->post_ok('/thread/post', form => \%preview_thread)
|
$t->post_ok('/thread/post', form => \%preview_thread)
|
||||||
# ->status_is(200)
|
->status_is(200)
|
||||||
# ->text_like(p => qr/ayy\.\.\. lmao/);
|
->text_like(p => qr/ayy\.\.\. lmao/);
|
||||||
};
|
};
|
||||||
|
|
||||||
done_testing;
|
done_testing;
|
||||||
|
|
|
@ -11,6 +11,11 @@
|
||||||
% end
|
% end
|
||||||
<h2 class="page-title"><%= title %></h2>
|
<h2 class="page-title"><%= title %></h2>
|
||||||
<form method="post" class="form-body">
|
<form method="post" class="form-body">
|
||||||
|
<% if ($draft) { =%>
|
||||||
|
<div class="form-preview">
|
||||||
|
<%== markdown $draft =%>
|
||||||
|
</div>
|
||||||
|
<% } =%>
|
||||||
<div class="form-field">
|
<div class="form-field">
|
||||||
<% if (my $error = validation->error('author')) { =%>
|
<% if (my $error = validation->error('author')) { =%>
|
||||||
<p class="field-with-error">Must be between <%= $error->[2] %>
|
<p class="field-with-error">Must be between <%= $error->[2] %>
|
||||||
|
@ -52,5 +57,9 @@
|
||||||
rows => 6
|
rows => 6
|
||||||
) %>
|
) %>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-checkbox">
|
||||||
|
<%= check_box preview => 1, id => 'preview' %>
|
||||||
|
<%= label_for preview => 'Preview' %>
|
||||||
|
</div>
|
||||||
<button type="submit" class="form-button">Post</button>
|
<button type="submit" class="form-button">Post</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
Loading…
Reference in a new issue