# Path: side_menu.py
# MENU_ITEMS = [
#     {'name': 'Home', 'page': {'template': 'index.html', 'cpp': None}},
#     {'name': 'Data Types', 'page': None},
#     {'name': 'Primitives', 'page': {'template': 'primitives.html', 'cpp': 'primitives.cpp', 'rust': 'primitives.rs', 'java': 'Primitives.java'}},
#     {'name': 'Classes & Structs', 'page': {'template': 'class_struct.html', 'cpp': 'class_struct.cpp', 'rust': 'class_struct.rs', 'java': 'MyClass.java'}},
#     {'name': 'Interfaces', 'page': {'template': 'interfaces.html', 'cpp': 'interfaces.cpp', 'rust': 'interfaces.rs', 'java': 'Interfaces.java'}},
#     {'name': 'Enums', 'page': {'template': 'enums.html', 'cpp': 'enum.cpp', 'rust': 'enum.rs', 'java': 'Enum.java'}},
#     {'name': 'Generics', 'page': {'template': 'generics.html', 'cpp': 'generics.cpp', 'rust': 'generics.rs', 'java': 'Generics.java'}},
# 
#     {'name': 'Functions', 'page': None},
#     {'name': 'Parameters', 'page': {'template': 'params.html', 'cpp': 'params.cpp', 'rust': 'params.rs', 'java': 'Params.java'}},
#     {'name': 'Lambdas & Closures', 'page': {'template': 'lambdas.html', 'cpp': 'lambda.cpp', 'rust': 'lambda.rs', 'java': 'Lambda.java'}},
# 
#     {'name': 'Control Flow', 'page': None},
#     {'name': 'Branches', 'page': {'template': 'branches.html', 'cpp': 'branches.cpp', 'rust': 'branches.rs', 'java': 'Branches.java'}},
#     {'name': 'Loops', 'page': {'template': 'loops.html', 'cpp': 'loops.cpp', 'rust': 'loops.rs', 'java': 'Loops.java'}},
#     {'name': 'Exceptions', 'page': {'template': 'exceptions.html', 'cpp': 'exceptions.cpp', 'rust': 'exceptions.rs', 'java': 'Exceptions.java'}},
# 
#     {'name': 'Memory', 'page': None},
#     {'name': 'Stack & Heap', 'page': {'template': 'stack_heap.html', 'cpp': 'stack_heap.cpp', 'rust': 'stack_heap.rs', 'java': 'StackHeap.java'}},
#     {'name': 'Pointers & References', 'page': {'template': 'pointers.html', 'cpp': 'pointers.cpp', 'rust': 'pointers.rs', 'java': 'Pointers.java'}},
# 
#     {'name': 'Containers', 'page': None},
#     {'name': 'Vector & List', 'page': {'template': 'vectors.html', 'cpp': 'vectors.cpp', 'rust': 'vectors.rs', 'java': 'Vectors.java'}},
#     {'name': 'Set & Map', 'page': {'template': 'map_set.html', 'cpp': 'map_set.cpp', 'rust': 'map_set.rs', 'java': 'MapSet.java'}},
# ]


from jinja2 import Environment, FileSystemLoader
from side_menu import MENU_ITEMS
import re
    ret = []
    add_line = False
    ws_count = -1

    with open(file_name, 'r') as f:
        for line in f:
            if '// END_CODE' in line:
                break

            if add_line:
                line = line.replace(r' {3,8}', '\t')
                line = line.replace('\t', '  ')

                if ws_count == -1:
                    ws_count = re.search(r'[\S]', line).start()
                ret.append(line[ws_count:] if len(line) >= ws_count else line)

            if '// BEGIN_CODE' in line:
                add_line = True

    if len(ret) == 0:
        print "Error did not read any code from %s. Make sure you have a BEGIN_CODE marker" % file_name

    return ret


env = Environment(loader=FileSystemLoader('templates'))
env.autoescape = True

# go through and "fix-up" MENU_ITEMS

