Adding support for books subspace. There is now a book list in the resources directory which is used to populate the book list. Each book has a directory and a list of pages.

This commit is contained in:
Robert Tice
2017-11-21 16:21:59 -05:00
parent ba93cf9e13
commit d83f82ea92
14 changed files with 545 additions and 4 deletions

4
.gitignore vendored
View File

@@ -1,2 +1,6 @@
*.pyc
db.sqlite3
.DS_Store
.idea

View File

@@ -19,7 +19,7 @@ from compile_server.app.views import CrossDomainResponse
gnatprove_found = False
gnatemulator_found = False
ALLOW_RUNNING_PROGRAMS_EVEN_THOUGH_IT_IS_NOT_SECURE = False
ALLOW_RUNNING_PROGRAMS_EVEN_THOUGH_IT_IS_NOT_SECURE = True
# TODO: right now, executables are run through gnatemulator. We have not
# yet done the due diligence to sandbox this, though, so deactivating the
# run feature through this boolean.

View File

@@ -0,0 +1,168 @@
/*
DEMO STYLE
*/
@import "https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700";
body {
font-family: 'Poppins', sans-serif;
background: #fafafa;
}
p {
font-family: 'Poppins', sans-serif;
font-size: 1.1em;
font-weight: 300;
line-height: 1.7em;
color: #999;
}
a, a:hover, a:focus {
color: inherit;
text-decoration: none;
transition: all 0.3s;
}
.navbar {
padding: 15px 10px;
background: #fff;
border: none;
border-radius: 0;
margin-bottom: 40px;
box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.1);
}
.navbar-btn {
box-shadow: none;
outline: none !important;
border: none;
}
.line {
width: 100%;
height: 1px;
border-bottom: 1px dashed #ddd;
margin: 40px 0;
}
/* ---------------------------------------------------
SIDEBAR STYLE
----------------------------------------------------- */
.wrapper {
display: flex;
align-items: stretch;
}
#sidebar {
min-width: 250px;
max-width: 250px;
background: #7386D5;
color: #fff;
transition: all 0.3s;
}
#sidebar.active {
margin-left: -250px;
}
#sidebar .sidebar-header {
padding: 20px;
background: #6d7fcc;
}
#sidebar ul.components {
padding: 20px 0;
border-bottom: 1px solid #47748b;
}
#sidebar ul p {
color: #fff;
padding: 10px;
}
#sidebar ul li a {
padding: 10px;
font-size: 1.1em;
display: block;
}
#sidebar ul li a:hover {
color: #7386D5;
background: #fff;
}
#sidebar ul li.active > a, a[aria-expanded="true"] {
color: #fff;
background: #6d7fcc;
}
a[data-toggle="collapse"] {
position: relative;
}
a[aria-expanded="false"]::before, a[aria-expanded="true"]::before {
content: '\e259';
display: block;
position: absolute;
right: 20px;
font-family: 'Glyphicons Halflings';
font-size: 0.6em;
}
a[aria-expanded="true"]::before {
content: '\e260';
}
ul ul a {
font-size: 0.9em !important;
padding-left: 30px !important;
background: #6d7fcc;
}
ul.CTAs {
padding: 20px;
}
ul.CTAs a {
text-align: center;
font-size: 0.9em !important;
display: block;
border-radius: 5px;
margin-bottom: 5px;
}
a.download {
background: #fff;
color: #7386D5;
}
a.article, a.article:hover {
background: #6d7fcc !important;
color: #fff !important;
}
/* ---------------------------------------------------
CONTENT STYLE
----------------------------------------------------- */
#content {
padding: 20px;
min-height: 100vh;
transition: all 0.3s;
}
/* ---------------------------------------------------
MEDIAQUERIES
----------------------------------------------------- */
@media (max-width: 768px) {
#sidebar {
margin-left: -250px;
}
#sidebar.active {
margin-left: 0;
}
#sidebarCollapse span {
display: none;
}
}

View File

@@ -0,0 +1,5 @@
$(document).ready(function () {
$('#sidebarCollapse').on('click', function () {
$('#sidebar').toggleClass('active');
});
});

View File

@@ -0,0 +1,28 @@
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Ada for the C Programmer</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="{% static "style.css" %}" />
</head>
<body>
<div class="wrapper">
{% block sidebar %}{% endblock %}
{% block reader %}{% endblock %}
</div>
<script src="{% static "ace-builds/src/ace.js" %}" type="text/javascript" charset="utf-8"></script>
<script src="{% static "jquery-3.2.1.min.js" %}"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js" integrity="sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="{% static "editors.js" %}"></script>
<script src="{% static "sidebar.js" %}"></script>
</body>
</html>

View File

