def test_empty_function_block(): spaced = trim(""" COMPACT --- --- """) unspaced = trim(""" COMPACT --- --- """) blocks = BlockList(spaced) assert blocks.text() == unspaced blocks = BlockList(unspaced) assert blocks.text() == unspaced
def test_empty_blocklist(): "Test function block with zero lines" text = trim(""" TEXT --- Hi! --- """) blocks = BlockList(text) assert class_list(blocks) == ['FunctionBlock'] assert blocks.text() == text
def test_pop_titles_oneline(): """ We should be able to extract the title and summary lines. """ text = trim(""" Title """) blocks = BlockList(text) title, summary = blocks.pop_titles() assert title == "Title" assert summary == "" assert blocks.text() == ""
def test_nested_blocklist(): "Test function block with zero lines" text = trim(""" LEFT (35%) --- TEXT === Hi! === --- """) blocks = BlockList(text) assert class_list(blocks) == ['FunctionBlock'] subclass_list = [ _.__class__.__name__ for _ in list(iter(blocks))[0].blocks ] assert subclass_list == ['FunctionBlock'] assert blocks.text() == text
def reformat_part(slug, part): """ Normalise the layout of user-entered text. Remove bibliography and Demo blocks, process as a Blocklist, then put them back. """ if slug == 'biblio': return part else: content, bibliography = split_bibliography(clean_text(part)) demo_placeholders = Demo(Settings()) parts_sans_demo_blocks = demo_placeholders.insert({slug: content}) blocks = BlockList(parts_sans_demo_blocks[slug]) out_sans_demo_blocks = blocks.text() out_parts = demo_placeholders.replace({slug: out_sans_demo_blocks}, lambda text, slug: text) out = out_parts[slug] if bibliography: out += "\n\n\n_____\n\n" + bibliography return out
def user_page(user_slug): """ Show <user_slug>/fixtures/author + user documents. """ header_buttons = [login_or_logout_button()] login = get_login() if login and login['username'] == user_slug: header_buttons += [ new_article_button(user_slug), ] header_buttons += [ edit_button(user_slug, 'fixtures', 'author'), ] if not login: header_buttons += [subscribe_button(), rss_button(user_slug)] footer_buttons = [] if config['ARTICLE_WIKI_CREDIT'] == 'YES': footer_buttons += [source_button()] footer_buttons += [help_button()] if has_authority_for_user(user_slug): footer_buttons += [export_archive_button(user_slug)] slugs = data.userDocumentSet_list(user_slug) changes_list = data.userDocumentLastChanged_list(user_slug) if not has_authority_for_user(user_slug): # Show only those that have been published changes_list, __ = split_published(changes_list) article_slugs = [_ for _ in slugs if _ not in ['fixtures', 'templates']] article_keys = [ data.userDocumentMetadata_key(user_slug, _) for _ in article_slugs ] article_list = sorted(data.get_hashes(article_keys), key=lambda _: _.get('title', '')) published_articles, unpublished_articles = split_published(article_list) if not has_authority_for_user(user_slug): unpublished_articles = [] settings = Settings({ 'config:host': domain_name(bottle.request), 'config:user': user_slug, 'config:document': 'fixtures', }) wiki = Wiki(settings) document = data.userDocument_get(user_slug, 'fixtures') if not document: msg = "User '{:s}' not found." bottle.abort(HTTP_NOT_FOUND, msg.format(user_slug)) if 'author' in document: text = document['author'] else: text = trim(""" Author Page (Author information to be added here...) """) blocks = BlockList(clean_text(text)) page_title, page_summary = blocks.pop_titles() content_html = wiki.process(None, None, {'index': blocks.text()}, fragment=True, preview=True) inline = Inline() return views.get_template('user.html').render( config=config, user=user_slug, page_title="{:s} - {:s}".format(page_title, page_summary), title_html=inline.process(page_title), summary_html=inline.process(page_summary), header_buttons=header_buttons, footer_buttons=footer_buttons, changes_list=changes_list, published_articles=published_articles, unpublished_articles=unpublished_articles, content_html=content_html, pluralize=pluralize # <-- hack function injection )
def test_blocklist(): "List of blocks..." # 1 text = trim(""" @ Heading Paragraph - - - Paragraph TEXT (verse) --- Text --- Paragraph TEXT --- Text --- """) blocks = BlockList(text) assert class_list(blocks) == [ 'CharacterBlock', 'Paragraph', 'Divider', 'Paragraph', 'FunctionBlock', 'Paragraph', 'FunctionBlock', ] assert blocks.text() == "\n" + text # 2 text = trim(""" TEXT --- Text --- @ Heading Paragraph - - - Paragraph TEXT (verse) --- Text --- Paragraph """) blocks = BlockList(text) assert class_list(blocks) == [ 'FunctionBlock', 'CharacterBlock', 'Paragraph', 'Divider', 'Paragraph', 'FunctionBlock', 'Paragraph', ] assert blocks.text() == text