コード例 #1
0
ファイル: PyOuts.py プロジェクト: epykure/epyk-ui
  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
コード例 #2
0
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()


コード例 #3
0
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)