@@ -0,0 +1,31 @@
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>AdaCore Books</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="{% static "book_base.css" %}" />
</head>
<body>
<div class="wrapper">
<h3>AdaCore Books</h3>
<ul class="list-unstyled components">
{% for b in books %}
<li><a href="books/{{ b.url }}/part1-chapter1">{{ b.title }}</a></li>
{% endfor %}
</ul>
</div>
<script src="{% static "ace-builds/src/ace.js" %}" type="text/javascript" charset="utf-8"></script>
<script src="{% static "jquery-3.2.1.min.js" %}"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js" integrity="sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="{% static "editors.js" %}"></script>
<script src="{% static "sidebar.js" %}"></script>
</body>
</html>

View File

@@ -0,0 +1,59 @@
{% extends 'book_base.html' %}
{% block sidebar %}
<nav id="sidebar">
<ul class="list-unstyled components">
{% for p in parts %}
{% if forloop.counter == sel_part %}
<li class="active">
{% else %}
<li>
{% endif %}
<a href="#partSubmenu{{ forloop.counter }}" data-toggle="collapse" aria-expanded="false">{{ p.title }}</a>
<ul class="collapse list-unstyled" id="partSubmenu{{ forloop.counter }}">
{% for c in p.chapters %}
{% if forloop.counter == sel_chapter %}
<li class="active">
{% else %}
<li>
{% endif %}
<a href="{{ c.url }}">{{ c.title }}</a>
</li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
</nav>
{% endblock%}
{% block reader %}
<div id="content">
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" id="sidebarCollapse" class="btn btn-info navbar-btn">
<i class="glyphicon glyphicon-align-left"></i>
<span></span>
</button>
{{ sel_topic.title }}
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
{% if prev_topic %}
<li><a href="{{ prev_topic.url }}">Prev - {{ prev_topic.title }}</a></li>
{% endif %}
{% if next_topic %}
<li><a href="{{ next_topic.url }}">Next - {{ next_topic.title }}</a></li>
{% endif %}
</ul>
</div>
</div>
</nav>
{{ content|safe }}
</div>
{% endblock%}

View File

@@ -1,12 +1,15 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import json
from django.shortcuts import render
# Create your views here.
import os
import yaml
from django.conf import settings
from django.contrib.auth.models import User, Group
from django.views.decorators.clickjacking import xframe_options_exempt
from rest_framework import viewsets, status
@@ -106,3 +109,59 @@ def code_embed(request, example_name):
def examples_list(request):
context = {'examples': Example.objects.all}
return render(request, 'examples_list.html', context)
def book_list(request):
resources_base_path = os.path.join(settings.RESOURCES_DIR, "books")
with open(os.path.join(resources_base_path, "book_list.yaml"), 'r') as f:
booklist = yaml.load(f)
return render(request, 'book_list.html', booklist)
def book_router(request, book, part, chapter):
resources_base_path = os.path.join(settings.RESOURCES_DIR, "books")
book_path = os.path.join(resources_base_path, book)
if not os.path.isdir(book_path):
with open(os.path.join(resources_base_path, "book_list.yaml"), 'r') as f:
booklist = yaml.load(f)
return render(request, 'book_list.html', booklist)
path = os.path.join(book_path, "chapters.yaml")
with open(path, 'r') as f:
bookdata = yaml.load(f)
htmldata = bookdata
htmldata['sel_part'] = int(part)
htmldata['sel_chapter'] = int(chapter)
chapter_list = []
for p in bookdata['parts']:
chapter_list.extend(p['chapters'])
val_search = "part%s-chapter%s" % (part, chapter)
for i, ch in enumerate(chapter_list):
if ch['url'] == val_search:
htmldata['sel_topic'] = ch
if i != 0:
htmldata['prev_topic'] = chapter_list[i - 1]
if i != len(chapter_list) - 1:
htmldata['next_topic'] = chapter_list[i + 1]
# TODO: handle instance where part and chapter are outside of valid range
content_page = os.path.join(book_path,
"pages",
"part%s-chapter%s.html" % (part, chapter))
if os.path.isfile(content_page):
with open(content_page, 'r') as f:
htmldata['content'] = f.read()
else:
htmldata['content'] = "<h3>Page Under Construction</h3>"
return render(request, 'readerpage.html', htmldata)

View File

@@ -14,7 +14,7 @@ import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
RESOURCES_DIR = os.path.join(BASE_DIR, "resources")
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/

View File

@@ -55,6 +55,12 @@ urlpatterns = [
# Get a list of all the examples
url(r'^examples_list/', views.examples_list),
# URL router for Books
url(r'^books/(.+)/part(\d+)-chapter(\d+)', views.book_router),
# URL router for Book landing
url(r'^books', views.book_list),
# The landing page
url(r'', views.examples_list),
]

View File

