Changed how the chapter CSS is set up.

master
Pacman Ghost 3 years ago
parent f802a7b38a
commit beb63e7087
  1. 2
      asl_rulebook2/webapp/asop.py
  2. 24
      asl_rulebook2/webapp/content.py
  3. 1
      asl_rulebook2/webapp/data/ASL Rulebook.css
  4. 12
      asl_rulebook2/webapp/rule_info.py
  5. 2
      asl_rulebook2/webapp/templates/index.html
  6. 15
      asl_rulebook2/webapp/utils.py

@ -38,7 +38,7 @@ def init_asop( startup_msgs, logger ):
# load the ASOP index
fname = os.path.join( _asop_dir, "index.json" )
_asop = load_data_file( fname, "ASOP index", False, logger, startup_msgs.error )
_asop = load_data_file( fname, "ASOP index", "json", logger, startup_msgs.error )
if not _asop:
return None, None, None

@ -1,10 +1,11 @@
""" Manage the content documents. """
import os
import io
import re
from collections import defaultdict
from flask import jsonify, send_file, url_for, abort
from flask import Response, jsonify, send_file, url_for, abort
from asl_rulebook2.webapp import app
from asl_rulebook2.webapp.utils import load_data_file, slugify
@ -72,6 +73,7 @@ def load_content_sets( startup_msgs, logger ):
logger.warn( "Didn't find targets file: %s", fname )
load_file( fname_stem+".chapters", content_doc, "chapters", startup_msgs.warning )
load_file( fname_stem+".vo-notes", content_doc, "vo-notes", startup_msgs.warning )
load_file( fname_stem+".css", content_doc, "css", startup_msgs.warning, ftype="text" )
if load_file( fname_stem+".footnotes", content_doc, "footnotes", startup_msgs.warning ):
# update the footnote index
# NOTE: The front-end doesn't care about what chapter a footnote belongs to,
@ -110,12 +112,12 @@ def load_content_sets( startup_msgs, logger ):
chapter[ rtype ] = url_for( "get_chapter_resource", chapter_id=chapter_id, rtype=rtype )
return content_doc
def load_file( rel_fname, save_loc, key, on_error, binary=False ):
def load_file( rel_fname, save_loc, key, on_error, ftype="json" ):
fname = os.path.join( data_dir, rel_fname )
if not os.path.isfile( fname ):
return False
# load the specified file
data = load_data_file( fname, key, binary, logger, on_error )
data = load_data_file( fname, key, ftype, logger, on_error )
if data is None:
return False
# save the file data
@ -343,6 +345,22 @@ def get_footnotes():
# ---------------------------------------------------------------------
@app.route( "/content/css" )
def get_content_css():
"""Return the custom CSS for each content doc."""
buf = io.StringIO()
fname = os.path.join( os.path.dirname(__file__), "data/ASL Rulebook.css" )
with open( fname, "r", encoding="utf-8" ) as fp:
print( "/* ASL Rulebook */", file=buf )
print( fp.read().strip(), file=buf )
for cset in _content_sets.values():
for cdoc in cset["content_docs"].values():
if "css" in cdoc:
print( file=buf )
print( "/* {} */".format( cdoc["title"] ), file=buf )
print( cdoc["css"].strip(), file=buf )
return Response( buf.getvalue(), mimetype="text/css" )
@app.route( "/chapter/<chapter_id>/<rtype>" )
def get_chapter_resource( chapter_id, rtype ):
"""Return a chapter resource."""

