Skip to content

Commit

Permalink
tidy up and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ebeahan committed Jun 4, 2020
1 parent 7e7b25c commit 140d7b1
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions scripts/generators/asciidoc_fields.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from functools import wraps
import os.path as path
from generators import ecs_helpers

import jinja2

from generators import ecs_helpers

# jinja2 setup
TEMPLATE_DIR = path.join(path.dirname(path.abspath(__file__)), 'templates')
template_loader = jinja2.FileSystemLoader(searchpath=TEMPLATE_DIR)
Expand All @@ -18,6 +19,10 @@ def generate(intermediate_nested, ecs_version, out_dir):
# Helpers

def templated(template_name):
"""Decorator function to simplify rendering a template.
::param template_name: the name of the template to be rendered
"""
def decorator(func):
@wraps(func)
def decorated_function(*args, **kwargs):
Expand All @@ -28,6 +33,13 @@ def decorated_function(*args, **kwargs):


def render_template(template_name, **context):
"""Renders a template from the template folder with the given
context.
:param template_name: the name of the template to be rendered
:param context: the variables that should be available in the
context of the template.
"""
template = template_env.get_template(template_name)
return template.render(**context)

Expand Down Expand Up @@ -74,7 +86,7 @@ def render_fieldset(fieldset, intermediate_nested):

def render_fields(fields):
text = ''
for field_name, field in sorted(fields.items()):
for _, field in sorted(fields.items()):
# Skip fields nested in this field set
if 'field_details' in field and 'original_fieldset' not in field['field_details']:
text += render_field_details_row(field['field_details'])
Expand All @@ -83,11 +95,6 @@ def render_fields(fields):
return text


def render_asciidoc_paragraphs(string):
'''Simply double the \n'''
return string.replace("\n", "\n\n")


def render_field_allowed_values(field):
if not 'allowed_values' in field:
return ''
Expand Down

0 comments on commit 140d7b1

Please sign in to comment.