Skip to content

Commit 3f2a08f

Browse files
Virv12edomora97
andauthored
Customizable documentation (#1300)
Allows documentation for multiple languges, when docs_path is not set the legacy stl_path variable is used mantaining retrocompatibility. Co-authored-by: Edoardo Morassutto <edoardo.morassutto@gmail.com>
1 parent 194b94d commit 3f2a08f

6 files changed

Lines changed: 27 additions & 9 deletions

File tree

cms/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ def __init__(self):
136136
self.max_submission_length = 100_000 # 100 KB
137137
self.max_input_length = 5_000_000 # 5 MB
138138
self.stl_path = "/usr/share/cppreference/doc/html/"
139+
self.docs_path = None
139140
# Prefix of 'shared-mime-info'[1] installation. It can be found
140141
# out using `pkg-config --variable=prefix shared-mime-info`, but
141142
# it's almost universally the same (i.e. '/usr') so it's hardly

cms/server/contest/handlers/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999

100100
# The following prefixes are handled by WSGI middlewares:
101101
# * /static, defined in cms/io/web_service.py
102-
# * /stl, defined in cms/server/contest/server.py
102+
# * /docs, defined in cms/server/contest/server.py
103103
]
104104

105105

cms/server/contest/handlers/main.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import ipaddress
3232
import json
3333
import logging
34+
import os.path
3435
import re
3536

3637
import collections
@@ -48,6 +49,7 @@
4849

4950
from cms import config
5051
from cms.db import PrintJob, User, Participation, Team
52+
from cms.grading.languagemanager import get_language
5153
from cms.grading.steps import COMPILATION_MESSAGES, EVALUATION_MESSAGES
5254
from cms.server import multi_contest
5355
from cms.server.contest.authentication import validate_login
@@ -367,7 +369,21 @@ class DocumentationHandler(ContestHandler):
367369
@tornado_web.authenticated
368370
@multi_contest
369371
def get(self):
372+
contest = self.r_params.get("contest")
373+
languages = [get_language(lang) for lang in contest.languages]
374+
375+
language_docs = []
376+
if config.docs_path is not None:
377+
for language in languages:
378+
ext = language.source_extensions[0][1:] # remove dot
379+
path = os.path.join(config.docs_path, ext)
380+
if os.path.exists(path):
381+
language_docs.append((language.name, ext))
382+
else:
383+
language_docs.append(("C++", "en"))
384+
370385
self.render("documentation.html",
371386
COMPILATION_MESSAGES=COMPILATION_MESSAGES,
372387
EVALUATION_MESSAGES=EVALUATION_MESSAGES,
388+
language_docs=language_docs,
373389
**self.r_params)

cms/server/contest/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def __init__(self, shard, contest_id=None):
100100
listen_address=listen_address)
101101

102102
self.wsgi_app = SharedDataMiddleware(
103-
self.wsgi_app, {"/stl": config.stl_path},
103+
self.wsgi_app, {"/docs": config.docs_path or config.stl_path},
104104
cache=True, cache_timeout=SECONDS_IN_A_YEAR,
105105
fallback_mimetype="application/octet-stream")
106106

cms/server/contest/templates/documentation.html

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ <h1>{% trans %}Documentation{% endtrans %}</h1>
1111

1212
<h2>{% trans %}Programming languages and libraries{% endtrans %}</h2>
1313

14-
{% if contest.languages|map("to_language")|map(attribute="source_extensions")|any("contains", ".cpp") %}
15-
<h3>C++</h3>
16-
17-
<p><a href="{{ url("stl", "en", "index.html") }}">{% trans %}Standard Template Library{% endtrans %}</a></p>
18-
{% endif %}
14+
{% for name, ext in language_docs %}
15+
<h3>{{name}}</h3>
16+
<p><a href="{{ url("docs", ext, "index.html") }}">{% trans %}Documentation{% endtrans %}</a></p>
17+
{% endfor %}
1918

2019
{% if contest.languages|map("to_language")|map(attribute="source_extensions")|any("contains", ".java") %}
2120
<h3>Java</h3>

config/cms.conf.sample

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,10 @@
130130
"max_submission_length": 100000,
131131
"max_input_length": 5000000,
132132

133-
"_help": "STL documentation path in the system (exposed in CWS).",
134-
"stl_path": "/usr/share/cppreference/doc/html/",
133+
"_help": "Path to the documentation exposed by CWS. To show a documentation",
134+
"_help": "link add a folder for each language with index.html inside. For",
135+
"_help": "example for C++ add 'cpp/index.html', for Java 'java/index.html'.",
136+
"docs_path": "/usr/share/cms/docs",
135137

136138

137139

0 commit comments

Comments
 (0)