コード例 #1
0
def main(config_file, source_dir):
    config = get_toc(config_file)
    result = {}

    lessons = config['lessons']
    figure = 1
    for (i, slug) in enumerate(lessons):
        key = str(i + 1)
        result['s:{}'.format(slug)] = {
            'slug': slug,
            'text': 'Chapter',
            'value': key
        }
        figure = process(result, source_dir, slug, key, figure)

    extras = config['extras']
    letters = ascii_uppercase[:len(extras)]
    for (key, slug) in zip(letters, extras):
        result['s:{}'.format(slug)] = {
            'slug': slug,
            'text': 'Appendix',
            'value': key
        }
        figure = process(result, source_dir, slug, key, figure)

    language = source_dir.lstrip('_')
    json.dump(result, sys.stdout)
コード例 #2
0
def main(language):
    config = get_toc()
    source_dir = '_{}'.format(language)
    result = {}

    lessons = config['lessons']
    counters = {'figure': 1, 'table': 1}
    for (i, slug) in enumerate(lessons):
        key = str(i+1)
        result['s:{}'.format(slug)] = {
            'slug': slug,
            'text': 'Chapter',
            'value': key
        }
        process(result, source_dir, slug, key, counters)

    extras = config['extras']
    letters = ascii_uppercase[:len(extras)]
    for (key, slug) in zip(letters, extras):
        result['s:{}'.format(slug)] = {
            'slug': slug,
            'text': 'Appendix',
            'value': key
        }
        process(result, source_dir, slug, key, counters)

    json.dump(result, sys.stdout)
コード例 #3
0
ファイル: check.py プロジェクト: dralastaircurrie/js-vs-ds
def check_toc(language):
    '''
    Check that filenames in configuration match actual files.
    '''
    toc = get_toc()
    defined = {slug for section in toc for slug in toc[section]}
    defined.add('index')
    actual = {
        filename.replace('.md', '')
        for filename in os.listdir(PROSE_DIR_FMT.format(language))
        if not _ignore_file(filename)
    }
    report('Table of Contents', 'unused', actual - defined)
    report('Table of Contents', 'missing', defined - actual)
コード例 #4
0
def get_all(config_file, source_dir):
    '''
    Get all lines from input files, inserting a few markers for post-processing.
    '''

    toc = get_toc(config_file)

    print('==frontmatter==\n')
    with open(os.path.join(source_dir, 'index.html')) as reader:
        get_main_div(reader)

    print('==mainmatter==\n')
    for filename in make_filenames(source_dir, toc['lessons']):
        with open(filename, 'r') as reader:
            get_main_div(reader)

    print('==midpoint==\n')
    for filename in make_filenames(source_dir, toc['extras']):
        with open(filename, 'r') as reader:
            get_main_div(reader)