@@ -0,0 +1,70 @@
---
parts:
- title: "The Basics"
chapters:
- title: "Short rationale for migrating from Ada to C"
url: "part1-chapter1"
- title: "Compilation environments, multi language builds, bare metal v.s. Embedded linux"
url: "part1-chapter2"
- title: "Preprocessor macros vs build configurations"
url: "part1-chapter3"
- title: "Introducing your first piece of Ada in an existing C application"
url: "part1-chapter4"
- title: "Overview of Ada basics (expressions, control flow, types, record, arrays)"
url: "part1-chapter5"
- title: "Structure blocks (packages, encapsulation, genericity)"
url: "part1-chapter6"
- title: "Interfacing with C"
url: "part1-chapter7"
- title: "Use case #1 mathematical computations with physical dimension checking"
url: "part1-chapter8"
- title: "The Low-Level"
chapters:
- title: "Inline Assembly"
url: "part2-chapter1"
- title: "Bit masks"
url: "part2-chapter2"
- title: "Number wrap around"
url: "part2-chapter3"
- title: "Register overlays"
url: "part2-chapter4"
- title: "Memory mapped communication"
url: "part2-chapter5"
- title: "Streams"
url: "part2-chapter6"
- title: "Endianness"
url: "part2-chapter7"
- title: "The run-times (boot loader, BSP…)"
url: "part2-chapter8"
- title: "Ravenscar tasking"
url: "part2-chapter9"
- title: "ARM environment (svd2ada)"
url: "part2-chapter10"
- title: "Use case #2 [???]"
url: "part2-chapter11"
- title: "Typical Algorithms"
chapters:
- title: "List searches"
url: "part3-chapter1"
- title: "Switch debounce"
url: "part3-chapter2"
- title: "Lookup tables"
url: "part3-chapter3"
- title: "Large number support"
url: "part3-chapter4"
- title: "Use case #3 [???]"
url: "part3-chapter5"
- title: "Verifiable Programming"
chapters:
- title: "Using SPARK subset (Stone)"
url: "part4-chapter1"
- title: "Proving data flow (Bronze)"
url: "part4-chapter2"
- title: "Installing more provers and proving Absence of Run-Time Errors (Silver)"
url: "part4-chapter3"
- title: "Specifying and verifying defensive code (Gold)"
url: "part4-chapter4"
- title: "Use case #4 The crazyflies"
url: "part4-chapter5"
...

View File

@@ -0,0 +1,70 @@
---
parts:
- title: "The Basics"
chapters:
- title: "Short rationale for migrating from Ada to C"
url: "part1-chapter1"
- title: "Compilation environments, multi language builds, bare metal v.s. Embedded linux"
url: "part1-chapter2"
- title: "Preprocessor macros vs build configurations"
url: "part1-chapter3"
- title: "Introducing your first piece of Ada in an existing C application"
url: "part1-chapter4"
- title: "Overview of Ada basics (expressions, control flow, types, record, arrays)"
url: "part1-chapter5"
- title: "Structure blocks (packages, encapsulation, genericity)"
url: "part1-chapter6"
- title: "Interfacing with C"
url: "part1-chapter7"
- title: "Use case #1 mathematical computations with physical dimension checking"
url: "part1-chapter8"
- title: "The Low-Level"
chapters:
- title: "Inline Assembly"
url: "part2-chapter1"
- title: "Bit masks"
url: "part2-chapter2"
- title: "Number wrap around"
url: "part2-chapter3"
- title: "Register overlays"
url: "part2-chapter4"
- title: "Memory mapped communication"
url: "part2-chapter5"
- title: "Streams"
url: "part2-chapter6"
- title: "Endianness"
url: "part2-chapter7"
- title: "The run-times (boot loader, BSP…)"
url: "part2-chapter8"
- title: "Ravenscar tasking"
url: "part2-chapter9"
- title: "ARM environment (svd2ada)"
url: "part2-chapter10"
- title: "Use case #2 [???]"
url: "part2-chapter11"
- title: "Typical Algorithms"
chapters:
- title: "List searches"
url: "part3-chapter1"
- title: "Switch debounce"
url: "part3-chapter2"
- title: "Lookup tables"
url: "part3-chapter3"
- title: "Large number support"
url: "part3-chapter4"
- title: "Use case #3 [???]"
url: "part3-chapter5"
- title: "Verifiable Programming"
chapters:
- title: "Using SPARK subset (Stone)"
url: "part4-chapter1"
- title: "Proving data flow (Bronze)"
url: "part4-chapter2"
- title: "Installing more provers and proving Absence of Run-Time Errors (Silver)"
url: "part4-chapter3"
- title: "Specifying and verifying defensive code (Gold)"
url: "part4-chapter4"
- title: "Use case #4 The crazyflies"
url: "part4-chapter5"
...

View File

@@ -0,0 +1,34 @@
<h2>Part 1 Chapter 1</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur
sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur
sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<div class="line"></div>
<h2>Lorem Ipsum Dolor</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur
sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<div class="line"></div>
<h2>Lorem Ipsum Dolor</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur
sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<div class="line"></div>
<h3>Lorem Ipsum Dolor</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur
sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>

View File

@@ -0,0 +1,7 @@
---
books:
- title: "Ada For The C Developer"
url: "Ada_For_The_C_Developer"
- title: "Ada For the C++ Java Developer v2"
url: "Ada_For_The_C++_Java_Developer_v2"
...