diff --git a/.gitignore b/.gitignore
index c8f7987..912a858 100644
--- a/.gitignore
+++ b/.gitignore
@@ -119,3 +119,6 @@ dmypy.json
.vscode/
*~
+# onpoint-specific
+test/slides.*.html
+
diff --git a/README.md b/README.md
index fea9a37..599cb8c 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,9 @@
# onpoint
+## installation
+
+### requirements
+
+* pypandoc (from pip)
+ * needs pandoc
+
diff --git a/onpoint/__init__.py b/onpoint/__init__.py
index edc180c..e9cff5b 100644
--- a/onpoint/__init__.py
+++ b/onpoint/__init__.py
@@ -1 +1,95 @@
# Our python script goes here.
+
+import yaml
+import pypandoc
+import re
+
+def compile(directory, language='en'):
+ global root
+ root = directory
+ global lang
+ lang = language
+ wrapper = open(root + 'layouts/root.html', 'r').read()
+ wrapper = wrapper.replace('@slides', compile_chapters())
+ wrapper = insert_metadata(wrapper, lang=lang)
+ with open(root + 'slides.' + lang + '.html', 'w+') as output:
+ output.write(wrapper)
+ print('done')
+
+def insert_metadata(content, lang=None):
+ metadata = read_yaml('meta.yml')
+ for key, value in metadata.items():
+ placeholder = '@' + key
+ filler = value[lang]
+ print('replace', placeholder, 'with', filler)
+ if '@' + key in content:
+ content = content.replace(placeholder, filler)
+ return content
+
+def compile_chapters():
+ structure = read_yaml('slides.yml')
+ chapters = ""
+ for chapter in structure:
+ chapters += '\n' + compile_chapter(chapter) + '\n'
+ return chapters # string
+
+def compile_chapter(chapter):
+ if type(chapter) == str: # plain chapter names
+ chapter_input = '\n' + open(root + 'slides/' + chapter + '.' + lang + '.md', 'r').read()
+ delimiter = '\n@slide'
+ slides = [delimiter + slide for slide in chapter_input.split(delimiter)][1:]
+ print(slides)
+ chapter = ''
+ for slide in slides:
+ chapter += '\n' + compile_slide(slide) + '\n\n'
+ return chapter # string
+ else:
+ raise Exception('Chapters with attributes are not supported yet.\n' + str(chapter))
+
+def compile_slide(slide):
+ slide = slide.strip()
+ slide_metadata = get_slide_metadata(slide)
+ slide_data = get_slide_data(slide)
+ slide = get_slide_layout(slide_metadata['layout'])
+ for key, value in slide_data.items():
+ placeholder = '@' + key
+ filler = convert_slide_content(value)
+ print('replace', placeholder, 'with', filler)
+ if '@' + key in slide:
+ slide = slide.replace(placeholder, filler)
+ return slide # string
+
+def get_slide_metadata(slide):
+ metadata = { 'layout': 'default' }
+ metadata_attributes = re.search('^@slide\((.+)\)', slide.splitlines()[0])
+ if metadata_attributes:
+ metadata_attributes = metadata_attributes.group(1).split(' ')
+ for attribute in metadata_attributes:
+ metadata[attribute.split('=')[0]] = attribute.split('=')[1]
+ print("\nMETADATA:\n"+str(metadata)+"\n\n")
+ return metadata
+
+def get_slide_data(slide):
+ if slide.startswith('@slide'):
+ slide = slide[slide.find('\n')+1:] # cut off @slide declaration
+ slide_data = { data.split()[0].strip('@') : "\n".join(data.splitlines()[1:]) for data in slide.strip().split('\n\n@') }
+ return slide_data
+
+def get_slide_layout(layout_name):
+ try:
+ return open(root + 'layouts/' + layout_name + '.html', 'r').read()
+ except FileNotFoundError:
+ raise Exception('Layout ' + layout_name + ' not found!')
+
+def convert_slide_content(content):
+ return pypandoc.convert_text(content, 'html', format='md')
+
+def read_yaml(path):
+ with open(root + path, 'r') as stream:
+ try:
+ return yaml.safe_load(stream)
+ except yaml.YAMLError as exc:
+ print(exc)
+
+compile('../test/', language='de')
+compile('../test/', language='en')
diff --git a/test/layouts/default.html b/test/layouts/default.html
new file mode 100644
index 0000000..0f17d74
--- /dev/null
+++ b/test/layouts/default.html
@@ -0,0 +1,2 @@
+
@title
+@content
diff --git a/test/layouts/root.html b/test/layouts/root.html
index b13efde..007a5d5 100644
--- a/test/layouts/root.html
+++ b/test/layouts/root.html
@@ -7,6 +7,6 @@
@title
- @slides
+@slides
-