Skip to content
This repository has been archived by the owner on May 29, 2021. It is now read-only.

Commit

Permalink
merge Component and Page; add clean
Browse files Browse the repository at this point in the history
  • Loading branch information
yue committed Aug 28, 2018
1 parent 8075263 commit 0db0685
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 65 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ build
example/
build/
test/
*/__pycache__
*/__pycache__
src
public
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"ENTRY": "../test/",
"ENTRY": "../src/",
"OUTPUT": "../build/",
"COMPONENTS": "components/",
"PAGES": "views/",
Expand Down
59 changes: 58 additions & 1 deletion lib/component.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
import os


class Component(object):
Expand Down Expand Up @@ -39,7 +40,6 @@ def resolve(self):

self.style_set = list(set(self.style_set))


def update(self, origin, inside):

classes = re.findall(self.__classname_reg, origin)
Expand All @@ -62,3 +62,60 @@ def make_div(classes, inside):
# print(inner_html)

return inner_html


class Page(Component):
def __init__(self, page_name, engine):
super().__init__(page_name, engine)
self.base_html = engine.base_html
self.engine = engine
self.title_reg = re.compile('<title>([\s\S]+?)</title>')
self.import_reg = re.compile('@import[\s\S]+?scss";')
self.title = self.name.rsplit('.', 1)[0].lower()
self.css_link = ''

def make(self):

print(f'making {self.title}')
self.make_html()
self.make_style()
self.write()

def make_html(self):
self.output_html = self.base_html.replace('<div id="app"></div>',
self.engine.base_component.template)
self.resolve()

self.css_link = f'<link href="../statics/css/{self.title}.css" rel="stylesheet"/>'

self.output_html = re.sub(self.title_reg,
lambda x: f'''<title>{self.title}</title>
{self.css_link}
''',
self.output_html)
self.output_html = self.output_html.replace('<router-view/>', self.template)

def make_style(self):
self.output_style += self.engine.base_component.style

for each in self.engine.base_component.style_set:
self.output_style += self.engine.components[each].style

self.output_style += self.style
scss_imports = re.findall(self.import_reg, self.output_style)
scss_imports = list(set(scss_imports))
for each in scss_imports:
self.output_style = re.sub(each, '', self.output_style)
self.output_style = '\n'.join(scss_imports) + self.output_style

def write(self):
html_file_name = self.engine.config.out_path + self.title
scss_file_name = self.engine.config.out_path + '/statics/scss/' + self.title

os.mkdir(html_file_name)

with open(html_file_name + '/index.html', 'w') as html:
html.write(self.output_html)

with open(scss_file_name + '.scss', 'w') as scss:
scss.write(self.output_style)
16 changes: 11 additions & 5 deletions lib/engine.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
from component import Component
from page import Page
from component import Component, Page
from config import Config


Expand All @@ -14,11 +13,12 @@ def __init__(self):
self.pages = {}

def run(self):
self.clean()
self.config.load()

print('config loaded')

with open(self.config.source_path + 'index.html', 'r') as base:
with open(self.config.source_path.replace('src', 'public') + 'index.html', 'r') as base:
self.base_html = base.read()

self.base_component = Component(self.config.source_path + 'App.vue', self)
Expand All @@ -40,17 +40,23 @@ def make_dirs(self):
if not os.path.isdir('../build'):
os.mkdir('../build')
os.mkdir('../build/statics')
os.mkdir('../build/statics/img')
# os.mkdir('../build/statics/imgs')
os.mkdir('../build/statics/js')
os.mkdir('../build/statics/css')
os.system(f'cp -r {self.config.source_path+"statics/imgs"} ../build/statics/imgs')
os.system(f'cp -r {self.config.scss_path} ../build/statics/scss')

def test(self):
self.run()
# print(self.components['<PageFooter/>'].style)
# print(self.pages['About'].style)

def clean(self):
os.system('rm -rf ../build/')
print('cleared up')

def compile_sass(self):

os.chdir(self.config.out_path + 'statics')
os.system('sass --update scss:css --style compressed')

Expand Down Expand Up @@ -80,4 +86,4 @@ def make_pages(self):

if __name__ == '__main__':
engine = Engine()
engine.test()
engine.run()
57 changes: 0 additions & 57 deletions lib/page.py

This file was deleted.

0 comments on commit 0db0685

Please sign in to comment.