created md2html compiler module
for now it is watching md files and is synchronized with other modules remains the whole compiling process to code
This commit is contained in:
@@ -22,7 +22,7 @@ from PyQt5.QtWebKitWidgets import QWebPage, QWebView, QWebInspector
|
|||||||
import json
|
import json
|
||||||
import git
|
import git
|
||||||
|
|
||||||
from classes import server, sasscompiler, design, content
|
from classes import server, sasscompiler, design, content, md2html
|
||||||
|
|
||||||
class Core():
|
class Core():
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
@@ -44,6 +44,7 @@ class Core():
|
|||||||
|
|
||||||
self.server = server.Server(self)
|
self.server = server.Server(self)
|
||||||
self.sasscompiler = sasscompiler.Compiler(self)
|
self.sasscompiler = sasscompiler.Compiler(self)
|
||||||
|
self.contentcompiler = md2html.Compiler(self)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def mainwindow(self):
|
def mainwindow(self):
|
||||||
@@ -110,6 +111,7 @@ class Core():
|
|||||||
self.cwd = cwd
|
self.cwd = cwd
|
||||||
self.server.reload()
|
self.server.reload()
|
||||||
self.sasscompiler.reload()
|
self.sasscompiler.reload()
|
||||||
|
self.contentcompiler.reload()
|
||||||
# if not self.tempcwd:
|
# if not self.tempcwd:
|
||||||
self._mw.setWindowTitle("Cascade – "+self.cwd)
|
self._mw.setWindowTitle("Cascade – "+self.cwd)
|
||||||
|
|
||||||
|
|||||||
+5
-2
@@ -54,9 +54,10 @@ class Summary(QWidget):
|
|||||||
json.dump(self.sum, fp, ensure_ascii=False, indent="\t")
|
json.dump(self.sum, fp, ensure_ascii=False, indent="\t")
|
||||||
# refresh list
|
# refresh list
|
||||||
self.list.addNewItem(item)
|
self.list.addNewItem(item)
|
||||||
|
# reload content compiler
|
||||||
|
self.parent.core.contentcompiler.reload()
|
||||||
|
|
||||||
def recordNewList(self):
|
def recordNewList(self):
|
||||||
|
|
||||||
newdata = []
|
newdata = []
|
||||||
for i in range(0,self.list.count()):
|
for i in range(0,self.list.count()):
|
||||||
# print(self.item(i).item['title'])
|
# print(self.item(i).item['title'])
|
||||||
@@ -68,7 +69,8 @@ class Summary(QWidget):
|
|||||||
with open(jsonfilepath, "w") as fp:
|
with open(jsonfilepath, "w") as fp:
|
||||||
json.dump(newdata, fp, ensure_ascii=False, indent="\t")
|
json.dump(newdata, fp, ensure_ascii=False, indent="\t")
|
||||||
|
|
||||||
|
# reload content compiler
|
||||||
|
self.parent.core.contentcompiler.reload()
|
||||||
|
|
||||||
class SummaryList(QListWidget):
|
class SummaryList(QListWidget):
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
@@ -219,6 +221,7 @@ class MarkdownEditor(QWidget):
|
|||||||
self.refreshViewer()
|
self.refreshViewer()
|
||||||
if not self.changed:
|
if not self.changed:
|
||||||
self.changed = True
|
self.changed = True
|
||||||
|
# TODO: show in list that content needs to be saved
|
||||||
# i = self.tabs.currentIndex()
|
# i = self.tabs.currentIndex()
|
||||||
# self.tabs.setTabText(i, "* "+self.tabs.tabText(i))
|
# self.tabs.setTabText(i, "* "+self.tabs.tabText(i))
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import os
|
||||||
|
from PyQt5.QtCore import QFileSystemWatcher
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
class Compiler():
|
||||||
|
def __init__(self,parent):
|
||||||
|
self.parent = parent
|
||||||
|
self.initWatching()
|
||||||
|
self.compileContents()
|
||||||
|
|
||||||
|
def initWatching(self):
|
||||||
|
self.refreshPaths()
|
||||||
|
self.fs_watcher = QFileSystemWatcher(self.paths)
|
||||||
|
# self.fs_watcher.directoryChanged.connect(self.directory_changed)
|
||||||
|
self.fs_watcher.fileChanged.connect(self.onMdFileChanged)
|
||||||
|
|
||||||
|
def onMdFileChanged(self):
|
||||||
|
print("onMdFileChanged")
|
||||||
|
try:
|
||||||
|
self.compileContents()
|
||||||
|
except Exception as e:
|
||||||
|
print("Error compiling MD files", e)
|
||||||
|
pass
|
||||||
|
|
||||||
|
def refreshPaths(self):
|
||||||
|
jsonfilepath = os.path.join(self.parent.cwd,'.config/summary.json')
|
||||||
|
sum_json = open(jsonfilepath).read()
|
||||||
|
self.sum = json.loads(sum_json)
|
||||||
|
|
||||||
|
self.paths = [os.path.join(self.parent.cwd,'contents')]
|
||||||
|
for item in self.sum:
|
||||||
|
self.paths.append(os.path.join(self.parent.cwd,'contents',item['file']))
|
||||||
|
|
||||||
|
def reload(self):
|
||||||
|
self.fs_watcher.removePaths(self.paths)
|
||||||
|
self.refreshPaths()
|
||||||
|
self.fs_watcher.addPaths(self.paths)
|
||||||
|
self.compileContents()
|
||||||
|
|
||||||
|
def compileContents(self):
|
||||||
|
print('Compiling md')
|
||||||
Reference in New Issue
Block a user