diff --git a/.gitignore b/.gitignore index 8d57caf..8852fcf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,6 @@ *.pyc db.sqlite3 + + +.DS_Store +.idea diff --git a/compile_server/app/checker.py b/compile_server/app/checker.py index 988ecbc..5daa9ab 100644 --- a/compile_server/app/checker.py +++ b/compile_server/app/checker.py @@ -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. diff --git a/compile_server/app/static/book_base.css b/compile_server/app/static/book_base.css new file mode 100755 index 0000000..3dc3345 --- /dev/null +++ b/compile_server/app/static/book_base.css @@ -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; + } +} diff --git a/compile_server/app/static/sidebar.js b/compile_server/app/static/sidebar.js new file mode 100644 index 0000000..841403b --- /dev/null +++ b/compile_server/app/static/sidebar.js @@ -0,0 +1,5 @@ +$(document).ready(function () { + $('#sidebarCollapse').on('click', function () { + $('#sidebar').toggleClass('active'); + }); + }); \ No newline at end of file diff --git a/compile_server/app/templates/book_base.html b/compile_server/app/templates/book_base.html new file mode 100644 index 0000000..9766f25 --- /dev/null +++ b/compile_server/app/templates/book_base.html @@ -0,0 +1,28 @@ +{% load static %} + + + + + + Ada for the C Programmer + + + + + +
+ + {% block sidebar %}{% endblock %} + {% block reader %}{% endblock %} + +
+ + + + + + + + + + diff --git a/compile_server/app/templates/book_list.html b/compile_server/app/templates/book_list.html new file mode 100644 index 0000000..f8d3306 --- /dev/null +++ b/compile_server/app/templates/book_list.html @@ -0,0 +1,31 @@ +{% load static %} + + + + + + AdaCore Books + + + + + +
+

AdaCore Books

+ + +
+ + + + + + + + + + diff --git a/compile_server/app/templates/readerpage.html b/compile_server/app/templates/readerpage.html new file mode 100644 index 0000000..246bf49 --- /dev/null +++ b/compile_server/app/templates/readerpage.html @@ -0,0 +1,59 @@ +{% extends 'book_base.html' %} +{% block sidebar %} + +{% endblock%} + +{% block reader %} + +
+ + + + {{ content|safe }} +
+{% endblock%} \ No newline at end of file diff --git a/compile_server/app/views.py b/compile_server/app/views.py index ad3832b..a94884c 100644 --- a/compile_server/app/views.py +++ b/compile_server/app/views.py @@ -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'] = "

Page Under Construction

" + + return render(request, 'readerpage.html', htmldata) diff --git a/compile_server/settings.py b/compile_server/settings.py index 93fafc6..2d755ad 100644 --- a/compile_server/settings.py +++ b/compile_server/settings.py @@ -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/ diff --git a/compile_server/urls.py b/compile_server/urls.py index 2efa43e..556f620 100644 --- a/compile_server/urls.py +++ b/compile_server/urls.py @@ -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), ] diff --git a/resources/books/Ada_For_The_C++_Java_Developer_v2/chapters.yaml b/resources/books/Ada_For_The_C++_Java_Developer_v2/chapters.yaml new file mode 100644 index 0000000..128b6ec --- /dev/null +++ b/resources/books/Ada_For_The_C++_Java_Developer_v2/chapters.yaml @@ -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" +... + diff --git a/resources/books/Ada_For_The_C_Developer/chapters.yaml b/resources/books/Ada_For_The_C_Developer/chapters.yaml new file mode 100644 index 0000000..128b6ec --- /dev/null +++ b/resources/books/Ada_For_The_C_Developer/chapters.yaml @@ -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" +... + diff --git a/resources/books/Ada_For_The_C_Developer/pages/part1-chapter1.html b/resources/books/Ada_For_The_C_Developer/pages/part1-chapter1.html new file mode 100644 index 0000000..b482272 --- /dev/null +++ b/resources/books/Ada_For_The_C_Developer/pages/part1-chapter1.html @@ -0,0 +1,34 @@ + +

Part 1 Chapter 1

+

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.

+

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.

+ +
+ +

Lorem Ipsum Dolor

+

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.

+ +
+ +

Lorem Ipsum Dolor

+

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.

+ +
+ +

Lorem Ipsum Dolor

+

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.

\ No newline at end of file diff --git a/resources/books/book_list.yaml b/resources/books/book_list.yaml new file mode 100644 index 0000000..cd85283 --- /dev/null +++ b/resources/books/book_list.yaml @@ -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" +... \ No newline at end of file