Rewritten for web.py
This commit is contained in:
parent
bf68826f96
commit
f33af7fe50
10 changed files with 284 additions and 294 deletions
31
app.py
Normal file
31
app.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: UTF-8 -*-
|
||||
|
||||
import web
|
||||
|
||||
render = web.template.render('views/')
|
||||
db = web.database(dbn = 'sqlite', db = 'game.db')
|
||||
|
||||
urls = (
|
||||
'/app/', 'summary',
|
||||
)
|
||||
|
||||
app = web.application(urls, globals())
|
||||
|
||||
def render_html(game_name, main_block):
|
||||
sidebar = render.sidebar()
|
||||
return render.layout(main_block, sidebar, game_name)
|
||||
|
||||
|
||||
class summary(object):
|
||||
def GET(self):
|
||||
game_name = "My Game"
|
||||
player_num = 3
|
||||
stats_num = 10
|
||||
players = ['Reset', 'Logan', 'Estela']
|
||||
|
||||
summary = render.summary(game_name, player_num, stats_num, players)
|
||||
return render_html(game_name, summary)
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run()
|
12
package.json
12
package.json
|
@ -1,12 +0,0 @@
|
|||
{
|
||||
"name": "TyeDye",
|
||||
"version": "0.0.1",
|
||||
"private": "true",
|
||||
"dependencies": {
|
||||
"express": "3.x",
|
||||
"jade": "*",
|
||||
"stylus": "*",
|
||||
"nib": "*",
|
||||
"sqlite3": "*"
|
||||
}
|
||||
}
|
|
@ -1,144 +0,0 @@
|
|||
/*
|
||||
* Import nib
|
||||
*/
|
||||
@import 'nib'
|
||||
|
||||
/*
|
||||
* Grab a custom font from Google
|
||||
*/
|
||||
@import url('http://fonts.googleapis.com/css?family=Source+Code+Pro')
|
||||
|
||||
/*
|
||||
* Nib provides a CSS reset
|
||||
*/
|
||||
global-reset()
|
||||
|
||||
/*
|
||||
* Store the main color and
|
||||
* background color as variables
|
||||
*/
|
||||
main-color = #4d5bfa
|
||||
background-color = #faf9f0
|
||||
|
||||
body
|
||||
font-family 'Arial'
|
||||
background-color background-color
|
||||
color #444
|
||||
|
||||
header
|
||||
font-family 'Source Code Pro'
|
||||
padding 50px 10px
|
||||
color #fff
|
||||
font-size 25px
|
||||
text-align center
|
||||
|
||||
/*
|
||||
* Note the use of the `main-color`
|
||||
* variable and the `darken` function
|
||||
*/
|
||||
background-color main-color
|
||||
border-bottom 1px solid darken(main-color, 30%)
|
||||
text-shadow 2px 2px 4px 2px #333
|
||||
|
||||
h2
|
||||
font-family 'Source Code Pro'
|
||||
padding 0px
|
||||
border-bottom 1px dotted #ddd
|
||||
font-family 'Source Code Pro'
|
||||
padding-bottom 10px
|
||||
border-bottom 1px dotted #ddd
|
||||
border-radius 2px 2px 0px 0px
|
||||
margin-bottom 10px
|
||||
|
||||
.container
|
||||
width 500px
|
||||
margin 50px auto
|
||||
overflow hidden
|
||||
|
||||
.main-content
|
||||
float left
|
||||
width 300px
|
||||
|
||||
p
|
||||
margin-bottom 20px
|
||||
|
||||
.sidebar
|
||||
float left
|
||||
width 200px
|
||||
|
||||
.widget
|
||||
|
||||
/*
|
||||
* Note the lack of vendor
|
||||
* prefixes here. Nib will
|
||||
* add them for us
|
||||
*/
|
||||
border-radius 3px
|
||||
border 1px solid #ccc
|
||||
margin-left 20px
|
||||
padding-bottom 10px
|
||||
background-color background-color
|
||||
box-shadow inset 0px 0px 0px 3px rgba(#fff, 0.8), 0px 3px 0px -2px rgba(#000, 0.1)
|
||||
|
||||
h1
|
||||
font-family 'Source Code Pro'
|
||||
margin 13px 10px 4px
|
||||
padding-bottom 10px
|
||||
border-bottom 1px dotted #ddd
|
||||
border-radius 2px 2px 0px 0px
|
||||
margin-bottom 10px
|
||||
|
||||
p
|
||||
font-size 13px
|
||||
padding 0px 10px
|
||||
margin-bottom 10px
|
||||
|
||||
#cssmenu
|
||||
list-style none
|
||||
margin 6px
|
||||
padding 0
|
||||
width 90%
|
||||
|
||||
ul
|
||||
width 99%
|
||||
margin 0
|
||||
|
||||
li
|
||||
margin 0
|
||||
width 99%
|
||||
|
||||
a:link
|
||||
display block
|
||||
text-decoration none
|
||||
color #000
|
||||
background-color background-color
|
||||
padding 4px 8px
|
||||
margin 0
|
||||
width 99%
|
||||
|
||||
a:visited
|
||||
display block
|
||||
text-decoration none
|
||||
color #000
|
||||
padding 4px 8px
|
||||
margin 0
|
||||
width 99%
|
||||
|
||||
a:hover
|
||||
display block
|
||||
text-decoration none
|
||||
color #fff
|
||||
background #4d5bfa
|
||||
padding 4px 8px
|
||||
margin 0
|
||||
width 99%
|
||||
|
||||
p
|
||||
line-height 1.8
|
||||
|
||||
footer
|
||||
width 500px
|
||||
margin 50px auto
|
||||
border-top 1px dotted #ccc
|
||||
padding-top 5px
|
||||
font-size 13px
|
91
server.js
91
server.js
|
@ -1,91 +0,0 @@
|
|||
/*
|
||||
* This file is part of TyeDye.
|
||||
*
|
||||
* TyeDye is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* TyeDye is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with TyeDye. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* TyeDye by Jose Carlos Cuevas Albadalejo <reset.reboot@gmail.com>
|
||||
*
|
||||
*/
|
||||
|
||||
var express = require('express')
|
||||
, stylus = require('stylus')
|
||||
, nib = require('nib')
|
||||
, sqlite = require('sqlite3');
|
||||
|
||||
var app = express();
|
||||
|
||||
var database = new sqlite.Database('/home/reset/tyedye/game.db');
|
||||
|
||||
// Custom compile function for using nib alongside stylus
|
||||
function compile(str, path) {
|
||||
return stylus(str)
|
||||
.set('filename', path)
|
||||
.use(nib());
|
||||
}
|
||||
|
||||
function render_index(player_number, stats_number, players) {
|
||||
res.render('index',
|
||||
{
|
||||
title: 'My Game',
|
||||
player_num: player_number,
|
||||
stats_num: stats_number,
|
||||
player_list: players
|
||||
});
|
||||
}
|
||||
|
||||
app.set('views', __dirname + '/views');
|
||||
app.set('view engine', 'jade');
|
||||
app.use(express.logger('dev'))
|
||||
app.use(stylus.middleware(
|
||||
{ src: __dirname + '/public',
|
||||
compile: compile
|
||||
}
|
||||
));
|
||||
|
||||
// Let express serve static files
|
||||
app.use(express.static(__dirname + '/public'));
|
||||
|
||||
// Simple test call
|
||||
// app.get('/', function (req, res) {
|
||||
// res.send('Hi there!!');
|
||||
// });
|
||||
|
||||
app.get('/', function (req, res) {
|
||||
var player_number = 0;
|
||||
var stats_number = 0;
|
||||
var players = new Array();
|
||||
|
||||
console.log('Serializing');
|
||||
database.serialize(function() {
|
||||
console.log('Querying players');
|
||||
database.each("SELECT * FROM players", function(err, row) {
|
||||
console.log('Received a player row! Weheeeee!');
|
||||
var nextElement = players.length;
|
||||
players[nextElement] = row.name;
|
||||
console.log(players);
|
||||
});
|
||||
|
||||
console.log('Statistics');
|
||||
database.get("SELECT COUNT(*) FROM players", function (err, row) {
|
||||
player_number = row;
|
||||
});
|
||||
database.get("SELECT COUNT(*) FROM stats", function (err, row) {
|
||||
stats_number = row;
|
||||
render_index(player_number, stats_number, players);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
app.listen(3000);
|
208
static/main.css
Normal file
208
static/main.css
Normal file
|
@ -0,0 +1,208 @@
|
|||
@import url("http://fonts.googleapis.com/css?family=Source+Code+Pro");
|
||||
html,
|
||||
body,
|
||||
div,
|
||||
span,
|
||||
applet,
|
||||
object,
|
||||
iframe,
|
||||
h1,
|
||||
h2,
|
||||
h3,
|
||||
h4,
|
||||
h5,
|
||||
h6,
|
||||
p,
|
||||
blockquote,
|
||||
pre,
|
||||
a,
|
||||
abbr,
|
||||
acronym,
|
||||
address,
|
||||
big,
|
||||
cite,
|
||||
code,
|
||||
del,
|
||||
dfn,
|
||||
em,
|
||||
img,
|
||||
ins,
|
||||
kbd,
|
||||
q,
|
||||
s,
|
||||
samp,
|
||||
small,
|
||||
strike,
|
||||
strong,
|
||||
sub,
|
||||
sup,
|
||||
tt,
|
||||
var,
|
||||
dl,
|
||||
dt,
|
||||
dd,
|
||||
ol,
|
||||
ul,
|
||||
li,
|
||||
fieldset,
|
||||
form,
|
||||
label,
|
||||
legend,
|
||||
table,
|
||||
caption,
|
||||
tbody,
|
||||
tfoot,
|
||||
thead,
|
||||
tr,
|
||||
th,
|
||||
td {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
outline: 0;
|
||||
font-weight: inherit;
|
||||
font-style: inherit;
|
||||
font-family: inherit;
|
||||
font-size: 100%;
|
||||
vertical-align: baseline;
|
||||
}
|
||||
body {
|
||||
line-height: 1;
|
||||
color: #000;
|
||||
background: #fff;
|
||||
}
|
||||
ol,
|
||||
ul {
|
||||
list-style: none;
|
||||
}
|
||||
table {
|
||||
border-collapse: separate;
|
||||
border-spacing: 0;
|
||||
vertical-align: middle;
|
||||
}
|
||||
caption,
|
||||
th,
|
||||
td {
|
||||
text-align: left;
|
||||
font-weight: normal;
|
||||
vertical-align: middle;
|
||||
}
|
||||
a img {
|
||||
border: none;
|
||||
}
|
||||
body {
|
||||
font-family: 'Arial';
|
||||
background-color: #faf9f0;
|
||||
color: #444;
|
||||
}
|
||||
header {
|
||||
font-family: 'Source Code Pro';
|
||||
padding: 50px 10px;
|
||||
color: #fff;
|
||||
font-size: 25px;
|
||||
text-align: center;
|
||||
background-color: #4d5bfa;
|
||||
border-bottom: 1px solid #0618df;
|
||||
text-shadow: 2px 2px 4px 2px #333;
|
||||
}
|
||||
h2 {
|
||||
font-family: 'Source Code Pro';
|
||||
padding: 0px;
|
||||
border-bottom: 1px dotted #ddd;
|
||||
font-family: 'Source Code Pro';
|
||||
padding-bottom: 10px;
|
||||
border-bottom: 1px dotted #ddd;
|
||||
-webkit-border-radius: 2px 2px 0px 0px;
|
||||
border-radius: 2px 2px 0px 0px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.container {
|
||||
width: 500px;
|
||||
margin: 50px auto;
|
||||
overflow: hidden;
|
||||
}
|
||||
.main-content {
|
||||
float: left;
|
||||
width: 300px;
|
||||
}
|
||||
.main-content p {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.sidebar {
|
||||
float: left;
|
||||
width: 200px;
|
||||
}
|
||||
.sidebar .widget {
|
||||
-webkit-border-radius: 3px;
|
||||
border-radius: 3px;
|
||||
border: 1px solid #ccc;
|
||||
margin-left: 20px;
|
||||
padding-bottom: 10px;
|
||||
background-color: #faf9f0;
|
||||
-webkit-box-shadow: inset 0px 0px 0px 3px rgba(255,255,255,0.8), 0px 3px 0px -2px rgba(0,0,0,0.1);
|
||||
box-shadow: inset 0px 0px 0px 3px rgba(255,255,255,0.8), 0px 3px 0px -2px rgba(0,0,0,0.1);
|
||||
}
|
||||
.sidebar .widget h1 {
|
||||
font-family: 'Source Code Pro';
|
||||
margin: 13px 10px 4px;
|
||||
padding-bottom: 10px;
|
||||
border-bottom: 1px dotted #ddd;
|
||||
-webkit-border-radius: 2px 2px 0px 0px;
|
||||
border-radius: 2px 2px 0px 0px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.sidebar .widget p {
|
||||
font-size: 13px;
|
||||
padding: 0px 10px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.cssmenu {
|
||||
list-style: none;
|
||||
margin: 6px;
|
||||
padding: 0;
|
||||
width: 90%;
|
||||
}
|
||||
.cssmenu ul {
|
||||
width: 99%;
|
||||
margin: 0;
|
||||
}
|
||||
.cssmenu li {
|
||||
margin: 0;
|
||||
width: 99%;
|
||||
}
|
||||
.cssmenu a:link {
|
||||
display: block;
|
||||
text-decoration: none;
|
||||
color: #000;
|
||||
background-color: #faf9f0;
|
||||
padding: 4px 8px;
|
||||
margin: 0;
|
||||
width: 99%;
|
||||
}
|
||||
.cssmenu a:visited {
|
||||
display: block;
|
||||
text-decoration: none;
|
||||
color: #000;
|
||||
padding: 4px 8px;
|
||||
margin: 0;
|
||||
width: 99%;
|
||||
}
|
||||
.cssmenu a:hover {
|
||||
display: block;
|
||||
text-decoration: none;
|
||||
color: #fff;
|
||||
background: #4d5bfa;
|
||||
padding: 4px 8px;
|
||||
margin: 0;
|
||||
width: 99%;
|
||||
}
|
||||
p {
|
||||
line-height: 1.8;
|
||||
}
|
||||
footer {
|
||||
width: 500px;
|
||||
margin: 50px auto;
|
||||
border-top: 1px dotted #ccc;
|
||||
padding-top: 5px;
|
||||
font-size: 13px;
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
extend layout
|
||||
block content
|
||||
h2 Summary
|
||||
p
|
||||
| Registered players: #{player_num}
|
||||
p
|
||||
| Stats registered: #{stats_num}
|
||||
p
|
||||
- if (player_list.length > 0)
|
||||
ul
|
||||
each player in player_list
|
||||
li #{player}
|
||||
|
||||
block sidebar
|
||||
.widget
|
||||
h1 Access
|
||||
#cssmenu
|
||||
ul
|
||||
li
|
||||
a(href='/') Main
|
||||
ul
|
||||
li
|
||||
a(href='/register') Register New Player
|
||||
ul
|
||||
li
|
||||
a(href='/remove') Remove Player
|
||||
ul
|
||||
li
|
||||
a(href='/config') Configuration
|
||||
ul
|
||||
li
|
||||
a(href='/stats') Statistics
|
25
views/layout.html
Normal file
25
views/layout.html
Normal file
|
@ -0,0 +1,25 @@
|
|||
$def with (main_block, sidebar_block, game_name)
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>TyeDye for $game_name</title>
|
||||
<link rel='stylesheet' type='text/css' href='/static/main.css'>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1>TyeDye $game_name</h1>
|
||||
</header>
|
||||
<div class='container'>
|
||||
<div class='main-content'>
|
||||
$:main_block
|
||||
</div>
|
||||
<div class='sidebar'>
|
||||
$:sidebar_block
|
||||
</div>
|
||||
</div>
|
||||
<footer>
|
||||
<p>Under GPL License v3</p>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
!!!5
|
||||
html
|
||||
head
|
||||
title TyeDye - Remote Character Server for SL
|
||||
link(rel='stylesheet', href='/stylesheets/style.css')
|
||||
body
|
||||
header
|
||||
h1 TyeDye: #{title}
|
||||
.container
|
||||
.main-content
|
||||
block content
|
||||
.sidebar
|
||||
block sidebar
|
||||
footer
|
||||
p Running on node with Express, Jade and Stylus
|
11
views/sidebar.html
Normal file
11
views/sidebar.html
Normal file
|
@ -0,0 +1,11 @@
|
|||
<div class='widget'>
|
||||
<h1>Access</h1>
|
||||
<div class="cssmenu">
|
||||
<ul class="cssmenu">
|
||||
<li class="cssmenu"><a href='/app' class="cssmenu">Main</a></li>
|
||||
<li class="cssmenu"><a href='/app/register' class="cssmenu">Register New Player</a></li>
|
||||
<li class="cssmenu"><a href='/app/config' class="cssmenu">Configuration</a></li>
|
||||
<li class="cssmenu"><a href='/app/stats' class="cssmenu">Statistics</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
9
views/summary.html
Normal file
9
views/summary.html
Normal file
|
@ -0,0 +1,9 @@
|
|||
$def with (game_name, player_num, stats_num, player_list)
|
||||
<h2>$game_name quick summary</h2>
|
||||
<p>Registered players: $player_num</p>
|
||||
<p>Registered stats: $stats_num</p>
|
||||
<p>Player list:<br />
|
||||
<ul>
|
||||
$for player in player_list:
|
||||
<li>$player</li>
|
||||
</ul>
|
Loading…
Reference in a new issue