示例#1
0
文件: views.py 项目: JJediny/h
def annotation(context, request):
    annotation = context.model

    if 'title' in annotation.get('document', {}):
        title = 'Annotation by {user} on {title}'.format(
            user=annotation['user'].replace('acct:', ''),
            title=annotation['document']['title'])
    else:
        title = 'Annotation by {user}'.format(
            user=annotation['user'].replace('acct:', ''))

    alternate = request.resource_url(request.root, 'api', 'annotations',
                                     annotation['id'])

    return {
        'app_config': app_config(request),
        'meta_attrs': (
            {'property': 'og:title', 'content': title},
            {'property': 'og:description', 'content': ''},
            {'property': 'og:image', 'content': '/assets/images/logo.png'},
            {'property': 'og:site_name', 'content': 'Hypothes.is'},
            {'property': 'og:url', 'content': request.url},
        ),
        'link_attrs': (
            {'rel': 'alternate', 'href': alternate,
                'type': 'application/json'},
        ),
    }
示例#2
0
文件: views.py 项目: JJediny/h
def stream(context, request):
    atom = request.route_url('stream_atom')
    rss = request.route_url('stream_rss')
    return {
        'app_config': app_config(request),
        'link_tags': [
            {'rel': 'alternate', 'href': atom, 'type': 'application/atom+xml'},
            {'rel': 'alternate', 'href': rss, 'type': 'application/rss+xml'},
        ]
    }
示例#3
0
文件: sidebar_test.py 项目: JJediny/h
def test_websocket_url(url_in, url_out):
    request = mock.Mock()

    def fake_route_url(url):
        if url == 'api':
            return 'https://hypothes.is/api'
        elif url == 'ws':
            return url_in

    request.route_url = fake_route_url
    result = app_config(request)

    assert result['websocketUrl'] == url_out
示例#4
0
文件: buildext.py 项目: JJediny/h
def settings_dict(env):
    """ Returns a dictionary of settings to be bundled with the extension """
    request = env['request']
    config = app_config(request)
    api_url = config['apiUrl']
    sentry_dsn = request.sentry.get_public_dsn('https')

    if sentry_dsn:
        config.update({
            'raven': {
              'dsn': sentry_dsn,
              'release': h.__version__,
            },
        })

    config.update({
        'buildType': build_type_from_api_url(api_url),
    })
    return config
示例#5
0
文件: buildext.py 项目: JJediny/h
def build_chrome(args):
    """
    Build the Chrome extension. You can supply the base URL of an h
    installation with which this extension will communicate, such as
    "http://localhost:5000" (the default) when developing locally or
    "https://hypothes.is" to talk to the production Hypothesis application.

    By default, the extension will load static assets (JavaScript/CSS/etc.)
    from the application you specify. This can be useful when developing, but
    when building a production extension for deployment to the Chrome Store you
    will need to specify an assets URL that links to the built assets within
    the Chrome Extension, such as:

        chrome-extension://<extensionid>/public
    """
    paster.setup_logging(args.config_uri)

    os.environ['WEBASSETS_BASE_DIR'] = os.path.abspath('./build/chrome/public')
    if args.assets is not None:
        os.environ['WEBASSETS_BASE_URL'] = args.assets

    env = get_env(args.config_uri, args.base)

    # Prepare a fresh build.
    clean('build/chrome')
    os.makedirs('build/chrome')

    # Bundle the extension assets.
    webassets_env = env['request'].webassets_env
    content_dir = webassets_env.directory
    os.makedirs(content_dir)
    copytree('h/browser/chrome/content', 'build/chrome/content')
    copytree('h/browser/chrome/help', 'build/chrome/help')
    copytree('h/browser/chrome/images', 'build/chrome/images')
    copytree('h/static/images', 'build/chrome/public/images')

    os.makedirs('build/chrome/lib')

    subprocess_args = ['node_modules/.bin/browserify',
                       'h/browser/chrome/lib/extension.js',
                       '--outfile', 'build/chrome/lib/extension-bundle.js']
    if args.debug:
        subprocess_args.append('--debug')
    subprocess.call(subprocess_args)

    # Render the sidebar html.
    if webassets_env.url.startswith('chrome-extension:'):
        build_extension_common(env, bundle_app=True)
        request = env['request']
        context = {
          'app_config': app_config(request)
        }
        with codecs.open(content_dir + '/app.html', 'w', 'utf-8') as fp:
            data = render('h:templates/app.html.jinja2', context, request)
            fp.write(data)
    else:
        build_extension_common(env)

    # Render the manifest.
    with codecs.open('build/chrome/manifest.json', 'w', 'utf-8') as fp:
        data = chrome_manifest(env['request'])
        fp.write(data)

    # Write build settings to a JSON file
    with codecs.open('build/chrome/settings-data.js', 'w', 'utf-8') as fp:
        fp.write('window.EXTENSION_CONFIG = ' + json.dumps(settings_dict(env)))
示例#6
0
文件: views.py 项目: JJediny/h
def widget(context, request):
    return {
        'app_config': app_config(request)
    }
示例#7
0
文件: views.py 项目: JJediny/h
def embed(context, request):
    request.response.content_type = b'text/javascript'
    return {
        'app_config': app_config(request),
    }