How to use the branca.element.Link function in branca

To help you get started, we’ve selected a few branca 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 python-visualization / branca / branca / element.py View on Github external
def to_dict(self, depth=-1, **kwargs):
        """Returns a dict representation of the object."""
        out = super(Link, self).to_dict(depth=-1, **kwargs)
        out['url'] = self.url
        return out
github python-visualization / branca / branca / element.py View on Github external
class Link(Element):
    """An abstract class for embedding a link in the HTML."""
    def get_code(self):
        """Opens the link and returns the response's content."""
        if self.code is None:
            self.code = urlopen(self.url).read()
        return self.code

    def to_dict(self, depth=-1, **kwargs):
        """Returns a dict representation of the object."""
        out = super(Link, self).to_dict(depth=-1, **kwargs)
        out['url'] = self.url
        return out


class JavascriptLink(Link):
    """Create a JavascriptLink object based on a url.

    Parameters
    ----------
    url : str
        The url to be linked
    download : bool, default False
        Whether the target document shall be loaded right now.

    """
    _template = Template(
        '{% if kwargs.get("embedded",False) %}'
        ''
        '{% else %}'
        ''
        '{% endif %}'
github python-visualization / branca / branca / element.py View on Github external
''
        '{% else %}'
        ''
        '{% endif %}'
    )

    def __init__(self, url, download=False):
        super(JavascriptLink, self).__init__()
        self._name = 'JavascriptLink'
        self.url = url
        self.code = None
        if download:
            self.get_code()


class CssLink(Link):
    """Create a CssLink object based on a url.

    Parameters
    ----------
    url : str
        The url to be linked
    download : bool, default False
        Whether the target document shall be loaded right now.

    """
    _template = Template(
        '{% if kwargs.get("embedded",False) %}'
        '<style>{{this.get_code()}}</style>'
        '{% else %}'
        ''
        '{% endif %}'