def get(self, jsData=None, jsDataKey=None, isPyData=True, jsFnc=None): """ :return: """ if jsData is None: return Js.JsJson().parse("decodeURIComponent(document.cookies)", isPyData=False) jsData = JsUtils.jsConvert(jsData, jsDataKey, isPyData, jsFnc) return Js.JsJson().parse("decodeURIComponent(document.cookies)['%s']" % jsData, isPyData=False)
def get(self, data: Union[str, primitives.JsDataModel] = None, js_conv_func: Optional[Union[str, list]] = True, js_result_func: Optional[str] = None): """ Description: ------------ Attributes: ---------- :param Union[str, primitives.JsDataModel] data: Optional. A String corresponding to a JavaScript object. :param Optional[Union[str, list]] js_conv_func: Optional. A specific JavaScript data conversion function. :param Optional[str] js_result_func: Optional. A function used to transform the result. """ if data is None: return Js.JsJson().parse("decodeURIComponent(document.cookies)", js_result_func=js_result_func) data = JsUtils.jsConvertData(data, js_conv_func) return Js.JsJson().parse("decodeURIComponent(document.cookies)['%s']" % data, js_result_func=js_result_func)
def codepen(self, path: Optional[str] = None, target: str = "_blank", open_browser: bool = True): """ Description: ------------ Update the Html launcher and send the data to Codepen. URL used: https://codepen.io/pen/define/ Usage:: page = Report() page.ui.text("This is a text") page.outs.browser.codepen() Related Pages: https://www.debuggex.com/cheatsheet/regex/python Attributes: ---------- :param Optional[str] path: Optional. Output path in which the static files will be generated. :param str target: Optional. Load the data in a new tab in the browser. :param bool open_browser: Optional. Flag to open the browser automatically. :return: The output launcher full file name. """ import re import webbrowser results = self._context._to_html_obj() js_external = re.findall( '<script language="javascript" type="text/javascript" src="(.*?)"></script>', results['jsImports']) css_external = re.findall( '<link rel="stylesheet" href="(.*?)" type="text/css">', results['cssImports']) js_obj = Js.JsBase() result = {"js": results["jsFrgs"], "js_external": ";".join(js_external), "css_external": ";".join(css_external), "html": results['content'], "css": results["cssStyle"]} data = js_obj.location.postTo("https://codepen.io/pen/define/", {"data": json.dumps(result)}, target=target) if path is None: path = os.path.join(os.getcwd(), "outs") else: path = os.path.join(path) if not os.path.exists(path): os.makedirs(path) with open(os.path.join(path, "RunnerCodepen.html"), "w") as f: f.write('<html><body></body><script>%s</script></html>' % data.replace("\\\\n", "")) launcher_file = os.path.join(path, "RunnerCodepen.html") if open_browser: webbrowser.open(launcher_file) return launcher_file
from epyk.core.js import Js from epyk.core.js import JsUtils from epyk.core.js.fncs import JsFncsRecords jsObj = Js.JsBase() jsObj.registerFunction("row-buckets") jsObj.addKeyEvent(jsObj.window.alert("test alert"), 13) f = JsUtils.JsFile("RowBucket", path=r"../outs") f.writeReport(jsObj) f.close()
import pytest from epyk.core.js import Js from epyk.core.js import JsUtils from epyk.core.js.primitives import JsNumber jsObj = Js.JsBase() print(jsObj.objects.number.new(349.673, "MyNumber").toStr()) jsObj = Js.JsBase() f = JsUtils.JsFile(os.path.basename(__file__).split(".")[0], path=r"C:\Users\olivier\Documents\youpi\jsFiles") f.writeJs([ jsObj.objects.array.new([2, 5, 12, -3], "MyArray"), jsObj.objects.array.new([3, -9, 2, -6], "MyArray2"), jsObj.objects.array.new([], "MyArray3"), jsObj.console.log(jsObj.objects.array.get("MyArray3").concat(jsObj.objects.array.get("MyArray"), jsObj.objects.array.get("MyArray2"))), jsObj.console.log(jsObj.objects.array.get("MyArray").findIndex([ jsObj.if_(jsObj.data.loop.val <= 0, [ jsObj.return_(jsObj.objects.true)]).else_(jsObj.return_(jsObj.objects.false)), ])), jsObj.console.log(jsObj.objects.array.get("MyArray").map([ jsObj.data.loop.val * jsObj.math.max(jsObj.data.loop.arr.toArgs()), jsObj.return_(jsObj.data.loop.val) ])), jsObj.console.log("########"), # jsObj.console.log(jsObj.objects.array.get("MyArray")),
from epyk.core.js import JsUtils from epyk.core.js import Js f = JsUtils.JsFile(path=r"../outs") js_obj = Js.JsBase() breadcrumb = js_obj.breadcrumb js_obj.addOnLoad(breadcrumb.add("test1", "value1")) js_obj.addOnLoad(breadcrumb.add("test2", "value2")) js_obj.addOnLoad(breadcrumb.hash("test3")) js_obj.addOnLoad(js_obj.clipboard(breadcrumb.url)) js_obj.addOnLoad(js_obj.info("icon")) f.codepen(js_obj)