How to use the clld.web.util.htmllib.HTML.div function in clld

To help you get started, we’ve selected a few clld 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 clld / clld / tests / test_web_util_htmllib.py View on Github external
def test_HTML():
    from clld.web.util.htmllib import HTML

    assert 'class' in HTML.div(HTML.cdata(), class_='abc')
    assert str(HTML.a()) == '<a></a>'
github clld / clld / clld / web / util / helpers.py View on Github external
def alt_translation(sentence):
        res = ''
        if sentence.jsondata.get('alt_translation'):
            text = sentence.jsondata['alt_translation']
            name = ''
            if ALT_TRANSLATION_LANGUAGE_PATTERN.match(text):
                name, text = [t.strip() for t in text.split(':', 1)]
                name = HTML.span(name + ': ')
            res = HTML.div(name, HTML.span(text, class_='translation'))
        return res
github clld / clld / clld / web / util / helpers.py View on Github external
name = HTML.span(name + ': ')
            res = HTML.div(name, HTML.span(text, class_='translation'))
        return res

    units = []
    if sentence.analyzed and sentence.gloss:
        analyzed = sentence.analyzed
        glossed = sentence.gloss
        for morpheme, gloss in zip(analyzed.split('\t'), glossed.split('\t')):
            units.append(HTML.div(
                HTML.div(morpheme, class_='morpheme'),
                HTML.div(*gloss_with_tooltip(gloss), **{'class': 'gloss'}),
                class_='gloss-unit'))

    return HTML.div(
        HTML.div(
            HTML.div(
                HTML.div(sentence.original_script, class_='original-script')
                if sentence.original_script else '',
                HTML.div(literal(sentence.markup_text or sentence.name),
                         class_='object-language'),
                HTML.div(*units, **{'class': 'gloss-box'}) if units else '',
                HTML.div(sentence.description, class_='translation')
                if sentence.description else '',
                alt_translation(sentence),
                class_='body',
            ),
            class_="sentence",
        ),
        class_="sentence-wrapper",
    )
github clld / clld / src / clld / web / util / helpers.py View on Github external
res = HTML.div(name, HTML.span(text, class_='translation'))
        return res

    units = []
    if sentence.analyzed and sentence.gloss:
        analyzed = sentence.analyzed
        glossed = sentence.gloss
        for morpheme, gloss in zip(analyzed.split('\t'), glossed.split('\t')):
            units.append(HTML.div(
                HTML.div(morpheme, class_='morpheme'),
                HTML.div(*gloss_with_tooltip(gloss), **{'class': 'gloss'}),
                class_='gloss-unit'))

    return HTML.div(
        HTML.div(
            HTML.div(
                HTML.div(sentence.original_script, class_='original-script')
                if sentence.original_script else '',
                HTML.div(literal(sentence.markup_text or sentence.name),
                         class_='object-language'),
                HTML.div(*units, **{'class': 'gloss-box'}) if units else '',
                HTML.div(sentence.description, class_='translation')
                if sentence.description else '',
                alt_translation(sentence),
                class_='body',
            ),
            class_="sentence",
        ),
        class_="sentence-wrapper",
    )
github clld / glottolog3 / glottolog3 / util.py View on Github external
def infobox(*content):
    return HTML.div(
        HTML.button(
            '\xd7', **{'type': "button", 'class': "close", 'data-dismiss': "alert"}),
        *content,
        **{'class': "alert alert-success"})
github clld / clld / clld / web / util / helpers.py View on Github external
def icons(req, param):
    """Create an HTML snippet listing available icons.

    :param req: current request
    :param param: parameter name
    :return: HTML element
    """
    iconlist = req.registry.queryUtility(interfaces.IIconList)
    td = lambda icon: HTML.td(
        marker_img(icon.url(req)),
        onclick='CLLD.reload({"%s": "%s"})' % (param, icon.name))
    rows = [
        HTML.tr(*map(td, icons)) for c, icons in
        groupby(sorted(iconlist, key=lambda i: i.name[1:]), lambda i: i.name[1:])]
    return HTML.div(
        HTML.table(
            HTML.tbody(*rows),
            class_="table table-condensed"
        ),
        button('Close', **{'data-dismiss': 'clickover'}))
github clld / clld / src / clld / web / util / helpers.py View on Github external
"""Create an HTML snippet listing available icons.

    :param req: current request
    :param param: parameter name
    :return: HTML element
    """
    iconlist = req.registry.queryUtility(interfaces.IIconList)

    def td(icon):
        return HTML.td(
            marker_img(icon.url(req)),
            onclick='CLLD.reload({"%s": "%s"})' % (param, icon.name))
    rows = [
        HTML.tr(*map(td, icons)) for c, icons in
        groupby(sorted(iconlist, key=lambda i: i.name[1:]), lambda i: i.name[1:])]
    return HTML.div(
        HTML.table(
            HTML.tbody(*rows),
            class_="table table-condensed"
        ),
        button('Close', **{'data-dismiss': 'clickover'}))
github clld / clld / clld / web / util / helpers.py View on Github external
def rendered_sentence(sentence, abbrs=None, fmt='long'):
    """Format a sentence as HTML."""
    if sentence.xhtml:
        return HTML.div(
            HTML.div(Markup(sentence.xhtml), class_='body'), class_="sentence")

    if abbrs is None:
        q = DBSession.query(models.GlossAbbreviation).filter(
            or_(models.GlossAbbreviation.language_pk == sentence.language_pk,
                models.GlossAbbreviation.language_pk == None)
        )
        abbrs = dict((g.id, g.name) for g in q)

    def gloss_with_tooltip(gloss):
        person_map = {
            '1': 'first person',
            '2': 'second person',
            '3': 'third person',
        }

        res = []