pycharmers.utils.templates module

pycharmers.utils.templates.render_template(template_name_or_string, context={}, path=None, searchpath='/Users/iwasakishuto/Github/portfolio/Python-Charmers/pycharmers/templates', **envkwargs)[source]

Render Template.

Parameters
  • template_name_or_string (str) – The name of the template to be rendered or a string.

  • context (dict) – The variables that should be available in the context of the template.

  • path (str) – If given, output to path file.

  • searchpath (str) – (Default= TEMPLATES_DIR )

Examples

>>> import matplotlib
>>> from pycharmers.utils import render_template
>>> render_template(
...     template_name_or_string="fonts.html",
...     context={"fonts": sorted(set([f.name for f in matplotlib.font_manager.fontManager.ttflist]))}
>>> )
class pycharmers.utils.templates.defFunction(func_name, short_description='', description='', is_method=False)[source]

Bases: object

set_example(prefix='', suffix='')[source]
set_returns(name, type, description='')[source]
sort_arguments()[source]
set_argument(name, default, example=None, description='', type=<class 'str'>, is_required=True, **kwargs)[source]
set_arguments(**arguments)[source]
create()[source]
pycharmers.utils.templates.base_html()

Return the path to TEMPLATES_DIR/base.html

Returns

Where this file is.

Return type

str

The contents of the file are as follows:

{%- if add_base -%}
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="twitter:card" content="summary" />
    <meta name="twitter:site" content="@cabernet_rock" />
    <meta name="twitter:image:src" content="https://iwasakishuto.github.io/images/FacebookImage/Python-Charmers.png">
    <meta property="og:url" content="https://github.com/iwasakishuto/Python-Charmers" />
    <meta property="og:site_name" content="Python-Charmers" />
    <meta property="og:title" content="Python-Charmers" />
    <meta property="og:description" content="Translation Gummy is a collection of useful python programs." />
    <meta property="og:image" content="https://github.com/iwasakishuto/Python-Charmers/blob/master/image/header.png?raw=true" />
    <title>{% block title %}{{ SITENAME|striptags|e }}{% endblock title %}</title>
    <link rel="shortcut icon" href="https://iwasakishuto.github.io/images/apple-touch-icon/Python-Charmers.png"/>
    <link rel="apple-touch-icon" href="https://iwasakishuto.github.io/images/apple-touch-icon/Python-Charmers.png" sizes="152x152">
    {% include 'style.html' %}
  </head>
  <body>
{%- endif -%}
    {%- block content %}
    {%- endblock %}
{%- if add_base -%}
  </body>
</html>
{%- endif -%}

Examples

>>> from pycharmers.utils.templates import base_html
>>> base_html()
pycharmers.utils.templates.def_html()

Return the path to TEMPLATES_DIR/def.html

Returns

Where this file is.

Return type

str

The contents of the file are as follows:

{%- if __comment -%}<!--
  arguments={
    argname: {
      type,
      is_required,
      default,
      example_prefix,
      description,
      name_type
    }
  },
  short_description
  description
  is_method



-->{%- endif -%}
{%- from "_macros/utils.html" import pythonalization -%}
def {{ func_name }}(
    {%- if is_method -%}self{%- if arguments|length > 0 %}, {% endif %}{% endif -%}
    {%- for argname,argmeta in arguments.items() -%}
        {{ argname }}{% if not argmeta.is_required %}={{ pythonalization(argmeta.default) }}{% endif %}{% if not loop.last %}, {% endif -%}
    {%- endfor -%}
):
    """{% if short_description and short_description | length > 0 %}{{ short_description }}
    {% endif %}

    {%- if description and description | length > 0 %}
    {{ description }}
    {%- endif %}

    Args:
    {%- for argname,argmeta in arguments.items()%}
        {{ argmeta.name_type.ljust(argwidth) }} : {{ argmeta.description }} {% if argmeta.default %}(default= ``{{ pythonalization(argmeta.default) }}`` ){% endif %}
    {%- endfor %}

    {%- if returns %}

    Returns:
        {{ returns | indent(width=8, first=Faslse) }}
    {%- endif %}

    {%- if examples %}

    Examples:
        {{ example_prefix | indent(width=8, first=Faslse) }}
        {%- for argname,argmeta in arguments.items()%}
        ...     {{ argname }}={{ pythonalization(argmeta.example) }},
        {%- endfor %}
        >>> )
        {{ example_suffix | indent(width=8, first=Faslse) }}
    {%- endif %}
    """

Examples

>>> from pycharmers.utils.templates import def_html
>>> def_html()
pycharmers.utils.templates.fonts_html()

Return the path to TEMPLATES_DIR/fonts.html

Returns

Where this file is.

Return type

str

The contents of the file are as follows:

{% extends 'base.html' %}
{% block title %}All Fonts{% endblock title %}
{%- block content %}
    <h1>Available Fonts</h1>
    <ul>
      {%- for font in fonts %}
      <li>{{ font }}: <span style='font-family:{{ font }}; font-size: 2em;'>{{ font }}</li>
      {%- endfor %}
    </ul>
{%- endblock %}

Examples

>>> from pycharmers.utils.templates import fonts_html
>>> fonts_html()
pycharmers.utils.templates.style_html()

Return the path to TEMPLATES_DIR/style.html

Returns

Where this file is.

Return type

str

The contents of the file are as follows:

<style>
  body {
    font-family: "Times New Roman", "Helvetica Neue", Meiryo, monospace, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, IPAexMincho, "Open Sans", "Helvetica Neue", sans-serif, serif;
    margin: 0;
  }
</style>

Examples

>>> from pycharmers.utils.templates import style_html
>>> style_html()