Esempio n. 1
0
    def __init__(self):
        self._known_component_classes = set()
        self._modules = {}
        self._assets = {}
        self._associated_assets = {}
        self._data = {}
        self._used_assets = set()  # between all sessions (for export)

        # Create asset to reset CSS
        asset_reset = Asset('reset.css', RESET)
        # Create asset to bootstrap Flexx
        asset_loader = Asset('flexx-loader.js', LOADER)
        # Create asset for PScript std
        func_names, method_names = get_all_std_names()
        mod = create_js_module('pscript-std.js', get_full_std_lib(),
                               [], func_names + method_names, 'amd-flexx')
        asset_pscript = Asset('pscript-std.js', HEADER + mod)
        # Create asset for the even system
        pre1 = ', '.join(['%s%s = _py.%s%s' % (FUNCTION_PREFIX, n, FUNCTION_PREFIX, n)
                          for n in JS_EVENT.meta['std_functions']])
        pre2 = ', '.join(['%s%s = _py.%s%s' % (METHOD_PREFIX, n, METHOD_PREFIX, n)
                          for n in JS_EVENT.meta['std_methods']])
        mod = create_js_module('flexx.event.js',
                               'var %s;\nvar %s;\n%s' % (pre1, pre2, JS_EVENT),
                               ['pscript-std.js as _py'],
                               ['Component', 'loop', 'logger'] + _property.__all__,
                               'amd-flexx')
        asset_event = Asset('flexx.event.js', HEADER + mod)
        # Create asset for bsdf - we replace the UMD loader code with flexx.define()
        code = open(get_resoure_path('bsdf.js'), 'rb').read().decode().replace('\r', '')
        code = code.split('"use strict";\n', 1)[1]  # put in the Flexx loader instead
        code = 'flexx.define("bsdf", [], (function () {\n"use strict";\n' + code
        asset_bsdf = Asset('bsdf.js', code)
        # Create asset for bb64 - we replace the UMD loader code with flexx.define()
        code = open(get_resoure_path('bb64.js'), 'rb').read().decode().replace('\r', '')
        code = code.split('"use strict";\n', 1)[1]  # put in the Flexx loader instead
        code = 'flexx.define("bb64", [], (function () {\n"use strict";\n' + code
        asset_bb64 = Asset('bb64.js', code)

        # Add them
        for a in [asset_reset, asset_loader, asset_pscript]:
            self.add_shared_asset(a)

        if getattr(self, '_test_mode', False):
            return

        # Create flexx-core bootstrap bundle
        self.update_modules()  # to collect _component2 and _clientcore
        asset_core = Bundle('flexx-core.js')
        asset_core.add_asset(asset_loader)
        asset_core.add_asset(asset_bsdf)
        asset_core.add_asset(asset_bb64)
        asset_core.add_asset(asset_pscript)
        asset_core.add_asset(asset_event)
        asset_core.add_module(self.modules['flexx.app._clientcore'])
        asset_core.add_module(self.modules['flexx.app._component2'])
        self.add_shared_asset(asset_core)
Esempio n. 2
0
    def __init__(self):
        self._known_component_classes = set()
        self._modules = {}
        self._assets = {}
        self._associated_assets = {}
        self._data = {}
        self._used_assets = set()  # between all sessions (for dump)

        # Create asset to reset CSS
        asset_reset = Asset('reset.css', RESET)
        # Create asset to bootstrap Flexx
        asset_loader = Asset('flexx-loader.js', LOADER)
        # Create asset for PScript std
        func_names, method_names = get_all_std_names()
        mod = create_js_module('pscript-std.js', get_full_std_lib(),
                               [], func_names + method_names, 'amd-flexx')
        asset_pscript = Asset('pscript-std.js', HEADER + mod)
        # Create asset for the even system
        pre1 = ', '.join(['%s%s = _py.%s%s' % (FUNCTION_PREFIX, n, FUNCTION_PREFIX, n)
                          for n in JS_EVENT.meta['std_functions']])
        pre2 = ', '.join(['%s%s = _py.%s%s' % (METHOD_PREFIX, n, METHOD_PREFIX, n)
                          for n in JS_EVENT.meta['std_methods']])
        mod = create_js_module('flexx.event.js',
                               'var %s;\nvar %s;\n%s' % (pre1, pre2, JS_EVENT),
                               ['pscript-std.js as _py'],
                               ['Component', 'loop', 'logger'] + _property.__all__,
                               'amd-flexx')
        asset_event = Asset('flexx.event.js', HEADER + mod)
        # Create asset for bsdf - we replace the UMD loader code with flexx.define()
        code = open(get_resoure_path('bsdf.js'), 'rb').read().decode().replace('\r', '')
        code = code.split('"use strict";\n', 1)[1]  # put in the Flexx loader instead
        code = 'flexx.define("bsdf", [], (function () {\n"use strict";\n' + code
        asset_bsdf = Asset('bsdf.js', code)
        # Create asset for bb64 - we replace the UMD loader code with flexx.define()
        code = open(get_resoure_path('bb64.js'), 'rb').read().decode().replace('\r', '')
        code = code.split('"use strict";\n', 1)[1]  # put in the Flexx loader instead
        code = 'flexx.define("bb64", [], (function () {\n"use strict";\n' + code
        asset_bb64 = Asset('bb64.js', code)

        # Add them
        for a in [asset_reset, asset_loader, asset_pscript]:
            self.add_shared_asset(a)

        if getattr(self, '_test_mode', False):
            return

        # Create flexx-core bootstrap bundle
        self.update_modules()  # to collect _component2 and _clientcore
        asset_core = Bundle('flexx-core.js')
        asset_core.add_asset(asset_loader)
        asset_core.add_asset(asset_bsdf)
        asset_core.add_asset(asset_bb64)
        asset_core.add_asset(asset_pscript)
        asset_core.add_asset(asset_event)
        asset_core.add_module(self.modules['flexx.app._clientcore'])
        asset_core.add_module(self.modules['flexx.app._component2'])
        self.add_shared_asset(asset_core)
Esempio n. 3
0
    def script(self):
        """ Return JS (js of embbeded components), after transScript"""
        js = "\n".join(self._script)
        isPyComp = "_pyfunc_op_instantiate(" in js  # in fact : contains
        isLibInside = "var _pyfunc_op_instantiate" in js

        if (fullPyComp is False) and isPyComp and not isLibInside:
            return transScript(pscript.get_full_std_lib() + "\n" + js)
        else:
            return transScript(js)
Esempio n. 4
0
    def script(self):
        """ Return JS (js of embbeded components), after transScript"""
        scripts = list(topological_sort(self._script))
        js = "\n".join([x.code for x in scripts])
        isPyComp = "_pyfunc_op_instantiate(" in js  # in fact : contains
        isLibInside = "var _pyfunc_op_instantiate" in js

        if (vbuild.fullPyComp is False) and isPyComp and not isLibInside:
            import pscript
            return vbuild.transScript(pscript.get_full_std_lib() + "\n" + js)
        else:
            return vbuild.transScript(js)