mirror of
https://github.com/checktheroads/hyperglass
synced 2024-05-11 05:55:08 +00:00
fix docstrings
This commit is contained in:
@@ -1,6 +1,4 @@
|
|||||||
"""
|
"""Renders Jinja2 & Sass templates for use by the front end application."""
|
||||||
Renders Jinja2 & Sass templates for use by the front end application
|
|
||||||
"""
|
|
||||||
|
|
||||||
# Project Imports
|
# Project Imports
|
||||||
# flake8: noqa: F401
|
# flake8: noqa: F401
|
||||||
|
@@ -129,11 +129,19 @@ ets/traceroute_nanog.pdf" target="_blank">click here</a>.
|
|||||||
|
|
||||||
|
|
||||||
def generate_markdown(section, file_name=None):
|
def generate_markdown(section, file_name=None):
|
||||||
"""
|
"""Render markdown as HTML.
|
||||||
Renders markdown as HTML. If file_name exists in appropriate
|
|
||||||
directory, it will be imported and used. If not, the default values
|
Arguments:
|
||||||
will be used. Also renders the Front Matter values within each
|
section {str} -- Section name
|
||||||
template.
|
|
||||||
|
Keyword Arguments:
|
||||||
|
file_name {str} -- Markdown file name (default: {None})
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
HyperglassError: Raised if YAML front matter is unreadable
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
{dict} -- Frontmatter dictionary
|
||||||
"""
|
"""
|
||||||
if section == "help":
|
if section == "help":
|
||||||
file = working_directory.joinpath("templates/info/help.md")
|
file = working_directory.joinpath("templates/info/help.md")
|
||||||
@@ -188,13 +196,22 @@ def generate_markdown(section, file_name=None):
|
|||||||
|
|
||||||
|
|
||||||
def render_html(template_name, **kwargs):
|
def render_html(template_name, **kwargs):
|
||||||
"""Render Jinja2 HTML templates."""
|
"""Render Jinja2 HTML templates.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
template_name {str} -- Jinja2 template name
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
HyperglassError: Raised if template is not found
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
{str} -- Rendered template
|
||||||
|
"""
|
||||||
details_name_list = ["footer", "bgp_aspath", "bgp_community"]
|
details_name_list = ["footer", "bgp_aspath", "bgp_community"]
|
||||||
details_dict = {}
|
details_dict = {}
|
||||||
for details_name in details_name_list:
|
for details_name in details_name_list:
|
||||||
details_data = generate_markdown("details", details_name)
|
details_data = generate_markdown("details", details_name)
|
||||||
details_dict.update({details_name: details_data})
|
details_dict.update({details_name: details_data})
|
||||||
info_list = ["bgp_route", "bgp_aspath", "bgp_community", "ping", "traceroute"]
|
|
||||||
rendered_help = generate_markdown("help")
|
rendered_help = generate_markdown("help")
|
||||||
log.debug(rendered_help)
|
log.debug(rendered_help)
|
||||||
try:
|
try:
|
||||||
|
@@ -26,10 +26,7 @@ env = jinja2.Environment(
|
|||||||
|
|
||||||
|
|
||||||
def render_frontend_config():
|
def render_frontend_config():
|
||||||
"""
|
"""Render user config to JSON for use by frontend."""
|
||||||
Renders user config to JSON file so front end config can be used by
|
|
||||||
Javascript
|
|
||||||
"""
|
|
||||||
rendered_frontend_file = hyperglass_root.joinpath("static/src/js/frontend.json")
|
rendered_frontend_file = hyperglass_root.joinpath("static/src/js/frontend.json")
|
||||||
try:
|
try:
|
||||||
with rendered_frontend_file.open(mode="w") as frontend_file:
|
with rendered_frontend_file.open(mode="w") as frontend_file:
|
||||||
@@ -48,7 +45,7 @@ def render_frontend_config():
|
|||||||
|
|
||||||
|
|
||||||
def get_fonts():
|
def get_fonts():
|
||||||
"""Downloads google fonts"""
|
"""Download Google fonts."""
|
||||||
font_dir = hyperglass_root.joinpath("static/src/sass/fonts")
|
font_dir = hyperglass_root.joinpath("static/src/sass/fonts")
|
||||||
font_bin = str(
|
font_bin = str(
|
||||||
hyperglass_root.joinpath("static/src/node_modules/get-google-fonts/cli.js")
|
hyperglass_root.joinpath("static/src/node_modules/get-google-fonts/cli.js")
|
||||||
@@ -77,7 +74,7 @@ def get_fonts():
|
|||||||
|
|
||||||
|
|
||||||
def render_theme():
|
def render_theme():
|
||||||
"""Renders Jinja2 template to Sass file"""
|
"""Render Jinja2 template to Sass file."""
|
||||||
rendered_theme_file = hyperglass_root.joinpath("static/src/sass/theme.sass")
|
rendered_theme_file = hyperglass_root.joinpath("static/src/sass/theme.sass")
|
||||||
try:
|
try:
|
||||||
template = env.get_template("templates/theme.sass.j2")
|
template = env.get_template("templates/theme.sass.j2")
|
||||||
@@ -92,7 +89,7 @@ def render_theme():
|
|||||||
|
|
||||||
|
|
||||||
def build_assets():
|
def build_assets():
|
||||||
"""Builds, bundles, and minifies Sass/CSS/JS web assets"""
|
"""Build, bundle, and minify Sass/CSS/JS web assets."""
|
||||||
proc = subprocess.Popen(
|
proc = subprocess.Popen(
|
||||||
["yarn", "--silent", "--emoji", "false", "--json", "--no-progress", "build"],
|
["yarn", "--silent", "--emoji", "false", "--json", "--no-progress", "build"],
|
||||||
cwd=hyperglass_root.joinpath("static/src"),
|
cwd=hyperglass_root.joinpath("static/src"),
|
||||||
@@ -116,10 +113,7 @@ def build_assets():
|
|||||||
|
|
||||||
|
|
||||||
def render_assets():
|
def render_assets():
|
||||||
"""
|
"""Run web asset rendering functions."""
|
||||||
Controller function for rendering sass theme elements and building
|
|
||||||
web assets
|
|
||||||
"""
|
|
||||||
try:
|
try:
|
||||||
log.debug("Rendering front end config...")
|
log.debug("Rendering front end config...")
|
||||||
render_frontend_config()
|
render_frontend_config()
|
||||||
|
Reference in New Issue
Block a user