Compare commits
25 Commits
14e88b24cf
...
56e9365c45
Author | SHA1 | Date | |
---|---|---|---|
56e9365c45 | |||
bec86785d8 | |||
808dd7cd14 | |||
449edcecba | |||
fe2089e525 | |||
a2004aba7b | |||
dafbd6bde4 | |||
817dbc046b | |||
9cdc7aaf06 | |||
4c1eb3966d | |||
3f8b5f82e9 | |||
11e090258e | |||
40cc03a62d | |||
5651d7b208 | |||
f5caae569f | |||
d622219b22 | |||
df31080154 | |||
3c5f86c3de | |||
ce7ea8c755 | |||
df870f682f | |||
58670e3244 | |||
8c69bf31c0 | |||
2cbe24584b | |||
f04c9b81cb | |||
fc0d1cb1db |
@ -61,7 +61,7 @@ tests locally:
|
|||||||
|
|
||||||
## TODOs
|
## TODOs
|
||||||
|
|
||||||
- Stop working on this and start the imageboard
|
- Do I need `SUM` for `by_id()`?
|
||||||
|
|
||||||
## AGPL-3.0+ANTIFA compliance
|
## AGPL-3.0+ANTIFA compliance
|
||||||
|
|
||||||
|
1
cpanfile
1
cpanfile
@ -7,3 +7,4 @@ requires 'XML::RSS';
|
|||||||
requires 'Text::Markdown';
|
requires 'Text::Markdown';
|
||||||
requires 'HTML::Restrict';
|
requires 'HTML::Restrict';
|
||||||
requires 'Roman::Unicode';
|
requires 'Roman::Unicode';
|
||||||
|
requires 'SlapbirdAPM::Agent::Mojo';
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
{
|
{
|
||||||
max_thread_pages => 10,
|
max_thread_pages => 10,
|
||||||
threads_per_page => 5,
|
threads_per_page => 5,
|
||||||
remarks_per_page => 5,
|
remarks_per_page => 5,
|
||||||
results_per_page => 5,
|
results_per_page => 5,
|
||||||
body_max_length => 8_000,
|
body_max_length => 8_000,
|
||||||
version => 'Feb 11 2025',
|
version => 'Feb 11 2025',
|
||||||
secrets => ['t0p_s3cr3t'],
|
secrets => ['t0p_s3cr3t'],
|
||||||
development => {
|
version => 'cool version string here',
|
||||||
|
slapbirdapm_api_key => 'AyyLmao39b4eb99de26d437633e49555',
|
||||||
|
development => {
|
||||||
pg_string =>
|
pg_string =>
|
||||||
'postgresql://post_text:t0p_s3cr3t@127.0.0.1/post_text'
|
'postgresql://post_text:t0p_s3cr3t@127.0.0.1/post_text'
|
||||||
},
|
},
|
||||||
|
@ -19,6 +19,12 @@ sub startup($self) {
|
|||||||
$self->plugin('Config');
|
$self->plugin('Config');
|
||||||
$self->plugin('TagHelpers::Pagination');
|
$self->plugin('TagHelpers::Pagination');
|
||||||
|
|
||||||
|
# Alpha testing Slapbird APM
|
||||||
|
if (my $slapbirdapm_api_key = $self->config->{'slapbirdapm_api_key'}) {
|
||||||
|
$self->plugin('SlapbirdAPM', key => $slapbirdapm_api_key)
|
||||||
|
if $self->mode eq 'production'
|
||||||
|
}
|
||||||
|
|
||||||
# Helpers
|
# Helpers
|
||||||
$self->helper(pg => sub ($c) {
|
$self->helper(pg => sub ($c) {
|
||||||
state $pg = Mojo::Pg->new($c->config->{$self->mode}{'pg_string'})
|
state $pg = Mojo::Pg->new($c->config->{$self->mode}{'pg_string'})
|
||||||
@ -91,7 +97,7 @@ sub startup($self) {
|
|||||||
# Finish configuring some things
|
# Finish configuring some things
|
||||||
$self->secrets($self->config->{'secrets'}) || die $@;
|
$self->secrets($self->config->{'secrets'}) || die $@;
|
||||||
|
|
||||||
$self->pg->migrations->from_dir('migrations')->migrate(15);
|
$self->pg->migrations->from_dir('migrations')->migrate(16);
|
||||||
|
|
||||||
if (my $threads_per_page = $self->config->{'threads_per_page'}) {
|
if (my $threads_per_page = $self->config->{'threads_per_page'}) {
|
||||||
$self->thread->per_page($threads_per_page)
|
$self->thread->per_page($threads_per_page)
|
||||||
|
@ -32,10 +32,11 @@ sub create($self) {
|
|||||||
$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('body' )->size(2, $body_limit);
|
$v->required('body' )->size(2, $body_limit);
|
||||||
$v->optional('bump' );
|
$v->optional('bump' );
|
||||||
$v->optional('preview');
|
$v->optional('preview' );
|
||||||
|
$v->optional('markdown');
|
||||||
$v->csrf_protect;
|
$v->csrf_protect;
|
||||||
|
|
||||||
if ($v->has_error('csrf_token')) {
|
if ($v->has_error('csrf_token')) {
|
||||||
@ -48,10 +49,11 @@ sub create($self) {
|
|||||||
$self->stash(status => 400)
|
$self->stash(status => 400)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
my $remark_author = $v->param('author' );
|
my $remark_author = $v->param('author' );
|
||||||
my $remark_body = $v->param('body' );
|
my $remark_body = $v->param('body' );
|
||||||
my $bump_thread = $v->param('bump' );
|
my $bump_thread = $v->param('bump' );
|
||||||
my $preview = $v->param('preview');
|
my $preview = $v->param('preview' );
|
||||||
|
my $markdown = $v->param('markdown');
|
||||||
|
|
||||||
$self->session(author => $remark_author);
|
$self->session(author => $remark_author);
|
||||||
|
|
||||||
@ -59,7 +61,8 @@ sub create($self) {
|
|||||||
$self->remark->create(
|
$self->remark->create(
|
||||||
$thread_id,
|
$thread_id,
|
||||||
$remark_author,
|
$remark_author,
|
||||||
$remark_body
|
$remark_body,
|
||||||
|
$markdown
|
||||||
);
|
);
|
||||||
|
|
||||||
$self->thread->bump($thread_id) if $bump_thread;
|
$self->thread->bump($thread_id) if $bump_thread;
|
||||||
@ -70,7 +73,7 @@ sub create($self) {
|
|||||||
})->fragment('remarks'));
|
})->fragment('remarks'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$draft = $remark_body;
|
$draft = {body => $remark_body, markdown => $markdown};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,10 +11,11 @@ sub create($self) {
|
|||||||
$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, $body_limit);
|
$v->required('body' )->size(2, $body_limit);
|
||||||
$v->optional('preview');
|
$v->optional('preview' );
|
||||||
|
$v->optional('markdown');
|
||||||
$v->csrf_protect;
|
$v->csrf_protect;
|
||||||
|
|
||||||
if ($v->has_error('csrf_token')) {
|
if ($v->has_error('csrf_token')) {
|
||||||
@ -27,10 +28,11 @@ sub create($self) {
|
|||||||
$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 $preview = $v->param('preview' );
|
||||||
|
my $markdown = $v->param('markdown');
|
||||||
|
|
||||||
$self->session(author => $thread_author);
|
$self->session(author => $thread_author);
|
||||||
|
|
||||||
@ -38,7 +40,8 @@ sub create($self) {
|
|||||||
my $new_thread_id = $self->thread->create(
|
my $new_thread_id = $self->thread->create(
|
||||||
$thread_author,
|
$thread_author,
|
||||||
$thread_title,
|
$thread_title,
|
||||||
$thread_body
|
$thread_body,
|
||||||
|
$markdown
|
||||||
);
|
);
|
||||||
|
|
||||||
return $self->redirect_to(
|
return $self->redirect_to(
|
||||||
@ -46,7 +49,7 @@ sub create($self) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$draft = $thread_body;
|
$draft = {body => $thread_body, markdown => $markdown};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -238,7 +238,8 @@ sub thread_by_id($self, $thread_id) {
|
|||||||
t.thread_title AS title,
|
t.thread_title AS title,
|
||||||
t.thread_body AS body,
|
t.thread_body AS body,
|
||||||
COUNT(r.*) AS remark_tally,
|
COUNT(r.*) AS remark_tally,
|
||||||
t.bump_tally AS bump_tally
|
t.bump_tally AS bump_tally,
|
||||||
|
t.markdown_status AS markdown
|
||||||
FROM threads AS t
|
FROM threads AS t
|
||||||
LEFT JOIN remarks AS r
|
LEFT JOIN remarks AS r
|
||||||
ON t.thread_id = r.thread_id
|
ON t.thread_id = r.thread_id
|
||||||
@ -255,7 +256,8 @@ sub remark_by_id($self, $remark_id) {
|
|||||||
TO_CHAR(remark_date, ?) AS date,
|
TO_CHAR(remark_date, ?) AS date,
|
||||||
remark_author AS author,
|
remark_author AS author,
|
||||||
remark_body AS body,
|
remark_body AS body,
|
||||||
thread_id
|
thread_id,
|
||||||
|
markdown_status AS markdown
|
||||||
FROM remarks
|
FROM remarks
|
||||||
WHERE remark_id = ?;
|
WHERE remark_id = ?;
|
||||||
END_SQL
|
END_SQL
|
||||||
|
@ -18,7 +18,8 @@ sub by_page_for($self, $thread_id, $this_page = 1) {
|
|||||||
SELECT remark_id AS id,
|
SELECT remark_id AS id,
|
||||||
TO_CHAR(remark_date, ?) AS date,
|
TO_CHAR(remark_date, ?) AS date,
|
||||||
remark_author AS author,
|
remark_author AS author,
|
||||||
remark_body AS body
|
remark_body AS body,
|
||||||
|
markdown_status AS markdown
|
||||||
FROM remarks
|
FROM remarks
|
||||||
WHERE thread_id = ?
|
WHERE thread_id = ?
|
||||||
AND NOT hidden_status
|
AND NOT hidden_status
|
||||||
@ -27,9 +28,25 @@ sub by_page_for($self, $thread_id, $this_page = 1) {
|
|||||||
END_SQL
|
END_SQL
|
||||||
}
|
}
|
||||||
|
|
||||||
sub create($self, $thread_id, $author, $body, $hidden = 0, $flagged = 0) {
|
sub create(
|
||||||
|
$self,
|
||||||
|
$thread_id,
|
||||||
|
$author,
|
||||||
|
$body,
|
||||||
|
$markdown //= 0,
|
||||||
|
$hidden = 0,
|
||||||
|
$flagged = 0
|
||||||
|
)
|
||||||
|
{
|
||||||
my $clean_body = $self->hr->process($body);
|
my $clean_body = $self->hr->process($body);
|
||||||
my @data = ($thread_id, $author, $clean_body, $hidden, $flagged);
|
my @data = (
|
||||||
|
$thread_id,
|
||||||
|
$author,
|
||||||
|
$clean_body,
|
||||||
|
$hidden,
|
||||||
|
$flagged,
|
||||||
|
$markdown
|
||||||
|
);
|
||||||
|
|
||||||
$self->pg->db->query(<<~'END_SQL', @data);
|
$self->pg->db->query(<<~'END_SQL', @data);
|
||||||
INSERT INTO remarks (
|
INSERT INTO remarks (
|
||||||
@ -37,9 +54,10 @@ sub create($self, $thread_id, $author, $body, $hidden = 0, $flagged = 0) {
|
|||||||
remark_author,
|
remark_author,
|
||||||
remark_body,
|
remark_body,
|
||||||
hidden_status,
|
hidden_status,
|
||||||
flagged_status
|
flagged_status,
|
||||||
|
markdown_status
|
||||||
)
|
)
|
||||||
VALUES (?, ?, ?, ?, ?);
|
VALUES (?, ?, ?, ?, ?, ?);
|
||||||
END_SQL
|
END_SQL
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,7 +87,8 @@ sub last_for($self, $thread_id) {
|
|||||||
SELECT remark_id AS id,
|
SELECT remark_id AS id,
|
||||||
TO_CHAR(remark_date, ?) AS date,
|
TO_CHAR(remark_date, ?) AS date,
|
||||||
remark_author AS author,
|
remark_author AS author,
|
||||||
remark_body AS body
|
remark_body AS body,
|
||||||
|
markdown_status AS markdown
|
||||||
FROM remarks
|
FROM remarks
|
||||||
WHERE thread_id = ?
|
WHERE thread_id = ?
|
||||||
ORDER BY remark_date
|
ORDER BY remark_date
|
||||||
@ -85,7 +104,8 @@ sub by_id($self, $remark_id) {
|
|||||||
TO_CHAR(remark_date, ?) AS date,
|
TO_CHAR(remark_date, ?) AS date,
|
||||||
remark_author AS author,
|
remark_author AS author,
|
||||||
remark_body AS body,
|
remark_body AS body,
|
||||||
thread_id
|
thread_id,
|
||||||
|
markdown_status AS markdown
|
||||||
FROM remarks
|
FROM remarks
|
||||||
WHERE remark_id = ?
|
WHERE remark_id = ?
|
||||||
AND NOT hidden_status;
|
AND NOT hidden_status;
|
||||||
@ -122,7 +142,8 @@ sub feed($self) {
|
|||||||
$self->pg->db->query(<<~'END_SQL', $date_format)->hashes;
|
$self->pg->db->query(<<~'END_SQL', $date_format)->hashes;
|
||||||
SELECT remark_id AS id,
|
SELECT remark_id AS id,
|
||||||
TO_CHAR(remark_date, ?) AS date,
|
TO_CHAR(remark_date, ?) AS date,
|
||||||
remark_body AS body
|
remark_body AS body,
|
||||||
|
markdown_status AS markdown
|
||||||
FROM remarks
|
FROM remarks
|
||||||
WHERE NOT hidden_status
|
WHERE NOT hidden_status
|
||||||
GROUP BY remark_id
|
GROUP BY remark_id
|
||||||
|
@ -8,9 +8,25 @@ has per_page => 5;
|
|||||||
|
|
||||||
has date_format => 'Dy, FMDD Mon YYYY HH24:MI:SS TZHTZM';
|
has date_format => 'Dy, FMDD Mon YYYY HH24:MI:SS TZHTZM';
|
||||||
|
|
||||||
sub create($self, $author, $title, $body, $hidden = 0, $flagged = 0) {
|
sub create(
|
||||||
|
$self,
|
||||||
|
$author,
|
||||||
|
$title,
|
||||||
|
$body,
|
||||||
|
$markdown //= 0,
|
||||||
|
$hidden = 0,
|
||||||
|
$flagged = 0
|
||||||
|
)
|
||||||
|
{
|
||||||
my $clean_body = $self->hr->process($body);
|
my $clean_body = $self->hr->process($body);
|
||||||
my @data = ($author, $title, $clean_body, $hidden, $flagged);
|
my @data = (
|
||||||
|
$author,
|
||||||
|
$title,
|
||||||
|
$clean_body,
|
||||||
|
$hidden,
|
||||||
|
$flagged,
|
||||||
|
$markdown
|
||||||
|
);
|
||||||
|
|
||||||
$self->pg->db->query(<<~'END_SQL', @data)->hash->{'thread_id'};
|
$self->pg->db->query(<<~'END_SQL', @data)->hash->{'thread_id'};
|
||||||
INSERT INTO threads (
|
INSERT INTO threads (
|
||||||
@ -18,9 +34,10 @@ sub create($self, $author, $title, $body, $hidden = 0, $flagged = 0) {
|
|||||||
thread_title,
|
thread_title,
|
||||||
thread_body,
|
thread_body,
|
||||||
hidden_status,
|
hidden_status,
|
||||||
flagged_status
|
flagged_status,
|
||||||
|
markdown_status
|
||||||
)
|
)
|
||||||
VALUES (?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?, ?)
|
||||||
RETURNING thread_id;
|
RETURNING thread_id;
|
||||||
END_SQL
|
END_SQL
|
||||||
# The indented heredoc got a little confused by this one...
|
# The indented heredoc got a little confused by this one...
|
||||||
@ -43,7 +60,8 @@ sub by_page($self, $this_page = 1) {
|
|||||||
THEN 1
|
THEN 1
|
||||||
ELSE 0
|
ELSE 0
|
||||||
END) AS remark_tally,
|
END) AS remark_tally,
|
||||||
t.bump_tally AS bump_tally
|
t.bump_tally AS bump_tally,
|
||||||
|
t.markdown_status AS markdown
|
||||||
FROM threads AS t
|
FROM threads AS t
|
||||||
LEFT JOIN remarks AS r
|
LEFT JOIN remarks AS r
|
||||||
ON t.thread_id = r.thread_id
|
ON t.thread_id = r.thread_id
|
||||||
@ -87,7 +105,8 @@ sub by_id($self, $thread_id) {
|
|||||||
t.thread_title AS title,
|
t.thread_title AS title,
|
||||||
t.thread_body AS body,
|
t.thread_body AS body,
|
||||||
COUNT(r.*) AS remark_tally,
|
COUNT(r.*) AS remark_tally,
|
||||||
t.bump_tally AS bump_tally
|
t.bump_tally AS bump_tally,
|
||||||
|
t.markdown_status AS markdown
|
||||||
FROM threads AS t
|
FROM threads AS t
|
||||||
LEFT JOIN remarks AS r
|
LEFT JOIN remarks AS r
|
||||||
ON t.thread_id = r.thread_id
|
ON t.thread_id = r.thread_id
|
||||||
@ -121,7 +140,8 @@ sub feed($self) {
|
|||||||
SELECT thread_id AS id,
|
SELECT thread_id AS id,
|
||||||
TO_CHAR(thread_date, ?) AS date,
|
TO_CHAR(thread_date, ?) AS date,
|
||||||
thread_title AS title,
|
thread_title AS title,
|
||||||
thread_body AS body
|
thread_body AS body,
|
||||||
|
markdown_status AS markdown
|
||||||
FROM threads
|
FROM threads
|
||||||
WHERE NOT hidden_status
|
WHERE NOT hidden_status
|
||||||
GROUP BY thread_id
|
GROUP BY thread_id
|
||||||
|
5
migrations/16/down.sql
Normal file
5
migrations/16/down.sql
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
ALTER TABLE threads
|
||||||
|
DROP COLUMN markdown_status;
|
||||||
|
|
||||||
|
ALTER TABLE remarks
|
||||||
|
DROP COLUMN markdown_status;
|
23
migrations/16/up.sql
Normal file
23
migrations/16/up.sql
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
ALTER TABLE threads
|
||||||
|
ADD COLUMN markdown_status BOOLEAN;
|
||||||
|
|
||||||
|
-- Since Markdown was default, set existing threads to true
|
||||||
|
UPDATE threads
|
||||||
|
SET markdown_status = TRUE;
|
||||||
|
|
||||||
|
-- Now we can make it NOT NULL
|
||||||
|
ALTER TABLE threads
|
||||||
|
ALTER COLUMN markdown_status
|
||||||
|
SET NOT NULL;
|
||||||
|
|
||||||
|
-- Do the same for remarks
|
||||||
|
|
||||||
|
ALTER TABLE remarks
|
||||||
|
ADD COLUMN markdown_status BOOLEAN;
|
||||||
|
|
||||||
|
UPDATE remarks
|
||||||
|
SET markdown_status = TRUE;
|
||||||
|
|
||||||
|
ALTER TABLE remarks
|
||||||
|
ALTER COLUMN markdown_status
|
||||||
|
SET NOT NULL;
|
@ -130,3 +130,9 @@
|
|||||||
padding: 1em;
|
padding: 1em;
|
||||||
background-color: var(--transparent);
|
background-color: var(--transparent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.plain-text {
|
||||||
|
white-space: pre-wrap;
|
||||||
|
display: inline-block;
|
||||||
|
margin: 1em 0;
|
||||||
|
}
|
||||||
|
98
t/markdown.t
Normal file
98
t/markdown.t
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
use Mojo::Base -strict;
|
||||||
|
use Test::More;
|
||||||
|
use Test::Mojo;
|
||||||
|
|
||||||
|
my $t = Test::Mojo->new('PostText');
|
||||||
|
|
||||||
|
# For CAPTCHA
|
||||||
|
my %good_captcha = (answer => 1, number => 'Ⅰ');
|
||||||
|
my $bump_thread_url =
|
||||||
|
'/captcha/H4sIAImTzmQAA8soKSmw0tfPyU9OzMnILy6xMjYwMNDPKM1NzNMvyShKTUzRTyrNLdA3BAD5ek7T%0AKQAAAA==%0A';
|
||||||
|
|
||||||
|
my %markdown_thread = (
|
||||||
|
author => 'Anonymous',
|
||||||
|
title => 'hi',
|
||||||
|
body => '# ayy... lmao',
|
||||||
|
preview => 1,
|
||||||
|
markdown => 1
|
||||||
|
);
|
||||||
|
|
||||||
|
my %markdown_remark = (
|
||||||
|
author => 'Anonymous',
|
||||||
|
body => '# ayy... lmao',
|
||||||
|
preview => 1,
|
||||||
|
markdown => 1
|
||||||
|
);
|
||||||
|
|
||||||
|
my %plain_text_thread = (
|
||||||
|
author => 'Anonymous',
|
||||||
|
title => 'hi',
|
||||||
|
body => '# ayy... lmao',
|
||||||
|
preview => 1
|
||||||
|
);
|
||||||
|
|
||||||
|
my %plain_text_remark = (
|
||||||
|
author => 'Anonymous',
|
||||||
|
body => '# ayy... lmao',
|
||||||
|
preview => 1
|
||||||
|
);
|
||||||
|
|
||||||
|
# Do CAPTCHA
|
||||||
|
$t->get_ok($bump_thread_url);
|
||||||
|
|
||||||
|
$good_captcha{'csrf_token'} =
|
||||||
|
$t->tx->res->dom->at('input[name="csrf_token"]')->val;
|
||||||
|
|
||||||
|
$t->post_ok($bump_thread_url, form => \%good_captcha)
|
||||||
|
->status_is(302)
|
||||||
|
->header_like(Location => qr{human/thread/bump/1});
|
||||||
|
|
||||||
|
subtest 'Check the form + button', sub {
|
||||||
|
$t->get_ok('/human/remark/post/1')->status_is(200)
|
||||||
|
->element_exists('input[id="markdown"]');
|
||||||
|
|
||||||
|
$t->get_ok('/human/thread/post')->status_is(200)
|
||||||
|
->element_exists('input[id="markdown"]');
|
||||||
|
};
|
||||||
|
|
||||||
|
subtest 'Submit markdown input', sub {
|
||||||
|
$t->get_ok('/human/remark/post/1');
|
||||||
|
|
||||||
|
$markdown_remark{'csrf_token'} =
|
||||||
|
$t->tx->res->dom->at('input[name="csrf_token"]')->val;
|
||||||
|
|
||||||
|
$t->post_ok('/human/remark/post/1', form => \%markdown_remark)
|
||||||
|
->status_is(200)
|
||||||
|
->text_like('div.form-preview h1', qr/ayy\.\.\. lmao/);
|
||||||
|
|
||||||
|
$t->get_ok('/human/thread/post');
|
||||||
|
|
||||||
|
$markdown_thread{'csrf_token'} =
|
||||||
|
$t->tx->res->dom->at('input[name="csrf_token"]')->val;
|
||||||
|
|
||||||
|
$t->post_ok('/human/thread/post', form => \%markdown_thread)
|
||||||
|
->status_is(200)
|
||||||
|
->text_like('div.form-preview h1', qr/ayy\.\.\. lmao/);
|
||||||
|
};
|
||||||
|
|
||||||
|
subtest 'Submit plain text input', sub {
|
||||||
|
$t->get_ok('/human/remark/post/1');
|
||||||
|
|
||||||
|
$plain_text_remark{'csrf_token'} =
|
||||||
|
$t->tx->res->dom->at('input[name="csrf_token"]')->val;
|
||||||
|
|
||||||
|
$t->post_ok('/human/remark/post/1', form => \%plain_text_remark)
|
||||||
|
->status_is(200)
|
||||||
|
->text_like('span.plain-text', qr/# ayy\.\.\. lmao/);
|
||||||
|
|
||||||
|
$t->get_ok('/human/thread/post');
|
||||||
|
|
||||||
|
$plain_text_thread{'csrf_token'} =
|
||||||
|
$t->tx->res->dom->at('input[name="csrf_token"]')->val;
|
||||||
|
|
||||||
|
$t->post_ok('/human/thread/post', form => \%plain_text_thread)
|
||||||
|
->status_is(200)
|
||||||
|
->text_like('span.plain-text', qr/# ayy\.\.\. lmao/);
|
||||||
|
};
|
||||||
|
|
||||||
|
done_testing;
|
16
t/preview.t
16
t/preview.t
@ -10,16 +10,18 @@ my $bump_thread_url =
|
|||||||
'/captcha/H4sIAImTzmQAA8soKSmw0tfPyU9OzMnILy6xMjYwMNDPKM1NzNMvyShKTUzRTyrNLdA3BAD5ek7T%0AKQAAAA==%0A';
|
'/captcha/H4sIAImTzmQAA8soKSmw0tfPyU9OzMnILy6xMjYwMNDPKM1NzNMvyShKTUzRTyrNLdA3BAD5ek7T%0AKQAAAA==%0A';
|
||||||
|
|
||||||
my %preview_thread = (
|
my %preview_thread = (
|
||||||
author => 'Anonymous',
|
author => 'Anonymous',
|
||||||
title => 'hi',
|
title => 'hi',
|
||||||
body => 'ayy... lmao',
|
body => 'ayy... lmao',
|
||||||
preview => 1
|
preview => 1,
|
||||||
|
markdown => 1
|
||||||
);
|
);
|
||||||
|
|
||||||
my %preview_remark = (
|
my %preview_remark = (
|
||||||
author => 'Anonymous',
|
author => 'Anonymous',
|
||||||
body => 'ayy... lmao',
|
body => 'ayy... lmao',
|
||||||
preview => 1
|
preview => 1,
|
||||||
|
markdown => 1
|
||||||
);
|
);
|
||||||
|
|
||||||
# Do CAPTCHA
|
# Do CAPTCHA
|
||||||
|
@ -10,7 +10,11 @@
|
|||||||
</h4>
|
</h4>
|
||||||
<h5 class="post__author"><%= $remark->{'author'} %></h5>
|
<h5 class="post__author"><%= $remark->{'author'} %></h5>
|
||||||
<div class="post__body">
|
<div class="post__body">
|
||||||
|
<% if ($remark->{'markdown'}) { =%>
|
||||||
<%== markdown $remark->{'body'} =%>
|
<%== markdown $remark->{'body'} =%>
|
||||||
|
<% } else { =%>
|
||||||
|
<span class="plain-text"><%= $remark->{'body'} %></span>
|
||||||
|
<% } =%>
|
||||||
</div>
|
</div>
|
||||||
<nav class="post__nav">
|
<nav class="post__nav">
|
||||||
<%= link_to Hide => hide_remark => {remark_id => $remark->{'id'}},
|
<%= link_to Hide => hide_remark => {remark_id => $remark->{'id'}},
|
||||||
|
@ -11,7 +11,11 @@
|
|||||||
<h4 class="post__date"><%= $thread->{'date'} %></h4>
|
<h4 class="post__date"><%= $thread->{'date'} %></h4>
|
||||||
<h5 class="post__author"><%= $thread->{'author'} %></h5>
|
<h5 class="post__author"><%= $thread->{'author'} %></h5>
|
||||||
<div class="post__body">
|
<div class="post__body">
|
||||||
|
<% if ($thread->{'markdown'}) { =%>
|
||||||
<%== markdown $thread->{'body'} =%>
|
<%== markdown $thread->{'body'} =%>
|
||||||
|
<% } else { =%>
|
||||||
|
<span class="plain-text"><%= $thread->{'body'} %></span>
|
||||||
|
<% } =%>
|
||||||
</div>
|
</div>
|
||||||
<nav class="post__nav">
|
<nav class="post__nav">
|
||||||
<%= link_to Hide => hide_thread => {thread_id => $thread->{'id'}},
|
<%= link_to Hide => hide_thread => {thread_id => $thread->{'id'}},
|
||||||
|
@ -25,7 +25,11 @@
|
|||||||
</h4>
|
</h4>
|
||||||
<h5 class="post__author"><%= $remark->{'author'} %></h5>
|
<h5 class="post__author"><%= $remark->{'author'} %></h5>
|
||||||
<div class="post__body">
|
<div class="post__body">
|
||||||
|
<% if ($remark->{'markdown'}) { =%>
|
||||||
<%== markdown $remark->{'body'} =%>
|
<%== markdown $remark->{'body'} =%>
|
||||||
|
<% } else { =%>
|
||||||
|
<span class="plain-text"><%= $remark->{'body'} %></span>
|
||||||
|
<% } =%>
|
||||||
</div>
|
</div>
|
||||||
<nav class="post__nav">
|
<nav class="post__nav">
|
||||||
<%= link_to Thread => single_thread =>
|
<%= link_to Thread => single_thread =>
|
||||||
|
@ -14,9 +14,13 @@
|
|||||||
content="Remark on thread #<%= $thread->{'id'} %>.">
|
content="Remark on thread #<%= $thread->{'id'} %>.">
|
||||||
<% end %>
|
<% end %>
|
||||||
<form method="post" class="form-body">
|
<form method="post" class="form-body">
|
||||||
<% if ($draft) { =%>
|
<% if (keys %{$draft}) { =%>
|
||||||
<div class="form-preview">
|
<div class="form-preview">
|
||||||
<%== markdown $draft =%>
|
<% if ($draft->{'markdown'}) { =%>
|
||||||
|
<%== markdown $draft->{'body'} =%>
|
||||||
|
<% } else { =%>
|
||||||
|
<span class="plain-text"><%= $draft->{'body'} =%></span>
|
||||||
|
<% } =%>
|
||||||
</div>
|
</div>
|
||||||
<% } =%>
|
<% } =%>
|
||||||
<div class="form-field">
|
<div class="form-field">
|
||||||
@ -51,6 +55,10 @@
|
|||||||
<%= check_box bump => 1, id => 'bump', checked => undef %>
|
<%= check_box bump => 1, id => 'bump', checked => undef %>
|
||||||
<%= label_for bump => 'Bump' %>
|
<%= label_for bump => 'Bump' %>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-checkbox">
|
||||||
|
<%= check_box markdown => 1, id => 'markdown' %>
|
||||||
|
<%= label_for markdown => 'Markdown' %>
|
||||||
|
</div>
|
||||||
<div class="form-checkbox">
|
<div class="form-checkbox">
|
||||||
<%= check_box preview => 1, id => 'preview' %>
|
<%= check_box preview => 1, id => 'preview' %>
|
||||||
<%= label_for preview => 'Preview' %>
|
<%= label_for preview => 'Preview' %>
|
||||||
@ -72,7 +80,11 @@
|
|||||||
</h4>
|
</h4>
|
||||||
<h5 class="post__author"><%= $last_remark->{'author'} %></h5>
|
<h5 class="post__author"><%= $last_remark->{'author'} %></h5>
|
||||||
<div class="post__body">
|
<div class="post__body">
|
||||||
|
<% if ($last_remark->{'markdown'}) { =%>
|
||||||
<%== markdown $last_remark->{'body'} =%>
|
<%== markdown $last_remark->{'body'} =%>
|
||||||
|
<% } else { =%>
|
||||||
|
<span class="plain-text"><%= $last_remark->{'body'} %></span>
|
||||||
|
<% } =%>
|
||||||
</div>
|
</div>
|
||||||
<nav class="post__nav">
|
<nav class="post__nav">
|
||||||
<%= link_to Thread => single_thread =>
|
<%= link_to Thread => single_thread =>
|
||||||
@ -98,7 +110,11 @@
|
|||||||
<h4 class="post__date"><%= $thread->{'date'} %></h4>
|
<h4 class="post__date"><%= $thread->{'date'} %></h4>
|
||||||
<h5 class="post__author"><%= $thread->{'author'} %></h5>
|
<h5 class="post__author"><%= $thread->{'author'} %></h5>
|
||||||
<div class="post__body">
|
<div class="post__body">
|
||||||
|
<% if ($thread->{'markdown'}) { =%>
|
||||||
<%== markdown $thread->{'body'} =%>
|
<%== markdown $thread->{'body'} =%>
|
||||||
|
<% } else { =%>
|
||||||
|
<span class="plain-text"><%= $thread->{'body'} %></span>
|
||||||
|
<% } =%>
|
||||||
</div>
|
</div>
|
||||||
<nav class="post__nav">
|
<nav class="post__nav">
|
||||||
<%= link_to post_remark => {thread_id => $thread->{'id'}},
|
<%= link_to post_remark => {thread_id => $thread->{'id'}},
|
||||||
|
@ -24,7 +24,11 @@
|
|||||||
<h4 class="post__date"><%= $thread->{'date'} %></h4>
|
<h4 class="post__date"><%= $thread->{'date'} %></h4>
|
||||||
<h5 class="post__author"><%= $thread->{'author'} %></h5>
|
<h5 class="post__author"><%= $thread->{'author'} %></h5>
|
||||||
<div class="post__body">
|
<div class="post__body">
|
||||||
|
<% if ($thread->{'markdown'}) { =%>
|
||||||
<%== markdown $thread->{'body'} =%>
|
<%== markdown $thread->{'body'} =%>
|
||||||
|
<% } else { =%>
|
||||||
|
<span class="plain-text"><%= $thread->{'body'} %></span>
|
||||||
|
<% } =%>
|
||||||
</div>
|
</div>
|
||||||
<nav class="post__nav">
|
<nav class="post__nav">
|
||||||
<%= link_to post_remark => {thread_id => $thread->{'id'}},
|
<%= link_to post_remark => {thread_id => $thread->{'id'}},
|
||||||
@ -55,7 +59,11 @@
|
|||||||
</h4>
|
</h4>
|
||||||
<h5 class="post__author"><%= $remark->{'author'} %></h5>
|
<h5 class="post__author"><%= $remark->{'author'} %></h5>
|
||||||
<div class="post__body">
|
<div class="post__body">
|
||||||
|
<% if ($remark->{'markdown'}) { =%>
|
||||||
<%== markdown $remark->{'body'} =%>
|
<%== markdown $remark->{'body'} =%>
|
||||||
|
<% } else { =%>
|
||||||
|
<span class="plain-text"><%= $remark->{'body'} %></span>
|
||||||
|
<% } =%>
|
||||||
</div>
|
</div>
|
||||||
<nav class="post__nav">
|
<nav class="post__nav">
|
||||||
<%= link_to Remark => post_remark =>
|
<%= link_to Remark => post_remark =>
|
||||||
|
@ -28,11 +28,19 @@
|
|||||||
<summary>
|
<summary>
|
||||||
<%= truncate_text $thread->{'body'} %>
|
<%= truncate_text $thread->{'body'} %>
|
||||||
</summary>
|
</summary>
|
||||||
|
<% if ($thread->{'markdown'}) { =%>
|
||||||
<%== markdown $thread->{'body'} =%>
|
<%== markdown $thread->{'body'} =%>
|
||||||
|
<% } else { =%>
|
||||||
|
<span class="plain-text"><%= $thread->{'body'} %></span>
|
||||||
|
<% } =%>
|
||||||
</details>
|
</details>
|
||||||
<% } else { =%>
|
<% } else { =%>
|
||||||
<div class="post__body">
|
<div class="post__body">
|
||||||
|
<% if ($thread->{'markdown'}) { =%>
|
||||||
<%== markdown $thread->{'body'} =%>
|
<%== markdown $thread->{'body'} =%>
|
||||||
|
<% } else { =%>
|
||||||
|
<span class="plain-text"><%= $thread->{'body'} %></span>
|
||||||
|
<% } =%>
|
||||||
</div>
|
</div>
|
||||||
<% } =%>
|
<% } =%>
|
||||||
<nav class="post__nav">
|
<nav class="post__nav">
|
||||||
|
@ -11,9 +11,15 @@
|
|||||||
% 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) { =%>
|
<% if (keys %{$draft}) { =%>
|
||||||
<div class="form-preview">
|
<div class="form-preview">
|
||||||
<%== markdown $draft =%>
|
<% if ($draft->{'markdown'}) { =%>
|
||||||
|
<%== markdown $draft->{'body'} =%>
|
||||||
|
<% } else { =%>
|
||||||
|
<span class="plain-text">
|
||||||
|
<%= $draft->{'body'} =%>
|
||||||
|
</span>
|
||||||
|
<% } =%>
|
||||||
</div>
|
</div>
|
||||||
<% } =%>
|
<% } =%>
|
||||||
<div class="form-field">
|
<div class="form-field">
|
||||||
@ -57,6 +63,10 @@
|
|||||||
rows => 6
|
rows => 6
|
||||||
) %>
|
) %>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-checkbox">
|
||||||
|
<%= check_box markdown => 1, id => 'markdown' %>
|
||||||
|
<%= label_for markdown => 'Markdown' %>
|
||||||
|
</div>
|
||||||
<div class="form-checkbox">
|
<div class="form-checkbox">
|
||||||
<%= check_box preview => 1, id => 'preview' %>
|
<%= check_box preview => 1, id => 'preview' %>
|
||||||
<%= label_for preview => 'Preview' %>
|
<%= label_for preview => 'Preview' %>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user