Exemplo n.º 1
0
def page_view(pagename, foldername=None):
    # If we are in a folder, join its name with the pagename
    if foldername:
        pagename = foldername + '/' + pagename

    # Make a Site with a Footer
    site = Site(**load_yaml('site', base_dir=cwd))
    site.static_dirname = 'static/'  # Don't use Sphinx name

    # Get some globals. Jam them in here so that livereload will get them,
    # slows down requests for development, but that's ok.
    pages = Pages()
    pages.load_pages()

    # Get this page
    page = pages.get(pagename)

    # Make a navbar with site-specific and page-specific data
    navbar = Navbar(**load_yaml('navbar', base_dir=cwd))
    navbar.update(site, page)

    # Make a footer
    footer = Footer(**load_yaml('footer', base_dir=cwd))

    # Make a sidebar...it's either a section_sidebar or per-resource
    sidebar = None
    if page.template in ['section.html', 'reference.html']:
        section_sidebar = load_yaml('section_sidebar', base_dir=cwd)
        sidebar = SectionSidebar(**section_sidebar)
    elif page.template == 'page.html':
        page_sidebar = load_yaml('page_sidebar', base_dir=cwd)
        sidebar = PageSidebar(**page_sidebar)
    elif page.template in ['tutorial.html', 'tutorialpage.html']:
        tutorial_sidebar = load_yaml('tutorial_sidebar', base_dir=cwd)
        sidebar = TutorialSidebar(**tutorial_sidebar)

    try:
        active_category = [
            category
            for category in sidebar.entries
            if category.href[1:-6] in page.docname
        ]
        if active_category:
            active_category[0].is_active = True
    except AttributeError:
        pass

    # Make a context
    context = dict(
        site=site,
        page=page,
        navbar=navbar,
        sidebar=sidebar,
        footer=footer
    )

    return render_template(page.template, **context)
Exemplo n.º 2
0
def context_tutorialpage():
    site_yaml = load_yaml('site', base_dir=sample)
    site = Site(**site_yaml)
    navbar_yaml = load_yaml('navbar', base_dir=sample)
    navbar = Navbar(**navbar_yaml)
    footer_yaml = load_yaml('footer', base_dir=sample)
    footer = Footer(**footer_yaml)
    pages = load_yaml('pages', base_dir=sample)
    page = pages[7]
    tutorialpage = TutorialPage(**pages[7])
    sidebar_yaml = load_yaml('tutorial_sidebar', base_dir=sample)
    sidebar = TutorialSidebar(**sidebar_yaml)
    return dict(site=site, navbar=navbar, page=tutorialpage, sidebar=sidebar,
                footer=footer)
Exemplo n.º 3
0
def context_page():
    site_yaml = load_yaml('site', base_dir=sample)
    site = Site(**site_yaml)
    navbar_yaml = load_yaml('navbar', base_dir=sample)
    navbar = Navbar(**navbar_yaml)
    footer_yaml = load_yaml('footer', base_dir=sample)
    footer = Footer(**footer_yaml)
    pages = load_yaml('pages', base_dir=sample)
    page = Page(**pages[8])
    sidebar_yaml = load_yaml('page_sidebar', base_dir=sample)
    sidebar = PageSidebar(**sidebar_yaml)
    return dict(site=site,
                navbar=navbar,
                footer=footer,
                sidebar=sidebar,
                page=page)
Exemplo n.º 4
0
def context_section():
    site_yaml = load_yaml('site', base_dir=sample)
    site = Site(**site_yaml)
    navbar_yaml = load_yaml('navbar', base_dir=sample)
    navbar = Navbar(**navbar_yaml)
    footer_yaml = load_yaml('footer', base_dir=sample)
    footer = Footer(**footer_yaml)
    pages = load_yaml('pages', base_dir=sample)
    section = Section(**pages[1])
    section_sidebar = load_yaml('section_sidebar', base_dir=sample)
    sidebar = SectionSidebar(**section_sidebar)
    return dict(site=site,
                navbar=navbar,
                page=section,
                sidebar=sidebar,
                footer=footer)
Exemplo n.º 5
0
import inspect
from pathlib import Path

from bulmaio_jinja2.footer.models import Footer
from bulmaio_jinja2.navbar.models import Navbar
from bulmaio_jinja2.sidebar.page.models import PageSidebar
from bulmaio_jinja2.site.models import Site
from bulmaio_jinja2.utils import load_yaml

extensions = ['bulmaio_jinja2']

html_theme = 'bulmaio_jinja2'
master_doc = 'index'
exclude_patterns = ['_build']

# For test purposes, use the "sample" data for site, navbar, etc.
sample = Path(inspect.getfile(Site)).parents[2] / 'bulmaio_jinja2' / 'sample'
site_yaml = load_yaml('site', base_dir=sample)
site = Site(**site_yaml)
navbar_yaml = load_yaml('navbar', base_dir=sample)
navbar = Navbar(**navbar_yaml)
footer_yaml = load_yaml('footer', base_dir=sample)
footer = Footer(**footer_yaml)
sidebar_yaml = load_yaml('page_sidebar', base_dir=sample)
sidebar = PageSidebar(**sidebar_yaml)

bulmaio_jinja2_site = site
bulmaio_jinja2_navbar = navbar
bulmaio_jinja2_footer = footer
bulmaio_jinja2_sidebar = sidebar