diff --git a/compile_server/app/static/navbar-fixed-left.min.css b/compile_server/app/static/navbar-fixed-left.min.css new file mode 100644 index 0000000..94a8227 --- /dev/null +++ b/compile_server/app/static/navbar-fixed-left.min.css @@ -0,0 +1 @@ +@media (min-width:768px){.container{width:503px}}@media (min-width:992px){.container{width:723px}}@media (min-width:1200px){.container{width:923px}}@media (min-width:1432px){.container{width:1170px}}body{padding-top:70px;min-height:200vh}.navbar-fixed-left,.navbar-fixed-right{position:fixed;top:0;width:100%;z-index:1030}@media (min-width:768px) and (min-width:768px){.navbar-fixed-left,.navbar-fixed-right{width:232px;height:100vh;border-radius:0}.navbar-fixed-left .container,.navbar-fixed-right .container{padding-right:0;padding-left:0;width:auto}.navbar-fixed-left .navbar-header,.navbar-fixed-right .navbar-header{padding-left:15px;padding-right:15px}.navbar-fixed-left .navbar-collapse,.navbar-fixed-right .navbar-collapse{padding-right:0;padding-left:0;max-height:none}.navbar-fixed-left .navbar-collapse .navbar-nav,.navbar-fixed-right .navbar-collapse .navbar-nav{float:none!important}.navbar-fixed-left .navbar-collapse .navbar-nav>li,.navbar-fixed-right .navbar-collapse .navbar-nav>li{width:100%}.navbar-fixed-left .navbar-collapse .navbar-nav>li.dropdown .dropdown-menu,.navbar-fixed-right .navbar-collapse .navbar-nav>li.dropdown .dropdown-menu{top:0}.navbar-fixed-left .navbar-collapse .navbar-nav.navbar-right,.navbar-fixed-right .navbar-collapse .navbar-nav.navbar-right{margin-right:0}}@media (min-width:768px){body{padding-top:0;padding-left:232px}.navbar-fixed-left{right:auto!important;left:0!important;border-width:0 1px 0 0!important}.navbar-fixed-left .dropdown .dropdown-menu{left:100%;right:auto;border-radius:0 3px 3px 0}.navbar-fixed-left .dropdown .dropdown-toggle .caret{border-top:4px solid transparent;border-left:4px solid;border-bottom:4px solid transparent;border-right:none}} \ No newline at end of file diff --git a/compile_server/app/templates/book_base.html b/compile_server/app/templates/book_base.html index 7fb8174..9dc5088 100644 --- a/compile_server/app/templates/book_base.html +++ b/compile_server/app/templates/book_base.html @@ -6,8 +6,13 @@ Ada for the C Programmer - + + + + + + @@ -19,11 +24,11 @@ - + + - diff --git a/compile_server/app/templates/book_list.html b/compile_server/app/templates/book_list.html index 881b0fe..328b7d3 100644 --- a/compile_server/app/templates/book_list.html +++ b/compile_server/app/templates/book_list.html @@ -19,7 +19,7 @@ {% for b in books %} - + {{ b.title }} {{ b.description }} diff --git a/compile_server/app/templates/book_sidebar.html b/compile_server/app/templates/book_sidebar.html new file mode 100644 index 0000000..1f8aafd --- /dev/null +++ b/compile_server/app/templates/book_sidebar.html @@ -0,0 +1,46 @@ +{% extends 'book_base.html' %} + +{% block sidebar %} + + +
+ {% include "readerpage.html" %} +
+{% endblock%} diff --git a/compile_server/app/templates/readerpage.html b/compile_server/app/templates/readerpage.html index 799f140..60e25f6 100644 --- a/compile_server/app/templates/readerpage.html +++ b/compile_server/app/templates/readerpage.html @@ -1,72 +1,46 @@ -{% extends 'book_base.html' %} - {% load markdown_filter %} {% load rst_filter %} -{% block sidebar %} - -{% endblock%} +{% block javascript %} + +{% endblock %} {% block reader %}
- - {% if mdcontent %} - {{ mdcontent|markdownify|safe }} - {% elif rstcontent %} - {{ rstcontent|rstify|safe }} - {% endif %} +
+ + + + {% if chapter_obj.has_next %} + + {% endif %} + {% endblock%} \ No newline at end of file diff --git a/compile_server/app/views.py b/compile_server/app/views.py index 77464eb..86cca7d 100644 --- a/compile_server/app/views.py +++ b/compile_server/app/views.py @@ -11,6 +11,8 @@ import yaml from django.conf import settings from django.contrib.auth.models import User, Group +from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger + from django.views.decorators.clickjacking import xframe_options_exempt from rest_framework import viewsets, status from rest_framework.decorators import api_view @@ -117,7 +119,7 @@ def book_list(request): return render(request, 'book_list.html', booklist) -def book_router(request, subpath, part, chapter): +def book_router(request, subpath): resources_base_path = os.path.join(settings.RESOURCES_DIR, "books") matches = Book.objects.filter(subpath=subpath) @@ -143,52 +145,44 @@ def book_router(request, subpath, part, chapter): htmldata = bookdata htmldata['book_info'] = book - # store chapter and part numbers for absolute links - htmldata['sel_part'] = int(part) - htmldata['sel_chapter'] = int(chapter) - # strip chapters out of list into new list for prev, next references chapter_list = [] for p in bookdata['parts']: chapter_list.extend(p['chapters']) - # search list for current, prev, and next chapter references - val_search = "part%s-chapter%s" % (part, chapter) + paginator = Paginator(chapter_list, 1) + page = request.GET.get('page', 1) - inrange = False - for i, ch in enumerate(chapter_list): - if ch['url'] == val_search: - inrange = True - 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] - break + try: + chapter_obj = paginator.page(page) + except PageNotAnInteger: + # If page is not an integer, deliver first page. + chapter_obj = paginator.page(1) + except EmptyPage: + # If page is out of range (e.g. 9999), deliver last page of results. + chapter_obj = paginator.page(paginator.num_pages) - # load page, if part or chapter is out of range go to unknown page link - if inrange: - mdcontent_page = os.path.join(book['directory'], - "pages", - "part%s-chapter%s.md" % (part, chapter)) - rstcontent_page = os.path.join(book['directory'], - "pages", - "part%s-chapter%s.rst" % (part, chapter)) + htmldata['chapter_obj'] = chapter_obj - # check for markdown version - if os.path.isfile(mdcontent_page): - with open(mdcontent_page, 'r') as f: - htmldata['mdcontent'] = f.read() - elif os.path.isfile(rstcontent_page): - with open(rstcontent_page, 'r') as f: - htmldata['rstcontent'] = f.read() - else: - with open(os.path.join(resources_base_path, - "under-construction.md")) as f: - htmldata['mdcontent'] = f.read() + chapter = chapter_obj.object_list[0] + + mdcontent_page = os.path.join(book['directory'], + "pages", + "%s.md" % (chapter["url"])) + rstcontent_page = os.path.join(book['directory'], + "pages", + "%s.rst" % (chapter["url"])) + + # check for markdown version + if os.path.isfile(mdcontent_page): + with open(mdcontent_page, 'r') as f: + htmldata['mdcontent'] = f.read() + elif os.path.isfile(rstcontent_page): + with open(rstcontent_page, 'r') as f: + htmldata['rstcontent'] = f.read() else: with open(os.path.join(resources_base_path, - "invalid-page.md")) as f: + "under-construction.md")) as f: htmldata['mdcontent'] = f.read() - return render(request, 'readerpage.html', htmldata) + return render(request, 'book_sidebar.html', htmldata) diff --git a/compile_server/urls.py b/compile_server/urls.py index 556f620..e97afc6 100644 --- a/compile_server/urls.py +++ b/compile_server/urls.py @@ -56,7 +56,7 @@ urlpatterns = [ url(r'^examples_list/', views.examples_list), # URL router for Books - url(r'^books/(.+)/part(\d+)-chapter(\d+)', views.book_router), + url(r'^books/(.+)', views.book_router), # URL router for Book landing url(r'^books', views.book_list), diff --git a/resources/books/example/chapters.yaml b/resources/books/example/chapters.yaml index 6fa7a51..a895fa8 100644 --- a/resources/books/example/chapters.yaml +++ b/resources/books/example/chapters.yaml @@ -6,13 +6,17 @@ parts: chapters: - title: "Chapter 1" url: "part1-chapter1" + page: 1 - title: "Chapter 2" url: "part1-chapter2" + page: 2 - title: "Part 2" chapters: - title: "Chapter 1" url: "part2-chapter1" + page: 3 - title: "Chapter 2" url: "part2-chapter2" + page: 4 ... diff --git a/resources/books/example/pages/part1-chapter1.md b/resources/books/example/pages/part1-chapter1.md index 09cd88c..1a45f88 100644 --- a/resources/books/example/pages/part1-chapter1.md +++ b/resources/books/example/pages/part1-chapter1.md @@ -6,7 +6,7 @@ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam id massa felis. ### Test This is a test of inserting code blocks in the markdown -
+
Fusce molestie commodo nisi, bibendum dictum purus vehicula vel. Nulla mattis lobortis ipsum ac ornare. Integer sed erat vel mauris volutpat sodales nec auctor nulla. Aliquam ac adipiscing erat. Aliquam erat volutpat. Aenean fringilla congue odio non mattis. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Quisque porta vehicula diam, et placerat eros iaculis et. Cras nec ante ipsum, eu cursus sem. Suspendisse nec orci neque, ac egestas sapien. @@ -14,4 +14,6 @@ Pellentesque augue neque, bibendum eu elementum non, aliquam non nunc. Sed eget Mauris et eros erat, elementum iaculis velit. Donec nec quam felis, sed consequat velit. Nam dolor velit, bibendum vitae convallis id, semper sit amet diam. Integer auctor ultrices metus luctus mattis. Nulla sagittis suscipit arcu, et consequat ipsum dignissim eu. Nulla laoreet libero eget erat fermentum id porttitor odio blandit. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Nullam eget nunc eget tortor pretium sodales. Curabitur dapibus tristique lorem nec dignissim. Nullam pretium laoreet arcu ut semper. Nam ac risus et lacus auctor tempor. Curabitur bibendum, est tristique fermentum mattis, quam libero rutrum enim, at interdum dolor nisi ac nisi. Morbi ac tellus sem. In ornare vehicula risus sit amet venenatis. Pellentesque magna tellus, suscipit ac dapibus ut, rhoncus nec ante. Nullam ac purus eu massa vestibulum luctus a sed erat. -Nam lobortis aliquam scelerisque. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce auctor nisl feugiat nunc iaculis malesuada. Vestibulum neque nunc, adipiscing lacinia vehicula ut, blandit at diam. Pellentesque lobortis, justo non sollicitudin vestibulum, est tortor mattis sem, at pulvinar ante felis non ligula. Integer consequat congue adipiscing. Proin ut sodales nunc. Ut eleifend venenatis aliquam. Phasellus et viverra mauris. Quisque commodo sodales feugiat. Proin dignissim mollis quam, vel tristique velit sodales in. Aliquam egestas euismod venenatis. \ No newline at end of file +Nam lobortis aliquam scelerisque. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce auctor nisl feugiat nunc iaculis malesuada. Vestibulum neque nunc, adipiscing lacinia vehicula ut, blandit at diam. Pellentesque lobortis, justo non sollicitudin vestibulum, est tortor mattis sem, at pulvinar ante felis non ligula. Integer consequat congue adipiscing. Proin ut sodales nunc. Ut eleifend venenatis aliquam. Phasellus et viverra mauris. Quisque commodo sodales feugiat. Proin dignissim mollis quam, vel tristique velit sodales in. Aliquam egestas euismod venenatis. + +Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam id massa felis. Nam eget risus sit amet ante tempor lacinia. Mauris ut nunc sem. Cras mattis, nibh quis fermentum porttitor, arcu tortor porttitor magna, ac adipiscing quam urna at lectus. Ut at dolor in elit tempor ultrices sagittis sed lacus. Nullam a lectus mauris. Pellentesque molestie, leo in auctor semper, magna sem mattis tellus, a consectetur nisl tellus volutpat quam. Etiam ultricies risus sed sapien convallis aliquet. Curabitur vehicula purus vitae justo commodo facilisis. Quisque at porta ipsum. Sed purus leo, mattis sed ultricies ac, ultricies eget lacus. Sed ac nibh est. Suspendisse sed orci nisl. Vestibulum ultrices metus sapien, sed interdum nunc. In arcu neque, sollicitudin ut porta eu, viverra at elit. Nam accumsan condimentum metus nec accumsan. Nunc porta consectetur nisi in ornare. Vestibulum tempor mollis dui quis luctus. Aliquam dolor enim, tristique a blandit eu, auctor ut odio. \ No newline at end of file diff --git a/resources/books/example/pages/part1-chapter2.rst b/resources/books/example/pages/part1-chapter2.rst index da72513..1e37c12 100644 --- a/resources/books/example/pages/part1-chapter2.rst +++ b/resources/books/example/pages/part1-chapter2.rst @@ -10,7 +10,7 @@ This is a test of inserting code blocks in the RST .. raw:: html -
+
.. raw:: html