How to use the publ.utils.static_url function in Publ

To help you get started, we’ve selected a few Publ examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PlaidWeb / Publ / tests / test_utils.py View on Github external
def test_static_url():
    """ tests for the static URL builder """
    app = flask.Flask("tests", static_folder="asdf")
    with app.test_request_context("https://foo.bar/poiupoiupoiu"):
        assert utils.static_url("thing", absolute=False) == "/asdf/thing"
        assert utils.static_url("thong", absolute=True) == "https://foo.bar/asdf/thong"
github PlaidWeb / Publ / publ / image.py View on Github external
out_args['quality'] = kwargs['quality']
        if ext in ('.jpg', '.jpeg'):
            out_args['optimize'] = True

        # Build the output filename
        out_basename = '_'.join([str(s) for s in out_spec]) + ext
        out_rel_path = os.path.join(
            config.image_output_subdir,
            self._record.checksum[0:2],
            self._record.checksum[2:6],
            out_basename)
        out_fullpath = os.path.join(config.static_folder, out_rel_path)

        if os.path.isfile(out_fullpath):
            os.utime(out_fullpath)
            return utils.static_url(out_rel_path, kwargs.get('absolute')), size

        LocalImage.thread_pool().submit(
            self._render, out_fullpath, size, box, flatten, kwargs, out_args)

        return flask.url_for('async', filename=out_rel_path, _external=kwargs.get('absolute')), size
github PlaidWeb / Publ / publ / links.py View on Github external
def resolve(path: str, search_path: typing.Tuple[str, ...], absolute: bool = False) -> str:
    """ Remap a link or source target to an appropriate entry or image rendition """

    # Resolve external URLs
    if re.match(r'([a-z][a-z0-9+.\-]*:)?//', path, re.I):
        return path

    # Resolve static assets
    if path.startswith('@'):
        return utils.static_url(path[1:], absolute)

    path, sep, anchor = path.partition('#')

    # Resolve entries
    found = find_entry(path, search_path)
    if found:
        return entry.Entry.load(found).permalink(absolute=absolute) + sep + anchor

    # Resolve images and assets
    img_path, img_args, _ = image.parse_image_spec(path)
    img = image.get_image(img_path, search_path)
    if not isinstance(img, image.ImageNotFound):
        path, _ = img.get_rendition(**{**img_args, 'absolute': absolute})

    # We don't know what this is, so just treat it like a normal URL.
    if absolute:
github PlaidWeb / Publ / publ / image / local.py View on Github external
max_height -- the maximum height
        resize -- how to fit the width and height; "fit", "fill", or "stretch"
        fill_crop_x -- horizontal offset fraction for resize="fill"
        fill_crop_y -- vertical offset fraction for resize="fill"
        format -- output format
        background -- background color when converting transparent to opaque
        quality -- the JPEG quality to save the image as
        quantize -- how large a palette to use for GIF or PNG images
        """
        out_rel_path, size, pending = self._get_rendition(output_scale, **kwargs)

        if pending:
            return flask.url_for('async',
                                 filename=out_rel_path,
                                 _external=kwargs.get('absolute')), size
        return utils.static_url(out_rel_path, kwargs.get('absolute')), size
github PlaidWeb / Publ / publ / image.py View on Github external
def _get_url(self, absolute):
        return utils.static_url(self.path, absolute)
github PlaidWeb / Publ / publ / __init__.py View on Github external
self.add_url_rule('/_', 'chit', rendering.render_transparent_chit)

        self.add_url_rule('/_file/',
                          'asset', rendering.retrieve_asset)

        self.add_url_rule('/_token', 'token', tokens.token_endpoint, methods=['POST'])

        self.config['TRAP_HTTP_EXCEPTIONS'] = True
        self.register_error_handler(
            werkzeug.exceptions.HTTPException, rendering.render_exception)

        self.jinja_env.globals.update(  # pylint: disable=no-member
            get_view=view.get_view,
            arrow=arrow,
            static=utils.static_url,
            get_template=rendering.get_template,
            login=utils.auth_link('login'),
            logout=utils.auth_link('logout'),
            token_endpoint=utils.CallableProxy(lambda: utils.secure_link('token')),
            secure_url=utils.secure_link,
        )

        self.jinja_env.filters['strip_html'] = html_entry.strip_html  # pylint: disable=no-member

        caching.init_app(self, self.publ_config.cache)

        self.authl = authl.flask.AuthlFlask(self, self.publ_config.auth,
                                            login_path='/_login',
                                            login_name='login',
                                            callback_path='/_cb',
                                            tester_path='/_ct',