def render(self, includeGuyJs=False): Intergambio.template = "static/template.html" vue = vbuild.render("static/*.vue") template = open(Intergambio.template).read() template = template.replace("/* SCRIPT */", str(vue.script)) template = template.replace("/* STYLE */", str(vue.style)) return template.replace("<!-- HTML -->", str(vue.html))
def render_vue(vue_file) -> str: rendered = [str(vbuild.render(gv)) for gv in glob(vue_file)] if len(rendered) > 1: return "\n".join(rendered) elif len(rendered) == 1: return rendered[0] else: return ""
def register(self, bottle: Bottle, app_dir: str): for route in self: route_vue(bottle, "/routes" + route["path"], os.path.join(app_dir, "src", "views", route["component"] + ".vue"), os.path.join(app_dir, "public", "index.html"), os.path.join(app_dir, "src", "components", "*.vue"), base_style=vbuild.render(os.path.join( app_dir, "App.vue")).style)
def _render(self, path): #here is the magic # load your template (from web folder) with open(os.path.join(path, "static", "index.html")) as fid: content = fid.read() # load all vue/sfc components v = vbuild.render(os.path.join(path, "static/*.vue")) # and inject them in your template return content.replace("<!-- HERE -->", str(v))
def _render(self, path): #here is the magic # this method is overrided, so you can render what you want # load your template (from static folder) with open(os.path.join(path, "static/index.html")) as fid: content = fid.read() # load all vue/sfc components v = vbuild.render(os.path.join(path, "static/*.vue")) # and inject them in your template return content.replace("<!-- HERE -->", str(v))
def test_real_files(): import glob for i in glob.glob("tests/vues/*.vue"): r = vbuild.render(i) assert str(r) assert str(vbuild.render("tests/vues/list.vue")) assert str(vbuild.render("tests/vues/*.vue")) assert str(vbuild.render("tests/*/*.vue")) assert str(vbuild.render("tests/vues/test.vue", "tests/vues/todo.vue")) assert str(vbuild.render(["tests/vues/test.vue", "tests/vues/todo.vue"])) assert str(vbuild.render(glob.glob("tests/vues/*.vue")))
def testfiles(self): if not os.path.isdir("vues"): self.skipTest("Don't test real vue files (you haven't a vues folder with .vue files)") import glob for i in glob.glob("vues/*.vue"): r=vbuild.render(i) self.assertTrue(str(r)) self.assertTrue(str(vbuild.render( "vues/list.vue"))) self.assertTrue(str(vbuild.render( "vues/*.vue"))) self.assertTrue(str(vbuild.render( "*/*.vue"))) self.assertTrue(str(vbuild.render( "vues/test.vue", "vues/todo.vue" ))) self.assertTrue(str(vbuild.render( ["vues/test.vue","vues/todo.vue"] ))) self.assertTrue(str(vbuild.render( glob.glob("vues/*.vue"))))
def render(template, title, vue=(), **kwargs): """ Helper function to render templates given a page title :param template: template to render :param title: title of the page :param vue: the vue components to render on this page :param kwargs: :return: """ if not isinstance(vue, list): vue = [vue] vue_html = [] vue_script = [] vue_style = [] # go through each vue component, and render the HTML, CSS, and JavaScript for v in vue: if not str(v).endswith('.vue'): v = str(v) + '.vue' res = vbuild.render("static/vue/{}".format(v)) vue_html.append(res.html) vue_script.append(res.script) vue_style.append(res.style) return render_template( template, page_title=title, vue_html=vue_html, vue_script=vue_script, vue_style=vue_style, **kwargs )
def test_bad_file(self): with self.assertRaises(vbuild.VBuildException): vbuild.render("unknown_file.vue") # No such file or directory
def test_bad_file(): with pytest.raises(vbuild.VBuildException): vbuild.render("unknown_file.vue") # No such file or directory