diff --git a/.gitignore b/.gitignore index bacd1f0..192a733 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,6 @@ .eggs env/* __pycache__ -site \ No newline at end of file +site +examples/*.html + diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..e1878bd --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.pythonPath": "c:\\Users\\dang\\Documents\\GitHub\\MarkdownMark\\env\\Scripts\\python.exe" +} \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 6db0fc0..6303bfe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.3.2 + + - Entry point script uses the generic template (feedback.jinja2) by default + # 0.3.1 - Software diff --git a/remarkable/scripts/runDMC.py b/remarkable/scripts/runDMC.py index 317c19a..1edec37 100644 --- a/remarkable/scripts/runDMC.py +++ b/remarkable/scripts/runDMC.py @@ -57,7 +57,8 @@ def main(): help="File to Convert") parser.add_argument("-t", "--template", - help="Template file to use for rendering") + default="feedback.jinja2", + help="Template file to use for rendering. Will default to generic marking template (feedback.jinja2)") parser.add_argument("-d", "--templatedir", help="Local template directory") diff --git a/remarkable/templates/feedback.jinja2 b/remarkable/templates/feedback.jinja2 index cad7e84..40e81a2 100644 --- a/remarkable/templates/feedback.jinja2 +++ b/remarkable/templates/feedback.jinja2 @@ -1,11 +1,12 @@ {% extends "base/bootstrap.jinja2" %} {% block content %} - +{# -------------------- Header Section ------------------------ #}
{% if header %}
-
+
+
Module:

{% if header.mod_code %} {{ header.mod_code }} : @@ -15,17 +16,23 @@

+{% if header.cw %}
+
Cousework Title:

{{ header.cw }}

+{% endif %} +{% if header.sid or header.student %}
+
Student:

{{ header.sid }} {{ header.student }}

+{% endif %} {% else %}
@@ -38,18 +45,23 @@ {% endif %} - {% for item in order %} -
-
-

{{content[item].header}}

- {{ content[item] }} -
-
-

{{ content[item].getMarks() }}

-

-
- {% endfor %} - + {# -------------------- Content Section ------------------------ #} +
+
+ {% for item in order %} +
+

+ {{ content[item].header}} + {{ content[item].getMarks() }} +

+
+ {{ content[item] }} +
+
+ {% endfor %} +
+
+ {% if calcs.marksAwarded %}
diff --git a/setup.py b/setup.py index 1205627..8313ee9 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,3 @@ -import os - from setuptools import setup, find_packages requires = [ @@ -20,16 +18,16 @@ setup( name="remarkable", author="Dan Goldsmith", author_email="djgoldsmith@googlemail.com", - version="0.3.1", + version="0.3.2", #Dependencies install_requires=requires, tests_require=testRequires, #Load the Library packages=find_packages(), - package_data = {"remarkable": ["templates/"]}, + package_data={"remarkable": ["templates"]}, #And scripts - entry_points = { + entry_points={ "console_scripts":[ "DMC = remarkable.scripts.runDMC:main", "runDMC = remarkable.scripts.runDMC:main", @@ -37,5 +35,3 @@ setup( ] } ) - - diff --git a/test/test_controller.py b/test/test_controller.py index 8209907..de181ce 100644 --- a/test/test_controller.py +++ b/test/test_controller.py @@ -4,6 +4,8 @@ Testing for the Main Methods and Script Functions import unittest import os +import tempfile + import jinja2 import remarkable.controller as controller @@ -18,13 +20,16 @@ class ControllerTest(unittest.TestCase): ```convertFile(inputFile, templateFile = None, templateDir=None, outputFile = None):``` """ + @classmethod + def setUpClass(cls): + """Setup the temp directory to hold any generated files""" + + cls.tmpdir = tempfile.TemporaryDirectory() + def tearDown(self): """ Called before all tests, make sure the tmp directory is clean """ - if os.path.exists("/tmp/render.html"): - os.remove("/tmp/render.html") - #And if we dont sepcify a file if os.path.exists("inputController.html"): os.remove("inputController.html") @@ -32,10 +37,12 @@ class ControllerTest(unittest.TestCase): def testConvertAll(self): """ Convert with all parameters supplied """ + outFile = os.path.join(self.tmpdir.name, "render.html") + controller.convertFile("test/inputs/inputController.md", "controller.jinja2", "test/templates", - outputFile="/tmp/render.html") + outputFile=outFile) self._checkOutput() @@ -47,10 +54,12 @@ class ControllerTest(unittest.TestCase): we look in the file header for a ```template:``` and use that """ + outFile = os.path.join(self.tmpdir.name, "render.html") + controller.convertFile("test/inputs/inputController.md", templateFile=None, templateDir="test/templates", - outputFile="/tmp/render.html") + outputFile=outFile) self._checkOutput() def testNoOutput(self): @@ -102,7 +111,7 @@ class ControllerTest(unittest.TestCase): templateFile="missing.jinja") - def _checkOutput(self, outFile="/tmp/render.html"): + def _checkOutput(self, outFile=None): """ Helper function to check the output @@ -114,6 +123,9 @@ class ControllerTest(unittest.TestCase):

Some Input from a markdown file

""" + if not outFile: + outFile = os.path.join(self.tmpdir.name, "render.html") + fd = open(outFile, "r") out = fd.read() fd.close() diff --git a/test/test_markdown.py b/test/test_markdown.py index 79c32c5..1b9cecd 100644 --- a/test/test_markdown.py +++ b/test/test_markdown.py @@ -7,16 +7,13 @@ I just ran down https://www.markdownguide.org/basic-syntax/ import unittest import os +import tempfile import bs4 import remarkable.parser as parser import remarkable.renderer as renderer - - -OUTFILE = "/tmp/syntaxtest.html" - class markdownTest(unittest.TestCase): """ Test cases for markdown rendering. @@ -30,19 +27,19 @@ class markdownTest(unittest.TestCase): """ Keep the parser and input file consistent """ + tmpdir = tempfile.TemporaryDirectory() + cls.outfile = os.path.join(tmpdir.name, "syntaxtest.html") + print ("Create temproary file {0}".format(cls.outfile)) + cls.theParser = parser.MarkdownParser("test/inputs/markdownSyntax.md") cls.theParser.parseFile() cls.theRenderer = renderer.HTMLRenderer("syntax.jinja2", "test/templates") - cls.theRenderer.toFile(cls.theParser, OUTFILE) + cls.theRenderer.toFile(cls.theParser, cls.outfile) #And Beautiful soup version - with open(OUTFILE, "r") as fd: + with open(cls.outfile, "r") as fd: cls.soup = bs4.BeautifulSoup(fd, features="html.parser") - @classmethod - def tearDownClass(cls): - if os.path.exists(OUTFILE): - os.remove(OUTFILE) def cleanBS(self, theInput): """ diff --git a/test/test_render.py b/test/test_render.py index 4701672..db7fb32 100644 --- a/test/test_render.py +++ b/test/test_render.py @@ -1,4 +1,6 @@ import unittest +import os +import tempfile import jinja2 @@ -13,6 +15,12 @@ class renderTest(unittest.TestCase): However, if things start failing its something to eyeball """ + @classmethod + def setUpClass(cls): + """Setup the temp directory to hold any generated files""" + + cls.tmpdir = tempfile.TemporaryDirectory() + def setUp(self): """ Parse the file and get the rendered output. @@ -236,7 +244,8 @@ For example new lines.

#And Renderer theRenderer = renderer.HTMLRenderer("testingMD.jinja2", "test/templates") - out = theRenderer.toFile(theParser, "/tmp/testout.html") + filename = os.path.join(self.tmpdir.name, "testout.html") + out = theRenderer.toFile(theParser, filename) expected = """

Introduction

10 @@ -265,7 +274,7 @@ For example new lines.

And More Spacing to be dealt with

""" - fd = open("/tmp/testout.html", "r") + fd = open(filename, "r") out = fd.read() fd.close()