Initial structure of web app

This commit is contained in:
Noah 2014-02-18 22:30:21 -08:00
parent 426a63ea23
commit f86d1df276
13 changed files with 297 additions and 0 deletions

7
.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
# Don't check in site specific settings.
config.py
site/www/*.html
site/www/*/*
# Compiled Python
*.pyc

30
config-sample.py Normal file
View File

@ -0,0 +1,30 @@
# Sample config file for Rophako.
#
# Edit this file and save the copy as "config.py".
import os
_basedir = os.path.abspath(os.path.dirname(__file__))
DEBUG = True
# Unique name of your site, e.g. "kirsle.net"
SITE_NAME = "example.com"
# Secret key used for session cookie signing. Make this long and hard to guess.
#
# Tips for creating a strong secret key:
# $ python
# >>> import os
# >>> os.urandom(24)
# '\xfd{H\xe5<\x95\xf9\xe3\x96.5\xd1\x01O<!\xd5\xa2\xa0\x9fR"\xa1\xa8'
#
# Then take that whole quoted string and paste it right in as the secret key!
# Do NOT use that one. It was just an example! Make your own.
SECRET_KEY = 'for the love of Arceus, change this key!'
# Rophako uses a flat file JSON database system, and the Redis caching server
# sits between Ropahko and the filesystem.
REDIS_HOST = "localhost"
REDIS_PORT = 6379
REDIS_DB = 0
REDIS_PREFIX = "rophako:"

2
requirements.txt Normal file
View File

@ -0,0 +1,2 @@
flask
redis

77
rophako/__init__.py Normal file
View File

@ -0,0 +1,77 @@
__version__ = '0.01'
from flask import Flask, g, request, session, render_template, send_file
import jinja2
import os.path
import config
app = Flask(__name__)
app.DEBUG = config.DEBUG
app.SECRET_KEY = config.SECRET_KEY
# Load all the blueprints!
from rophako.modules.account import mod as AccountModule
app.register_blueprint(AccountModule)
# Custom Jinja handler to support custom- and default-template folders for
# rendering templates.
app.jinja_loader = jinja2.ChoiceLoader([
jinja2.FileSystemLoader("site/www"), # Site specific.
jinja2.FileSystemLoader("rophako/www"), # Default
])
@app.before_request
def before_request():
"""Called before all requests. Initialize global template variables."""
# Default template vars.
g.info = {
"app": {
"name": "Rophako",
"version": __version__,
"author": "Noah Petherbridge",
},
"uri": request.path.split("/")[1:],
}
@app.context_processor
def after_request():
"""Called just before render_template. Inject g.info into the template vars."""
return g.info
@app.route("/<path:path>")
def catchall(path):
"""The catch-all path handler. If it exists in the www folders, it's sent,
otherwise we give the 404 error page."""
# Search for this file.
for root in ["site/www", "rophako/www"]:
abspath = os.path.abspath("{}/{}".format(root, path))
print abspath
print abspath + ".html"
if os.path.isfile(abspath):
return send_file(abspath)
elif not "." in path and os.path.isfile(abspath + ".html"):
return render_template(path + ".html")
return not_found("404")
@app.route("/")
def index():
print "INDEX PAGE"
return catchall("index")
@app.errorhandler(404)
def not_found(error):
print "NOT FOUND"
return render_template('errors/404.html', **g.info), 404
# Domain specific endpoints.
if config.SITE_NAME == "kirsle.net":
import rophako.modules.kirsle_legacy

View File

View File

@ -0,0 +1,9 @@
# -*- coding: utf-8 -*-
from flask import Blueprint
mod = Blueprint("account", __name__, url_prefix="/account")
@mod.route("/")
def index():
return "Test"

View File

@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# Legacy endpoint compatibility from kirsle.net.
from flask import request, redirect
from rophako import app
@app.route("/+")
def google_plus():
return redirect("https://plus.google.com/+NoahPetherbridge/posts")
@app.route("/blog.html")
def legacy_blog():
post_id = request.args.get("id", "")
# All of this is TO-DO.
# friendly_id = get friendly ID
# return redirect(...)
return "TO-DO"
@app.route("/<page>.html")
def legacy_url(page):
return "/{}".format(page)

88
rophako/www/css/style.css Normal file
View File

@ -0,0 +1,88 @@
/******************************************************************************
* "Resets" - styles on HTML tags *
******************************************************************************/
body {
background-color: #FFFFFF;
font-family: "Trebuchet MS",Verdana,Arial,Helvetica,sans-serif;
font-size: small;
color: #000000;
width: 850px;
margin: 20px auto;
}
h1, h2, h3, h4 {
font-family: Verdana,Arial,Helvetica,sans-serif;
font-weight: bold;
margin: 12px 0px;
}
h1 {
font-size: 32pt;
margin-top: 0px;
}
h2 {
font-size: 28pt;
}
h3 {
font-size: 24pt;
}
h4 {
font-size: 18pt;
}
a:link, a:visited {
color: #006699;
text-decoration: underline;
}
header {
display: block;
padding: 12px;
border: 1px solid #000000;
margin-bottom: 40px;
box-shadow: 1px 1px 5px #000000;
border-radius: 12px;
}
header h1 {
font-size: 46pt;
text-align: center;
color: #0099FF;
text-shadow: 2px 2px 2px #000099;
}
nav {
float: left;
width: 200px;
border: 1px solid #000000;
border-radius: 12px;
}
nav ul {
list-style-type: none;
padding: 8px;
margin: 0px;
}
nav ul li {
padding: 2px 0px;
}
nav ul li.header {
font-weight: bold;
}
div#content {
float: right;
width: 620px;
}
div.clear {
clear: both;
}
footer {
clear: both;
margin-top: 40px;
padding: 12px;
text-align: center;
color: #707070;
border: 1px solid #000000;
border-radius: 12px;
}

View File

@ -0,0 +1,9 @@
{% extends "layout.html" %}
{% block title %}Page Not Found{% endblock %}
{% block content %}
<h1>Page Not Found</h1>
The page you requested could not be found.
{% endblock %}

9
rophako/www/index.html Normal file
View File

@ -0,0 +1,9 @@
{% extends "layout.html" %}
{% block title %}Rophako CMS{% endblock %}
{% block content %}
<h1>Welcome!</h1>
This is the Rophako CMS!
{% endblock %}

39
rophako/www/layout.html Normal file
View File

@ -0,0 +1,39 @@
<!DOCTYPE html>
<html>
<head>
<title>{% block title %}{% endblock %}</title>
<link rel="stylesheet" type="text/css" href="/css/style.css">
</head>
<body>
<header>
<h1>Rophako</h1>
</header>
<nav>
<ul>
<li class="header">:: Navigation</li>
<li><a href="/">Home</a></li>
<li><a href="#">About Rophako</a></li>
<li><a href="#">Download</a></li>
</ul>
</nav>
<div id="content">
{% block content %}{% endblock %}
</div>
<div class="clear"></div>
<footer>
&copy; 2014 Noah Petherbridge. Web design released along with the Rophako CMS
under the GNU General Public License v2.0.<br>
<a href="https://github.com/kirsle/rophako" target="_blank">
{{ app["name"] }} v{{ app["version"] }}
</a>
</footer>
</body>
</html>

4
runserver.py Normal file
View File

@ -0,0 +1,4 @@
#!/usr/bin/env python
from rophako import app
app.run(host='0.0.0.0', debug=True, port=2006)

0
site/www/.dummy Normal file
View File