Browse Source

Adding a few new views

marches
Graham Northup 3 years ago
parent
commit
0cddb7390a
Signed by untrusted user: grissess GPG Key ID: 5D000E6F539376FB
  1. 47
      app/routes.py
  2. 17
      app/static/style.css
  3. 13
      app/templates/base.html
  4. 94
      app/templates/index.html
  5. 48
      app/templates/listing.html
  6. 21
      app/templates/macros.html
  7. 16
      app/templates/table.html

47
app/routes.py

@ -1,10 +1,10 @@
import sys
from flask import Flask, render_template, request
from flask import Flask, render_template, request, redirect
from items import get_items
from random import choice
from random import choice, sample
if sys.version_info.major < 3:
# XXX OOF
@ -32,14 +32,14 @@ def addPage():
def addContent():
bucket = request.form['bucket']
text = request.form['entry']
title = text.split('\n')[0].lower().replace(".","").replace("/","").replace(" ","_").strip()
title = text.partition('\n')[0].lower().replace(".","").replace("/","").replace(" ","_").strip()
if bucket in ["Items","Places","Characters","Spells"]:
f = open("../" + bucket + "/" + title + ".txt",'x')
f.write(text)
f.close()
return render_template('add.html')
else:
return "<h1>bruh</h1>"
return "<h1>bruh</h1><p><b>Pls no.</b></p>"
@app.route('/search', methods=['POST'])
def search():
@ -73,21 +73,30 @@ def search():
return render_template('index.html',featureType=featureType,featureText=item, searchResults=results)
@app.route('/items')
def items():
return render_template('listing.html',title="Items",items=get_items("../Items/*"))
@app.route('/places')
def places():
return render_template('listing.html',title="Places",items=get_items("../Places/*"))
@app.route('/characters')
def characters():
return render_template('listing.html',title="Characters",items=get_items("../Characters/*"))
@app.route('/spells')
def spells():
return render_template('listing.html',title="Spells",items=get_items("../Spells/*"))
def bucket_route(uri, dir, sing=None):
if sing is None:
sing = dir[:-1] # minus "s"
def render_bucket():
return render_template('listing.html', title=dir, uri=uri, items=get_items(f'../{dir}/*'))
app.add_url_rule(f'/{uri}', f'render_{uri}', render_bucket)
def random_bucket():
nm = choice(get_items(f'../{dir}/*'))[0]
return redirect(f'/{uri}#{nm}')
app.add_url_rule(f'/{uri}/random', f'random_{uri}', random_bucket)
def bucket_table(amt):
try:
return render_template('table.html', title=f'{sing} Table', items=sample(get_items(f'../{dir}/*'), amt), roll=amt)
except ValueError:
return render_template('table.html', title='you dun goofed', error="Can't construct that table (not enough items?)")
app.add_url_rule(f'/{uri}/table/<int:amt>', f'{uri}_table', bucket_table)
bucket_route('items', 'Items')
bucket_route('places', 'Places')
bucket_route('characters', 'Characters')
bucket_route('spells', 'Spells')
if __name__ == "__main__":
app.run()

17
app/templates/style.css → app/static/style.css

