mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-23 11:03:39 +00:00
Add base for full display of exercises
This commit is contained in:
@@ -9,6 +9,7 @@ var fs = require('./fs');
|
||||
// return a templeter for page
|
||||
var initTemplate = function(options) {
|
||||
var tpl = swig.compileFile(path.resolve(__dirname, '../../templates/page.html'));
|
||||
var nExercise = 1;
|
||||
|
||||
options = _.defaults(options || {}, {
|
||||
// Base folder for input
|
||||
@@ -33,19 +34,7 @@ var initTemplate = function(options) {
|
||||
|
||||
// Parse sections
|
||||
.then(function(markdown) {
|
||||
return parse.page(markdown)
|
||||
.concat([
|
||||
{
|
||||
id: 1,
|
||||
type: "exercise",
|
||||
content: "test",
|
||||
codes: {
|
||||
base: "var a = 1;",
|
||||
solution: "var a = 1; var b = 1;",
|
||||
validation: "assert(a == b);"
|
||||
}
|
||||
}
|
||||
]);
|
||||
return parse.page(markdown);
|
||||
})
|
||||
|
||||
//Calcul template
|
||||
|
||||
@@ -1,37 +1,24 @@
|
||||
<div class="header">
|
||||
<h2>Exercise #{{ section.id }}</h2>
|
||||
<h2>Exercise</h2>
|
||||
</div>
|
||||
<div class="alert alert-success hidden">
|
||||
<b>Correct!</b>
|
||||
</div>
|
||||
|
||||
<div class="alert alert-error hidden">
|
||||
<b>False!</b>
|
||||
</div>
|
||||
|
||||
<div class="message">
|
||||
{% autoescape false %}{{ section.content }}{% endautoescape %}
|
||||
</div>
|
||||
<div class="editor" style="height: {{ section.content.split("\n").length*20 }};">{{ section.codes.base }}</div>
|
||||
<div class="editor" style="height: {{ section.content.split("\n").length*20 }};">{{ section.code.base }}</div>
|
||||
|
||||
<pre class="hidden code-solution">{{ section.codes.solution }}</pre>
|
||||
<pre class="hidden code-validation">{{ section.codes.validation }}</pre>
|
||||
<pre class="hidden code-solution">{{ section.code.solution }}</pre>
|
||||
<pre class="hidden code-validation">{{ section.code.validation }}</pre>
|
||||
|
||||
<div class="btn-group btn-group-justified">
|
||||
<a href="#" class="btn btn-default action-submit">Submit</a>
|
||||
<a href="#" class="btn btn-default action-solution">Solution</a>
|
||||
<a href="https://github.com/{{ githubId }}/issues/new" target="_blank" class="btn btn-default">Have a Question?</a>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
var $exercise = $("#section-{{ section.id }}");
|
||||
|
||||
var editor = ace.edit($exercise.find(".editor").get(0));
|
||||
editor.setTheme("ace/theme/tomorrow");
|
||||
editor.getSession().setMode("ace/mode/javascript");
|
||||
|
||||
$exercise.find(".action-submit").click(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
alert("submit");
|
||||
});
|
||||
$exercise.find(".action-solution").click(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
editor.setValue($exercise.find(".code-solution").html());
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
@@ -22,4 +22,30 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$("section.exercise").each(function() {
|
||||
var $exercise = $(this);
|
||||
|
||||
var codeSolution = $exercise.find(".code-solution").html();
|
||||
var codeValidation = $exercise.find(".code-validation").html();
|
||||
|
||||
var editor = ace.edit($exercise.find(".editor").get(0));
|
||||
editor.setTheme("ace/theme/tomorrow");
|
||||
editor.getSession().setMode("ace/mode/javascript");
|
||||
|
||||
$exercise.find(".action-submit").click(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
alert("submit");
|
||||
});
|
||||
$exercise.find(".action-solution").click(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
editor.setValue(codeSolution);
|
||||
});
|
||||
})
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user