How to use the lookatme.exceptions.IgnoredByContrib function in lookatme

To help you get started, we’ve selected a few lookatme 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 d0c-s4vage / lookatme / lookatme / contrib / file_loader.py View on Github external
def render_code(token, body, stack, loop):
    """Render the code, ignoring all code blocks except ones with the language
    set to ``file``.
    """
    lang = token["lang"] or ""
    if lang != "file":
        raise IgnoredByContrib

    file_info_data = token["text"]
    file_info = FileSchema().loads(file_info_data)

    # relative to the slide source
    if file_info["relative"]:
        base_dir = lookatme.config.SLIDE_SOURCE_DIR
    else:
        base_dir = os.getcwd()

    full_path = os.path.join(base_dir, file_info["path"])
    if not os.path.exists(full_path):
        token["text"] = "File not found"
        token["lang"] = "text"
        raise IgnoredByContrib
github d0c-s4vage / lookatme / examples / calendar_contrib / lookatme / contrib / calendar.py View on Github external
def render_code(token, body, stack, loop):
    lang = token["lang"] or ""
    if lang != "calendar":
        raise IgnoredByContrib()
    
    today = datetime.datetime.utcnow()
    return urwid.Text(calendar.month(today.year, today.month))
github d0c-s4vage / lookatme / lookatme / contrib / __init__.py View on Github external
def inner(*args, **kwargs):
        for mod in CONTRIB_MODULES:
            if not hasattr(mod, fn_name):
                continue
            try:
                return getattr(mod, fn_name)(*args, **kwargs)
            except IgnoredByContrib:
                pass

        return fn(*args, **kwargs)
github d0c-s4vage / lookatme / lookatme / contrib / terminal.py View on Github external
def render_code(token, body, stack, loop):
    lang = token["lang"] or ""

    numbered_term_match = re.match(r'terminal(\d+)', lang)
    if lang != "terminal-ex" and numbered_term_match is None:
        raise IgnoredByContrib

    if numbered_term_match is not None:
        term_data = TerminalExSchema().load({
            "command": token["text"].strip(),
            "rows": int(numbered_term_match.group(1)),
            "init_codeblock": False,
        })

    else:
        term_data = TerminalExSchema().loads(token["text"])

        if term_data["init_text"] is not None and term_data["init_wait"] is not None:
            orig_command = term_data["command"]
            term_data["command"] = " ".join([shlex.quote(x) for x in [
                "expect", "-c", ";".join([
                   'spawn -noecho {}'.format(term_data["command"]),