@ -12,6 +12,10 @@ html {
color: #fff;
}
:target {
background-color: #442;
}
h1 {
font-variant: small-caps;
font-size: 60px;
@ -60,6 +64,10 @@ ul.headlist li {
display: inline-block;
}
ul.headlist.special a {
color: #aff;
}
table,th,td {
border: 1px solid #66c;
}
@ -96,6 +104,15 @@ table.props th {
vertical-align: top;
}
table.rolls {
border-collapse: collapse;
margin: 1em auto;
}
table.rolls td, table.rolls th {
border: 1px solid #aff;
}
.freeform {
white-space: pre-wrap;
}

13
app/templates/base.html

@ -0,0 +1,13 @@
{% import "macros.html" as macros %}
<html>
<head>
<meta charset='utf-8'>
<link rel="stylesheet" type="text/css" href="/static/style.css">
<link href="https://fonts.googleapis.com/css?family=IBM+Plex+Mono|IBM+Plex+Sans|IBM+Plex+Sans+Condensed" rel="stylesheet">
<title>{% block title %}COSI D&D Archive{% endblock %}</title>
</head>
<body class="content">
<h1><a href="/">COSI D&D Archive</a></h1>
{% block content %}{% endblock %}
</body>
</html>

94
app/templates/index.html

@ -1,66 +1,34 @@
<html>
<head>
<meta charset='utf-8'>
<link rel="stylesheet" type="text/css" href="style.css">
<link href="https://fonts.googleapis.com/css?family=IBM+Plex+Mono|IBM+Plex+Sans|IBM+Plex+Sans+Condensed" rel="stylesheet">
<title>COSI D&D Archive</title>
</head>
<body class="content">
<h1>COSI D&D Archive</h1>
<form action="/search" id="searchForm" method="post">
Search Type:
<select name="type">
<option value="name">Name</option>
<option value="rarity">Rarity</option>
<option value="aura">Aura</option>
<option value="text">Text</option>
</select>
<input type="text" name="inputText" placeholder="Enter your search here">
{% extends "base.html" %}
{% block content %}
<form action="/search" id="searchForm" method="post">
Search Type:
<select name="type">
<option value="name">Name</option>
<option value="rarity">Rarity</option>
<option value="aura">Aura</option>
<option value="text">Text</option>
</select>
<input type="text" name="inputText" placeholder="Enter your search here">
<input type="submit" value="search">
</form>
<nav>
<ul>
<li><a href="/items">Items</a></li>
<li><a href="/places">Places</a></li>
<li><a href="/characters">Characters</a></li>
<li><a href="/spells">Spells</a></li>
</ul>
</nav>
<input type="submit" value="search">
</form>
<nav>
<ul>
<li><a href="/items">Items</a></li>
<li><a href="/places">Places</a></li>
<li><a href="/characters">Characters</a></li>
<li><a href="/spells">Spells</a></li>
</ul>
</nav>
{% if searchResults is defined %}
<table>
{% for (name,heads,text) in searchResults %}
<tr>
<th class="topalign" id="{{name}}">
{{name}}
<table class="props">
{% for (key, value) in heads %}
<tr><th> {{key}} </th><td> {{value}} </td></tr>
{% endfor %}
</table>
</th>
<td class="freeform monospace"> {{text}} </td>
</tr>
{% endfor %}
</table>
{% endif %}
{% if searchResults is defined %}
{{ macros.itemTable(searchResults) }}
{% endif %}
<section>
<h2>Featured {{featureType}}:</h2>
<table>
<tr>
<th class="topalign" id="{{name}}">
{{featureText[0]}}
<table class="props">
{% for (key, value) in featureText[1] %}
<tr><th> {{key}} </th><td> {{value}} </td></tr>
{% endfor %}
</table>
</th>
<td class="freeform monospace"> {{featureText[2]}} </td>
</tr>
</table>
</section>
</body>
</html>
{% if featureText is defined %}
<section>
<h2>Featured {{featureType}}:</h2>
{{ macros.itemTable([featureText]) }}
</section>
{% endif %}
{% endblock %}

48
app/templates/listing.html

@ -1,33 +1,15 @@
<html>
<head>
<meta charset='utf-8'>
<link rel="stylesheet" type="text/css" href="style.css">
<link href="https://fonts.googleapis.com/css?family=IBM+Plex+Mono|IBM+Plex+Sans|IBM+Plex+Sans+Condensed" rel="stylesheet">
<title>{{ title }} - COSI D&D Archive</title>
</head>
<body class="content">
<h1><a href="/">COSI D&D Archive</a></h1>
<h2>{{title}}</h2>
<ul class="headlist">
{% for (name,_,_) in items %}
<li><a href="#{{name}}"> {{name}} </a> {% if not loop.last %} &middot; {% endif %} </li>
{% endfor %}
</ul>
<table>
{% for (name,heads,text) in items %}
<tr>
<th class="topalign" id="{{name}}">
{{name}}
<table class="props">
{% for (key, value) in heads %}
<tr><th> {{key}} </th><td> {{value}} </td></tr>
{% endfor %}
</table>
</th>
<td class="freeform monospace"> {{text}} </td>
</tr>
{% endfor %}
</table>
<a class="topLink" href="#">Scroll to Top</a>
</body>
</html>
{% extends "base.html" %}
{% block content %}
<h2>{{title}}</h2>
<ul class="headlist special">
<li><a href="{{uri}}/random">Random</a></li>
</ul>
<ul class="headlist">
{% for (name,_,_) in items %}
<li><a href="#{{name}}"> {{name}} </a> {% if not loop.last %} &middot; {% endif %} </li>
{% endfor %}
</ul>
{{ macros.itemTable(items) }}
<a class="topLink" href="#">Scroll to Top</a>
{% endblock %}

21
app/templates/macros.html

@ -0,0 +1,21 @@
{% macro itemRow(name, heads, text) -%}
<tr>
<th class="topalign" id="{{name}}">
{{name}}
<table class="props">
{% for (key, value) in heads %}
<tr><th>{{key}}</th><td>{{value}}</td></tr>
{% endfor %}
</table>
</th>
<td class="freeform monospace">{{text}}</td>
</tr>
{%- endmacro %}
{% macro itemTable(rows) -%}
<table>
{% for (name, heads, text) in rows %}
{{ itemRow(name, heads, text) }}
{% endfor %}
</table>
{%- endmacro %}

16
app/templates/table.html

@ -0,0 +1,16 @@
{% extends "base.html" %}
{% block content %}
<h2>{{title}}</h2>
{% if error is defined %}
<div class="error">{{ error }}</div>
{% else %}
<table class="rolls">
<tr><th>d{{roll}}</th><th>Result</th></tr>
{% for (name, _, _) in items %}
<tr><td>{{ loop.index }}</td><td><a href="#{{name}}">{{name}}</a></td></tr>
{% endfor %}
</table>
{{ macros.itemTable(items) }}
{% endif %}
<a class="topLink" href="#">Scroll to Top</a>
{% endblock %}
Loading…
Cancel
Save