# Path: side_menu.py
# MENU_ITEMS = [
#     {'name': 'Home', 'page': {'template': 'index.html', 'cpp': None}},
#     {'name': 'Data Types', 'page': None},
#     {'name': 'Primitives', 'page': {'template': 'primitives.html', 'cpp': 'primitives.cpp', 'rust': 'primitives.rs', 'java': 'Primitives.java'}},
#     {'name': 'Classes & Structs', 'page': {'template': 'class_struct.html', 'cpp': 'class_struct.cpp', 'rust': 'class_struct.rs', 'java': 'MyClass.java'}},
#     {'name': 'Interfaces', 'page': {'template': 'interfaces.html', 'cpp': 'interfaces.cpp', 'rust': 'interfaces.rs', 'java': 'Interfaces.java'}},
#     {'name': 'Enums', 'page': {'template': 'enums.html', 'cpp': 'enum.cpp', 'rust': 'enum.rs', 'java': 'Enum.java'}},
#     {'name': 'Generics', 'page': {'template': 'generics.html', 'cpp': 'generics.cpp', 'rust': 'generics.rs', 'java': 'Generics.java'}},
# 
#     {'name': 'Functions', 'page': None},
#     {'name': 'Parameters', 'page': {'template': 'params.html', 'cpp': 'params.cpp', 'rust': 'params.rs', 'java': 'Params.java'}},
#     {'name': 'Lambdas & Closures', 'page': {'template': 'lambdas.html', 'cpp': 'lambda.cpp', 'rust': 'lambda.rs', 'java': 'Lambda.java'}},
# 
#     {'name': 'Control Flow', 'page': None},
#     {'name': 'Branches', 'page': {'template': 'branches.html', 'cpp': 'branches.cpp', 'rust': 'branches.rs', 'java': 'Branches.java'}},
#     {'name': 'Loops', 'page': {'template': 'loops.html', 'cpp': 'loops.cpp', 'rust': 'loops.rs', 'java': 'Loops.java'}},
#     {'name': 'Exceptions', 'page': {'template': 'exceptions.html', 'cpp': 'exceptions.cpp', 'rust': 'exceptions.rs', 'java': 'Exceptions.java'}},
# 
#     {'name': 'Memory', 'page': None},
#     {'name': 'Stack & Heap', 'page': {'template': 'stack_heap.html', 'cpp': 'stack_heap.cpp', 'rust': 'stack_heap.rs', 'java': 'StackHeap.java'}},
#     {'name': 'Pointers & References', 'page': {'template': 'pointers.html', 'cpp': 'pointers.cpp', 'rust': 'pointers.rs', 'java': 'Pointers.java'}},
# 
#     {'name': 'Containers', 'page': None},
#     {'name': 'Vector & List', 'page': {'template': 'vectors.html', 'cpp': 'vectors.cpp', 'rust': 'vectors.rs', 'java': 'Vectors.java'}},
#     {'name': 'Set & Map', 'page': {'template': 'map_set.html', 'cpp': 'map_set.cpp', 'rust': 'map_set.rs', 'java': 'MapSet.java'}},
# ]


# Path: build.py
from jinja2 import Environment, FileSystemLoader
from side_menu import MENU_ITEMS
import re

    ret = []
    add_line = False
    ws_count = -1

    with open(file_name, 'r') as f:
        for line in f:
            if '// END_CODE' in line:
                break

            if add_line:
                line = line.replace(r' {3,8}', '\t')
                line = line.replace('\t', '  ')

                if ws_count == -1:
                    ws_count = re.search(r'[\S]', line).start()
                ret.append(line[ws_count:] if len(line) >= ws_count else line)

            if '// BEGIN_CODE' in line:
                add_line = True

    if len(ret) == 0:
        print "Error did not read any code from %s. Make sure you have a BEGIN_CODE marker" % file_name

    return ret


env = Environment(loader=FileSystemLoader('templates'))
env.autoescape = True

# go through and "fix-up" MENU_ITEMS

for item in list(MENU_ITEMS):