def embed(context, request): request.response.content_type = b'text/javascript' request.response.text = client.render_embed_js( assets_env=request.registry['assets_client_env'], app_html_url=request.route_url('widget'), base_url=request.route_url('index')) return request.response
def build_extension_common(webassets_env, service_url, bundle_app=False): """ Copy the contents of src to dest, including some generic extension scripts. """ # Create the assets directory content_dir = webassets_env.directory # Copy over the config and destroy scripts shutil.copyfile('h/static/extension/destroy.js', content_dir + '/destroy.js') shutil.copyfile('h/static/extension/config.js', content_dir + '/config.js') # Render the embed code. with codecs.open(content_dir + '/embed.js', 'w', 'utf-8') as fp: if bundle_app: app_html_url = '/public/app.html' else: app_html_url = '{}app.html'.format(service_url) data = client.render_embed_js(webassets_env=webassets_env, app_html_url=app_html_url) fp.write(data)
def build_extension(args): """ Build the Chrome or Firefox extensions. You can supply the base URL of an h installation with which this extension will communicate, such as "http://localhost:5000" when developing locally or "https://hypothes.is" to talk to the production Hypothesis application. """ service_url = args.service_url if not service_url.endswith('/'): service_url = '{}/'.format(service_url) build_dir = 'build/' + args.browser public_dir = os.path.join(build_dir, 'public') # Prepare a fresh build. clean(build_dir) os.makedirs(build_dir) os.makedirs(public_dir) # Bundle the extension assets. copytree('h/browser/chrome/content', os.path.join(build_dir, 'content')) copytree('h/browser/chrome/help', os.path.join(build_dir, 'help')) copytree('h/browser/chrome/images', os.path.join(build_dir, 'images')) copytree('h/static/images', os.path.join(public_dir, 'images')) copytree('h/static/styles/vendor/fonts', os.path.join(public_dir, 'fonts')) extension_sources = ['extension.bundle.js'] if args.debug: extension_sources.extend([x + '.map' for x in extension_sources]) client_sources = [] env = assets.Environment('/public', 'h/assets.ini', 'build/manifest.json') for bundle in ['app_js', 'app_css', 'inject_js', 'inject_css']: client_sources.extend(env.files(bundle)) if args.debug: client_sources.extend([x + '.map' for x in client_sources]) try: copyfilelist(src='build/scripts', dst=os.path.join(build_dir, 'lib'), filelist=extension_sources) copyfilelist(src='h/browser/chrome/lib', dst=os.path.join(build_dir, 'lib'), filelist=['options.html', 'options.js']) copyfilelist(src='build', dst=public_dir, filelist=client_sources) copyfilelist(src='h/browser/chrome/lib', dst=public_dir, filelist=['destroy.js']) except MissingSourceFile as e: print( "Missing source file: {:s}! Have you run `gulp build`?".format(e)) sys.exit(1) # Render the embed code. with codecs.open(os.path.join(public_dir, 'embed.js'), 'w', 'utf-8') as fp: data = client.render_embed_js(assets_env=env, app_html_url='/public/app.html') fp.write(data) # Render the sidebar html api_url = '{}api/'.format(service_url) with codecs.open(os.path.join(public_dir, 'app.html'), 'w', 'utf-8') as fp: data = client.render_app_html( api_url=api_url, service_url=service_url, # Google Analytics tracking is currently not enabled # for the extension ga_tracking_id=None, assets_env=env, websocket_url=args.websocket_url, sentry_public_dsn=args.sentry_public_dsn) fp.write(data) # Render the manifest. with codecs.open(os.path.join(build_dir, 'manifest.json'), 'w', 'utf-8') as fp: data = chrome_manifest(script_host_url=None, bouncer_url=args.bouncer_url, browser=args.browser) fp.write(data) # Write build settings to a JSON file with codecs.open(os.path.join(build_dir, 'settings-data.js'), 'w', 'utf-8') as fp: settings = settings_dict(service_url, api_url, args.sentry_public_dsn) fp.write('window.EXTENSION_CONFIG = ' + json.dumps(settings))
def build_extension(args): """ Build the Chrome or Firefox extensions. You can supply the base URL of an h installation with which this extension will communicate, such as "http://localhost:5000" when developing locally or "https://hypothes.is" to talk to the production Hypothesis application. """ service_url = args.service_url if not service_url.endswith('/'): service_url = '{}/'.format(service_url) build_dir = 'build/' + args.browser public_dir = os.path.join(build_dir, 'public') # Prepare a fresh build. clean(build_dir) os.makedirs(build_dir) os.makedirs(public_dir) # Bundle the extension assets. copytree('h/browser/chrome/content', os.path.join(build_dir, 'content')) copytree('h/browser/chrome/help', os.path.join(build_dir, 'help')) copytree('h/browser/chrome/images', os.path.join(build_dir, 'images')) copytree('h/static/images', os.path.join(public_dir, 'images')) copytree('h/static/styles/vendor/fonts', os.path.join(public_dir, 'fonts')) extension_sources = ['extension.bundle.js'] if args.debug: extension_sources.extend([x + '.map' for x in extension_sources]) client_sources = [] env = assets.Environment('/public', 'h/assets.ini', 'build/manifest.json') for bundle in ['app_js', 'app_css', 'inject_js', 'inject_css']: client_sources.extend(env.files(bundle)) if args.debug: client_sources.extend([x + '.map' for x in client_sources]) try: copyfilelist(src='build/scripts', dst=os.path.join(build_dir, 'lib'), filelist=extension_sources) copyfilelist(src='h/browser/chrome/lib', dst=os.path.join(build_dir, 'lib'), filelist=['options.html', 'options.js']) copyfilelist(src='build', dst=public_dir, filelist=client_sources) copyfilelist(src='h/browser/chrome/lib', dst=public_dir, filelist=['destroy.js']) except MissingSourceFile as e: print("Missing source file: {:s}! Have you run `gulp build`?" .format(e)) sys.exit(1) # Render the embed code. with codecs.open(os.path.join(public_dir, 'embed.js'), 'w', 'utf-8') as fp: data = client.render_embed_js(assets_env=env, app_html_url='/public/app.html') fp.write(data) # Render the sidebar html api_url = '{}api/'.format(service_url) with codecs.open(os.path.join(public_dir, 'app.html'), 'w', 'utf-8') as fp: data = client.render_app_html( api_url=api_url, service_url=service_url, # Google Analytics tracking is currently not enabled # for the extension ga_tracking_id=None, assets_env=env, websocket_url=args.websocket_url, sentry_public_dsn=args.sentry_public_dsn) fp.write(data) # Render the manifest. with codecs.open(os.path.join(build_dir, 'manifest.json'), 'w', 'utf-8') as fp: data = chrome_manifest(script_host_url=None, bouncer_url=args.bouncer_url, browser=args.browser) fp.write(data) # Write build settings to a JSON file with codecs.open(os.path.join(build_dir, 'settings-data.js'), 'w', 'utf-8') as fp: settings = settings_dict(service_url, api_url, args.sentry_public_dsn) fp.write('window.EXTENSION_CONFIG = ' + json.dumps(settings))
def embed(context, request): request.response.content_type = b"text/javascript" request.response.text = client.render_embed_js( webassets_env=request.webassets_env, app_html_url=request.resource_url(context, "app.html") ) return request.response