# Path: templar/exceptions.py
# class TemplarError(Exception):
#     """Top-level exception for Templar."""
#     pass


from templar.exceptions import TemplarError
import os
import re

    # Process the block's file if it hasn't been processed before.
    if not block_map.has_block(filename, block_name):
        with open(filename, 'r') as f:
            content = f.read()
        convert_lines_to_block(content.splitlines(), block_map, link_stack, filename)

    # If the block is not in the map even after converting, then the block doesn't exist.
    if not block_map.has_block(filename, block_name):
        raise IncludeNonExistentBlock(
            source_path + ' tried to include a non-existent block: ' + filename + ':' + block_name)

    link_stack.pop()
    # Convert the Block to a string and indent.
    return indent(str(block_map.get_block(filename, block_name)), leading_whitespace)


def indent(content, whitespace):
    lines = content.splitlines()
    indented_lines = map(lambda line: whitespace + line, lines)
    return '\n'.join(indented_lines)


##############
# Exceptions #
##############

class InvalidBlockName(TemplarError):
    pass


# Path: templar/exceptions.py
# class TemplarError(Exception):
#     """Top-level exception for Templar."""
#     pass


# Path: templar/linker.py
from templar.exceptions import TemplarError
import os
import re


    # Process the block's file if it hasn't been processed before.
    if not block_map.has_block(filename, block_name):
        with open(filename, 'r') as f:
            content = f.read()
        convert_lines_to_block(content.splitlines(), block_map, link_stack, filename)

    # If the block is not in the map even after converting, then the block doesn't exist.
    if not block_map.has_block(filename, block_name):
        raise IncludeNonExistentBlock(
            source_path + ' tried to include a non-existent block: ' + filename + ':' + block_name)

    link_stack.pop()
    # Convert the Block to a string and indent.
    return indent(str(block_map.get_block(filename, block_name)), leading_whitespace)


def indent(content, whitespace):
    lines = content.splitlines()
    indented_lines = map(lambda line: whitespace + line, lines)
    return '\n'.join(indented_lines)


##############
# Exceptions #
##############

class InvalidBlockName(TemplarError):
    pass


class IncludeNonExistentBlock(TemplarError):