1 Star 0 Fork 0

谷嘉龙/blockpy

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
build.py 1.71 KB
一键复制 编辑 原始数据 按行查看 历史
Austin Cory Bart 提交于 2018-01-28 02:13 . More Tifa bindings
import os
import re
with open('src/interface.html', 'r') as inp:
with open('src/interface.js', 'w') as output:
contents = inp.read()
cleaned_contents = contents.replace('"', '\\"').replace('\n', '')
js_contents = '''
/**
* An automatically generated file, based on interface.html.
* An interesting problem in web development is managing HTML
* code in JS files. Rather than embedding string literals and
* concatenating them, or some other hackish soluion,
* we simply convert an HTML file to a JS string. Therefore,
* relevant edits should be in interface.html instead.
*
* The BlockPyInterface global can be seen as a constant
* representation of the default interface.
*/
BlockPyInterface = "{interface_code}";
'''.format(interface_code=cleaned_contents)
output.write(js_contents)
INSTRUCTOR_ROOT = 'src/instructor/'
with open('src/sk_mod_instructor_extended.js', 'w') as output:
output.write("""
/**
* An automatically generated file, based on the files in `instructors/`.
* We need to have the python code in these files made available in the
* JS files, so we load them in via a preprocessing step.
*/
var $INSTRUCTOR_MODULES_EXTENDED = {};
""")
for instructor_file_name in os.listdir(INSTRUCTOR_ROOT):
with open(INSTRUCTOR_ROOT+instructor_file_name, 'r') as input:
print(instructor_file_name)
contents = input.read()
contents = contents.replace('\\','\\\\').replace('"', '\\"').replace('\n', '\\n')
output.write('$INSTRUCTOR_MODULES_EXTENDED["{module}"] = "{code}"\n'.format(
module = instructor_file_name,
code = contents
))
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/huelong/blockpy.git
git@gitee.com:huelong/blockpy.git
huelong
blockpy
blockpy
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385