Browse Source

Unify sections with monsters and items

master
Graham Northup 3 years ago
parent
commit
cf6a92a1f2
Signed by untrusted user: grissess GPG Key ID: 5D000E6F539376FB
  1. 26
      app/items.py
  2. 13
      app/templates/macros.html

26
app/items.py

@ -15,6 +15,27 @@ def parse_headers(spell_text):
lines = lines[1:]
return heads, '\n'.join(lines) # Should be empty, but :shrug:
def parse_sections(body):
lines = body.split('\n')
cur_sec = None
cur_lines = []
secs = {}
skipping_leader = False
for lidx in range(len(lines) - 1):
if skipping_leader:
skipping_leader = False
continue
if lines[lidx + 1].startswith('---') or lines[lidx + 1].startswith('==='):
secs[cur_sec] = '\n'.join(cur_lines)
cur_lines = []
cur_sec = lines[lidx]
skipping_leader = True
else:
cur_lines.append(lines[lidx])
cur_lines.append(lines[-1])
secs[cur_sec] = '\n'.join(cur_lines)
return secs
def test_spell_parse():
f = open("../Spells/deceptive_sending.txt",'r')
text = '\n'.join(f.read().split("\n")[2:])
@ -30,9 +51,10 @@ def get_items(items_dir):
lines = lines[1:]
while not (set(lines[0]) - set('-')):
lines = lines[1:]
heads, body= parse_headers('\n'.join(lines))
heads, body = parse_headers('\n'.join(lines))
secs = parse_sections(body)
items_list.append((title,heads,body))
items_list.append((title,heads,secs))
items_list.sort(key = lambda data: data[0])
return items_list

13
app/templates/macros.html

@ -1,4 +1,4 @@
{% macro itemRow(name, heads, text) -%}
{% macro itemRow(name, heads, secs) -%}
<tr>
<th class="topalign" id="{{name}}">
{{name}}
@ -8,14 +8,19 @@
{% endfor %}
</table>
</th>
<td class="freeform monospace">{{text}}</td>
<td class="monospace">
{% for (name, body) in secs.items() %}
{% if name %}<h4>{{ name }}</h4>{% endif %}
<span class="freeform">{{ body }}</span>
{% endfor %}
</td>
</tr>
{%- endmacro %}
{% macro itemTable(rows) -%}
<table>
{% for (name, heads, text) in rows %}
{{ itemRow(name, heads, text) }}
{% for (name, heads, secs) in rows %}
{{ itemRow(name, heads, secs) }}
{% endfor %}
</table>
{%- endmacro %}

Loading…
Cancel
Save