(self, js_path, exports={}, **kwargs)
return rendered_path
Wraps the JavaScript code at *js_path* in a (JavaScript) sandbox which
        exports whatever global variables are provided via *exports* then
        minifies, caches, and sends the result to the client.

        The provided *kwargs* will be passed to the
        `ApplicationWebSocket.send_js` method.

        The *exports* dict needs to be in the following format::

            exports = {
                "global": "export_name"
            }

        For example, if you wanted to use underscore.js but didn't want to
        overwrite the global ``_`` variable (if already being used by a parent
        web application)::

            exports = {"_": "GateOne._"}
            self.wrap_and_send_js('/path/to/underscore.js', exports)

        This would result in the "_" global being exported as "GateOne._".  In
        other words, this is what will end up at the bottom of the wrapped
        JavaScript just before the end of the sandbox:

        .. code-block:: javascript

            window.GateOne._ = _;

        This method should make it easy to include any given JavaScript library
        without having to worry (as much) about namespace conflicts.

        .. note::

            You don't have to prefix your export with 'GateOne'.  You can export
            the global with whatever name you like.
Wraps the JavaScript code at *js_path* in a (JavaScript) sandbox which
        exports whatever global variables are provided via *exports* then
        minifies, caches, and sends the result to the client.
Wraps the JavaScript code at * js_path * in a ( JavaScript ) sandbox which exports whatever global variables are provided via * exports * then minifies caches and sends the result to the client .
def wrap_and_send_js(self, js_path, exports={}, **kwargs):
        """
        Wraps the JavaScript code at *js_path* in a (JavaScript) sandbox which
        exports whatever global variables are provided via *exports* then
        minifies, caches, and sends the result to the client.

        The provided *kwargs* will be passed to the
        `ApplicationWebSocket.send_js` method.

        The *exports* dict needs to be in the following format::

            exports = {
                "global": "export_name"
            }

        For example, if you wanted to use underscore.js but didn't want to
        overwrite the global ``_`` variable (if already being used by a parent
        web application)::

            exports = {"_": "GateOne._"}
            self.wrap_and_send_js('/path/to/underscore.js', exports)

        This would result in the "_" global being exported as "GateOne._".  In
        other words, this is what will end up at the bottom of the wrapped
        JavaScript just before the end of the sandbox:

        .. code-block:: javascript

            window.GateOne._ = _;

        This method should make it easy to include any given JavaScript library
        without having to worry (as much) about namespace conflicts.

        .. note::

            You don't have to prefix your export with 'GateOne'.  You can export
            the global with whatever name you like.
        """
        if not os.path.exists(js_path):
            self.sync_log.error(_("File does not exist: {0}").format(js_path))
            return
        cache_dir = self.settings['cache_dir']
        mtime = os.stat(js_path).st_mtime
        filename = os.path.split(js_path)[1]
        script = {'name': filename}
        filepath_hash = hashlib.md5(
            js_path.encode('utf-8')).hexdigest()[:10]
        # Store the file info in the file_cache just in case we need to
        # reference the original (non-rendered) path later:
        self.file_cache[filepath_hash] = {
            'filename': filename,
            'kind': 'js',
            'path': js_path,
            'mtime': mtime,
        }
        rendered_filename = 'rendered_%s_%s' % (filepath_hash, int(mtime))
        rendered_path = os.path.join(cache_dir, rendered_filename)
        if os.path.exists(rendered_path):
            self.send_js(rendered_path, filename=filename, force=True, **kwargs)
            return
        script['source'] = resource_string('gateone', 'templates/libwrapper.js')
        rendered = self.render_string(
            libwrapper,
            script=script,
            exports=exports
        )
        with io.open(rendered_path, 'wb') as f:
            f.write(rendered)
        self.send_js(rendered_path, filename=filename, force=True, **kwargs)
        # Remove older versions of the rendered template if present
        for fname in os.listdir(cache_dir):
            if fname == rendered_filename:
                continue
            elif filepath_hash in fname:
                # Older version present.
                # Remove it (and it's minified counterpart).
                os.remove(os.path.join(cache_dir, fname))
        return rendered_path
def wrap_and_send_js ( self , js_path , exports = { } , * * kwargs ) : if not os . path . exists ( js_path ) : self . sync_log . error ( _ ( "File does not exist: {0}" ) . format ( js_path ) ) return cache_dir = self . settings [ 'cache_dir' ] mtime = os . stat ( js_path ) . st_mtime filename = os . path . split ( js_path ) [ 1 ] script = { 'name' : filename } filepath_hash = hashlib . md5 ( js_path . encode ( 'utf-8' ) ) . hexdigest ( ) [ : 10 ] # Store the file info in the file_cache just in case we need to # reference the original (non-rendered) path later: self . file_cache [ filepath_hash ] = { 'filename' : filename , 'kind' : 'js' , 'path' : js_path , 'mtime' : mtime , } rendered_filename = 'rendered_%s_%s' % ( filepath_hash , int ( mtime ) ) rendered_path = os . path . join ( cache_dir , rendered_filename ) if os . path . exists ( rendered_path ) : self . send_js ( rendered_path , filename = filename , force = True , * * kwargs ) return script [ 'source' ] = resource_string ( 'gateone' , 'templates/libwrapper.js' ) rendered = self . render_string ( libwrapper , script = script , exports = exports ) with io . open ( rendered_path , 'wb' ) as f : f . write ( rendered ) self . send_js ( rendered_path , filename = filename , force = True , * * kwargs ) # Remove older versions of the rendered template if present for fname in os . listdir ( cache_dir ) : if fname == rendered_filename : continue elif filepath_hash in fname : # Older version present. # Remove it (and it's minified counterpart). os . remove ( os . path . join ( cache_dir , fname ) ) return rendered_path