Introduced Exercitia
This commit is contained in:
parent
72b9a5dbc0
commit
6c0adcb745
@ -3,7 +3,9 @@ from flask import render_template, jsonify
|
||||
import os
|
||||
|
||||
capitula = [
|
||||
{'title': '01 Imperium Romanum'},
|
||||
{'title': '01 Imperium Romanum',
|
||||
'pensa': ['A', 'B'],
|
||||
'exercitia': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]},
|
||||
{'title': '02 Familia Romana'},
|
||||
{'title': '03 Puer Improbus'},
|
||||
{'title': '04 Dominus et Servi'},
|
||||
@ -24,8 +26,14 @@ for capitulum in capitula:
|
||||
def llpsi():
|
||||
return render_template('index.html', capitula=capitula)
|
||||
|
||||
@app.route('/llpsi/<path:pensum_id>')
|
||||
@app.route('/llpsi/pensum/<path:pensum_id>')
|
||||
def pensum(pensum_id):
|
||||
filename = app.root_path + '/templates/Pensa/' + pensum_id + '.html'
|
||||
with open(filename, 'r') as file:
|
||||
return render_template('Pensum_cloze.html', pensum_title=pensum_id.replace('_', ' '), pensum_content=file.read())
|
||||
|
||||
@app.route('/llpsi/pensum/<path:exercitium_id>')
|
||||
def exercitium(exercitium_id):
|
||||
filename = app.root_path + '/templates/Exercitia/' + exercitium_id + '.html'
|
||||
with open(filename, 'r') as file:
|
||||
return render_template('Exercitium_choice.html', exercitium_title=exercitium_id.replace('_', ' '), exercitium_content=file.read())
|
||||
|
5
app/templates/Exercitia/01_Imperium_Romanum_Exercitium_1
Normal file
5
app/templates/Exercitia/01_Imperium_Romanum_Exercitium_1
Normal file
@ -0,0 +1,5 @@
|
||||
est|sunt
|
||||
Italia in Eurōpā _est_.
|
||||
Gallia in Eurōpā _est_.
|
||||
Italia et Gallia in Eurōpā _sunt_.
|
||||
Arabia in Eurōpā nōn _est_.
|
109
app/templates/Exercitium_choice.html
Normal file
109
app/templates/Exercitium_choice.html
Normal file
@ -0,0 +1,109 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="la">
|
||||
<head>
|
||||
<meta charset="UTF-8"/>
|
||||
<title>{{pensum_title}}</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
||||
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/LLPSI.css') }}">
|
||||
<script type="text/javascript">
|
||||
function adjust_size() {
|
||||
const pensum = document.querySelector('#pensum_content');
|
||||
const inputs = pensum.querySelectorAll('input');
|
||||
inputs.forEach((input) => {
|
||||
if (input.type=="text") {
|
||||
input.setAttribute("value", "");
|
||||
input.setAttribute("style", "width: " + input.dataset.expected.length + "em");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function nomacron_to_macron(char) {
|
||||
var mapper = { 'A': 'Ā',
|
||||
'a': 'ā',
|
||||
'E': 'Ē',
|
||||
'e': 'ē',
|
||||
'I': 'Ī',
|
||||
'i': 'ī',
|
||||
'O': 'Ō',
|
||||
'o': 'ō',
|
||||
'U': 'Ū',
|
||||
'u': 'ū'};
|
||||
return mapper[char[0]];
|
||||
}
|
||||
|
||||
function macron_to_nomacron(char) {
|
||||
var mapper = { 'Ā': 'A',
|
||||
'ā': 'a',
|
||||
'Ē': 'E',
|
||||
'ē': 'e',
|
||||
'Ī': 'I',
|
||||
'ī': 'i',
|
||||
'Ō': 'O',
|
||||
'ō': 'o',
|
||||
'Ū': 'U',
|
||||
'ū': 'u'};
|
||||
return mapper[char];
|
||||
}
|
||||
|
||||
function to_nonmacron(input) {
|
||||
return input.replace(/Ā|ā|Ē|ē|Ī|ī/, macron_to_nomacron);
|
||||
}
|
||||
|
||||
function to_macron(input) {
|
||||
return input.replace(/(\w)\1/, nomacron_to_macron);
|
||||
}
|
||||
|
||||
|
||||
function validate() {
|
||||
const pensum = document.querySelector('#pensum_content');
|
||||
const inputs = pensum.querySelectorAll('input');
|
||||
|
||||
inputs.forEach((input) => {
|
||||
if (input.type == "text") {
|
||||
is_nonmacron_ok = false;
|
||||
is_macron_ok = false;
|
||||
if (document.getElementById('vowel_length').checked == false) {
|
||||
is_nonmacron_ok = (to_nonmacron(input.value) == to_nonmacron(input.dataset.expected));
|
||||
} else {
|
||||
is_macron_ok = (input.value == input.dataset.expected);
|
||||
}
|
||||
if (is_nonmacron_ok || is_macron_ok) {
|
||||
input.setAttribute("class", "correct");
|
||||
} else {
|
||||
input.setAttribute("class", "incorrect");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function show_answers() {
|
||||
const pensum = document.querySelector('#pensum_content');
|
||||
const inputs = pensum.querySelectorAll('input');
|
||||
|
||||
inputs.forEach((input) => {
|
||||
if (input.type=="text") {
|
||||
input.value = input.dataset.expected;
|
||||
input.removeAttribute("class");
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1><a href="/llpsi">Lingua Latīna Per Sē Illūstrāta</a></h1>
|
||||
<h2>{{pensum_title}}</h2>
|
||||
<label class="toggle">
|
||||
Quantitās: <input type="checkbox" id="vowel_length">
|
||||
</label>
|
||||
</header>
|
||||
<div id="pensum_content">
|
||||
<p>{{pensum_content|safe}}</p>
|
||||
<br>
|
||||
<button title="Check answers" onclick="return validate();">Mitte</button><button title="Show correct answers" onclick="return show_answers();">Responsa</button>
|
||||
</div>
|
||||
<script type="text/javascript">adjust_size();</script>
|
||||
</body>
|
||||
</html>
|
@ -11,8 +11,11 @@
|
||||
<dl>
|
||||
{% for capitulum in capitula %}
|
||||
<dt>{{capitulum.title}}
|
||||
<dd><a href="/llpsi/{{capitulum.filename}}_Pensum_A">Pensum A</a></dd>
|
||||
<dd><a href="/llpsi/{{capitulum.filename}}_Pensum_B">Pensum B</a></dd>
|
||||
<dd><a href="/llpsi/pensum/{{capitulum.filename}}_Pensum_A">Pensum A</a></dd>
|
||||
<dd><a href="/llpsi/pensum/{{capitulum.filename}}_Pensum_B">Pensum B</a></dd>
|
||||
{% for exercitium in capitulum.exercitia %}
|
||||
<dd><a href="/llpsi/exercitium/{{capitulum.filename}}_Exercitium_{{exercitium}}">Exercitium {{exercitium}}</a></dd>
|
||||
{% endfor %}
|
||||
</dt>
|
||||
{% endfor %}
|
||||
</dl>
|
||||
|
31
text2exercitium.py
Normal file
31
text2exercitium.py
Normal file
@ -0,0 +1,31 @@
|
||||
import sys
|
||||
import re
|
||||
|
||||
for filename in sys.argv[1:]:
|
||||
with open(filename, 'r') as infile:
|
||||
content = infile.readlines()
|
||||
|
||||
|
||||
to_use = content.pop(0).split('|')
|
||||
html_header = 'To use: ' + to_use.str() + '<br>'
|
||||
# Replace _string_ with html
|
||||
html_span_head = '<span>'
|
||||
html_input_head = '<input type="text" data-expected="'
|
||||
html_input_tail = '"/>'
|
||||
html_span_tail = '</span>'
|
||||
content = re.sub(r'(\s|\"|)([a-zA-Z\-\ÿ]+|)_([āēīōūa-zA-Z\-]+)_(\.|\,|)', r'\1' + html_span_head + r'\2' + html_input_head + r'\3' + html_input_tail + r'\4' + html_span_tail, content)
|
||||
|
||||
# Replace vowel-dash-vowel with vowels with macrons
|
||||
content = content.replace('A-A', 'Ā')
|
||||
content = content.replace('a-a', 'ā')
|
||||
content = content.replace('E-E', 'Ē')
|
||||
content = content.replace('e-e', 'ē')
|
||||
content = content.replace('I-I', 'Ī')
|
||||
content = content.replace('i-i', 'ī')
|
||||
content = content.replace('O-O', 'Ō')
|
||||
content = content.replace('o-o', 'ō')
|
||||
content = content.replace('U-U', 'Ū')
|
||||
content = content.replace('u-u', 'ū')
|
||||
|
||||
with open(filename + '.html', 'w') as outfile:
|
||||
outfile.write(content)
|
Loading…
Reference in New Issue
Block a user