Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
30a82a0
commit 4354ecb
Showing
7 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
name: hello | ||
cro: 1 | ||
id: hello | ||
entrypoint: bin/server.p6 | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
/lib/.precomp | ||
/alerts.sqlite.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use lib <lib>; | ||
use Cro::HTTP::Router; | ||
use Cro::HTTP::Server; | ||
use P6lert::Model::Alerts; | ||
|
||
my $Alerts := P6lert::Model::Alerts.new; | ||
# my $CSS := $*PROGRAM.sibling('../assets/main.css').absolute; | ||
|
||
sub MAIN (Str:D :$host = 'localhost', UInt:D :$port = 10000) { | ||
my $application = route { | ||
get -> { | ||
content 'text/html', html-render-alerts $Alerts.all | ||
} | ||
get -> 'alert', Int $id { | ||
content 'text/html', html-render-alerts $Alerts.get: $id | ||
} | ||
get -> 'main.css' { static 'static/main.css' }#$CSS } | ||
} | ||
|
||
with Cro::HTTP::Server.new: :$host, :$port, :$application { | ||
$^server.start; | ||
say "Started server http://$host:$port"; | ||
react whenever signal SIGINT { | ||
$server.stop; | ||
exit; | ||
} | ||
} | ||
} | ||
|
||
sub html-render-alerts(*@alerts) { | ||
html-layout-default '<ul id="alerts">' | ||
~ @alerts.map(-> $a { | ||
q:to/✎✎✎✎✎/; | ||
<li class="alert alert-\qq[$a.severity()]"> | ||
<p class="info"><a href="/alert/\qq[$a.id()]">#\qq[$a.id()]</a> | ||
| \qq[$a.time-human()] | ||
| posted by \qq[$a.creator()] | ||
| severity: \qq[$a.severity()] | ||
\qq[{"| affects: $a.affects()" if $a.affects}] | ||
<p>\qq[$a.alert()]</p> | ||
</li> | ||
✎✎✎✎✎ | ||
}) ~ '</ul>' | ||
} | ||
|
||
sub html-layout-default (Str:D $content) { | ||
q:to/✎✎✎✎✎/; | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<title>Perl 6 Alerts</title> | ||
<link rel="stylesheet" href="/main.css"> | ||
</head> | ||
<body> | ||
<h1>Perl 6 Alerts</h1> | ||
<div id="content"> | ||
\qq[$content] | ||
</div> | ||
<footer> | ||
<small>Code for this website is available at | ||
<a href="https://github.com/perl6/alerts">github.com/perl6/alerts</a> | ||
</footer> | ||
</body> | ||
</html> | ||
✎✎✎✎✎ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
|
||
body { | ||
margin: 10px auto; | ||
max-width: 1100px; | ||
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; | ||
} | ||
|
||
#content { | ||
padding: 10px 20px; | ||
margin-bottom: 20px; | ||
border-radius: 4px; | ||
border: 1px solid #eee; | ||
} | ||
|
||
code, kbd, pre, samp { | ||
font-family: Menlo, Monaco, Consolas, "Courier New", monospace; | ||
} | ||
|
||
h1 { | ||
font-size: 120%; | ||
font-weight: normal; | ||
} | ||
|
||
footer, footer * { | ||
color: #999; | ||
} | ||
|
||
#alerts { | ||
list-style-type: none; | ||
padding-left: 0; | ||
margin-left: 0; | ||
} |