@ -12,4 +12,3 @@
.chapter-o { border: 1px solid #e20000 !important ; }
.chapter-p { border: 1px solid #696a65 !important ; }
.chapter-t { border: 1px solid #eea63b !important ; }
.chapter-kgs { border: 1px solid #bed2e1 !important ; }

@ -38,7 +38,7 @@ def init_qa( startup_msgs, logger ):
def load_qa( fname ):
"""Load the Q+A entries from a data file."""
logger.info( "Loading Q+A: %s", fname )
qa_entries = load_data_file( fname, "Q+A", False, logger, startup_msgs.warning )
qa_entries = load_data_file( fname, "Q+A", "json", logger, startup_msgs.warning )
if qa_entries is None:
return
for key, entries in qa_entries.items():
@ -69,7 +69,7 @@ def init_qa( startup_msgs, logger ):
fname = os.path.join( base_dir, "fixups.json" )
if os.path.isfile( fname ):
logger.info( "Loading Q+A fixups: %s", fname )
fixups = load_data_file( fname, "fixups", False, logger, startup_msgs.warning )
fixups = load_data_file( fname, "fixups", "json", logger, startup_msgs.warning )
if fixups:
for qa_entries in qa.values():
for qa_entry in qa_entries:
@ -84,7 +84,7 @@ def init_qa( startup_msgs, logger ):
fname = os.path.join( base_dir, "sources.json" )
if os.path.isfile( fname ):
logger.info( "Loading Q+A sources: %s", fname )
sources = load_data_file( fname, "sources", False, logger, startup_msgs.warning )
sources = load_data_file( fname, "sources", "json", logger, startup_msgs.warning )
if sources:
logger.info( "- Loaded %s.", plural(len(sources),"source","sources") )
@ -162,7 +162,7 @@ def init_errata( startup_msgs, logger ):
fname = os.path.join( base_dir, "fixups.json" )
if os.path.isfile( fname ):
logger.info( "Loading errata fixups: %s", fname )
fixups = load_data_file( fname, "fixups", False, logger, startup_msgs.warning )
fixups = load_data_file( fname, "fixups", "json", logger, startup_msgs.warning )
if fixups:
for ruleid in _errata:
for anno in _errata[ruleid]:
@ -173,7 +173,7 @@ def init_errata( startup_msgs, logger ):
fname = os.path.join( base_dir, "sources.json" )
if os.path.isfile( fname ):
logger.info( "Loading errata sources: %s", fname )
sources = load_data_file( fname, "sources", False, logger, startup_msgs.warning )
sources = load_data_file( fname, "sources", "json", logger, startup_msgs.warning )
if sources:
logger.info( "- Loaded %s.", plural(len(sources),"source","sources") )
@ -190,7 +190,7 @@ def init_errata( startup_msgs, logger ):
def _load_anno( fname, atype, save_loc, logger, startup_msgs ):
"""Load annotations from a data file."""
logger.info( "Loading %s: %s", atype, fname )
anno_entries = load_data_file( fname, atype, False, logger, startup_msgs.warning )
anno_entries = load_data_file( fname, atype, "json", logger, startup_msgs.warning )
if not anno_entries:
return
for anno in anno_entries:

@ -21,7 +21,7 @@
<link rel="stylesheet" type="text/css" href="{{ url_for( 'static', filename='css/TabbedPages.css' ) }}" />
<link rel="stylesheet" type="text/css" href="{{ url_for( 'static', filename='css/Accordian.css' ) }}" />
<link rel="stylesheet" type="text/css" href="{{ url_for( 'static', filename='css/Collapsible.css' ) }}" />
<link rel="stylesheet" type="text/css" href="{{ url_for( 'static', filename='css/chapters.css' ) }}" />
<link rel="stylesheet" type="text/css" href="{{ url_for( 'get_content_css' ) }}" />
{%if ASOP_CSS_URL%}
<link rel="stylesheet" type="text/css" href="{{ASOP_CSS_URL}}" />
{%endif%}

@ -22,17 +22,22 @@ def make_config_path( path ):
"""Generate a path in the config directory."""
return os.path.join( CONFIG_DIR, path )
def load_data_file( fname, ftype, binary, logger, on_error ):
def load_data_file( fname, caption, ftype, logger, on_error ):
"""Load a data file."""
try:
# load the file
logger.debug("- Loading %s: %s", ftype, fname )
if binary:
with open( fname, mode="rb" ) as fp:
logger.debug("- Loading %s: %s", caption, fname )
if ftype == "text":
with open( fname, "r", encoding="utf-8" ) as fp:
data = fp.read()
else:
elif ftype == "json":
with open( fname, "r", encoding="utf-8" ) as fp:
data = json.load( fp )
elif ftype == "binary":
with open( fname, mode="rb" ) as fp:
data = fp.read()
else:
raise RuntimeError( "Unknown data file type: {}".format( ftype ) )
except Exception as ex: #pylint: disable=broad-except
msg = "Couldn't load \"{}\".".format( os.path.basename(fname) )
on_error( msg, str(ex) )

Loading…
Cancel
Save