create simple mustash sobstitute
This commit is contained in:
parent
de5d67b2cf
commit
ab31d8bb7e
@ -1,8 +1,22 @@
|
|||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
|
import re
|
||||||
|
import copy
|
||||||
|
|
||||||
TEMPLATE_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'index.html')
|
TEMPLATE_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'index.html')
|
||||||
|
|
||||||
|
def simple_mustache(input_string, value_dict):
|
||||||
|
output_string = copy.deepcopy(input_string)
|
||||||
|
mustache_variables = re.findall(r"{{.*}}",output_string)
|
||||||
|
for v_text in mustache_variables:
|
||||||
|
v_name = v_text[2:-2]
|
||||||
|
if '.' in v_name:
|
||||||
|
dict_name, dict_subname = v_name.split(".")
|
||||||
|
v = value_dict[dict_name][dict_subname]
|
||||||
|
else:
|
||||||
|
v = value_dict[v_name]
|
||||||
|
output_string = output_string.replace(v_text, str(v))
|
||||||
|
return output_string
|
||||||
|
|
||||||
def obj2html(
|
def obj2html(
|
||||||
obj_path, output_html_path=None,
|
obj_path, output_html_path=None,
|
||||||
@ -18,8 +32,13 @@ def obj2html(
|
|||||||
|
|
||||||
with open(TEMPLATE_PATH, "r") as f:
|
with open(TEMPLATE_PATH, "r") as f:
|
||||||
html_template = f.read()
|
html_template = f.read()
|
||||||
html_string = html_template.replace("{{obj_3d}}", js_string)
|
|
||||||
html_string = html_string.replace("{{camera.fov}}", str(camera['fov']))
|
data_dict = {
|
||||||
|
"obj_3d": js_string,
|
||||||
|
"camera": camera,
|
||||||
|
}
|
||||||
|
|
||||||
|
html_string = simple_mustache(html_template, data_dict)
|
||||||
|
|
||||||
if output_html_path != None:
|
if output_html_path != None:
|
||||||
with open(output_html_path, "w") as f:
|
with open(output_html_path, "w") as f:
|
||||||
|
Loading…
Reference in New Issue
Block a user