Switch to using docstrings for the function documentation

This commit is contained in:
Juhani Krekelä 2018-04-21 23:30:49 +03:00
parent 759e160e25
commit 7c423448aa
2 changed files with 14 additions and 15 deletions

View File

@ -1,8 +1,7 @@
import configparser
# load(filename)
# Populate the config variables
def load(filename):
"""Populate the config variables"""
global port, ssl, url_prefix
global site_name

View File

@ -4,8 +4,8 @@ import bs4
import config
# generate_nav(*, soup) → nav_tag
def generate_nav(*, soup):
"""Returns nav_tag"""
# TODO: Don't generate link to a board if we're at the index
nav_tag = soup.new_tag('nav')
@ -17,8 +17,8 @@ def generate_nav(*, soup):
return nav_tag
# generate_header(*, page_title, soup) → header_tag
def generate_header(*, page_title, soup):
"""Returns header_tag"""
header_tag = soup.new_tag('header')
h1_tag = soup.new_tag('h1')
@ -27,15 +27,15 @@ def generate_header(*, page_title, soup):
return header_tag
# generate_footer(*, soup) → footer_tag
def generate_footer(*, soup):
"""Returns footer_tag"""
# TODO: Add footer generation
return soup.new_tag('footer')
# page_skeleton(*, page_title, contents, soup) → html
# Given page title (string) and contents (iteratable of beautifulsoup tags), create the html
# Since most pages have same basic structure, it makes sense to factor this out from page creation functions
def page_skeleton(*, page_title, contents, soup):
"""Returns html
Given page title (string) and contents (iteratable of beautifulsoup tags), create the html
Since most pages have same basic structure, it makes sense to factor this out from page creation functions"""
# Doctype and head are more or less the same for each page, no need to do anything fancy when adding them
soup.append(bs4.Doctype('html'))
@ -63,18 +63,18 @@ def page_skeleton(*, page_title, contents, soup):
# We are probably never going to serve enough pages for the additional whitespace to count for data usage
return soup.prettify()
# new_soup() → soup
# Since we need a soup object to create tags, split this from page_skeleton
def new_soup():
"""Returns soup
Since we need a soup object to create tags, split this from page_skeleton"""
# Use python's built-in parser for portability
# We'll be constructing the document programmatically, so start with empty tree
soup = bs4.BeautifulSoup('', 'html.parser')
return soup
# board() → html
# Creates the board index page
def board(board_name):
"""Returns html
Creates the board index page"""
# TODO: Creae a board index page
soup = new_soup()
@ -82,15 +82,15 @@ def board(board_name):
return page_skeleton(page_title = page_title, contents = [], soup = soup)
# index() → html
# Create the site index
def index():
"""Returns html
Create the site index"""
# TODO: Create an index page
soup = new_soup()
return page_skeleton(page_title = config.site_name, contents = [], soup = soup)
# error_404(path) → html
def error_404(path):
"""Returns html"""
soup = new_soup()
p_tag = soup.new_tag('p')