Template

Note

The documentation in this section is aimed at people wishing to contribute to hubugs, and can be skipped if you are simply using the tool from the command line.

hubugs.template.get_template(group, name)

Fetch a Jinja template instance.

Parameters:
  • group (str) – Template group identifier
  • name (str) – Template name
Return type:

jinja2.environment.Template

Returns:

Jinja template instance

Jinja filter support

hubugs.template.jinja_filter(func)

Simple decorator to add a new filter to Jinja environment.

Parameters:func (func) – Function to add to Jinja environment
Return type:func
Returns:Unmodified function
hubugs.template.colourise(text, formatting)

Colourise text using blessings.

Returns text untouched if colour output is not enabled

See:

blessings

Parameters:
  • text (str) – Text to colourise
  • formatting (str) – Formatting to apply to text
Return type:

str

Returns:

Colourised text, when possible

hubugs.template.highlight(text, lexer='diff', formatter='terminal')

Highlight text with pygments.

Returns text untouched if colour output is not enabled

Parameters:
  • text (str) – Text to highlight
  • lexer (str) – Jinja lexer to use
  • formatter (str) – Jinja formatter to use
Return type:

str

Returns:

Syntax highlighted output, when possible

hubugs.template.html2text(html, width=80, ascii_replacements=False)

HTML to plain text renderer.

Parameters:
  • text (str) – Text to process
  • width (int) – Paragraph width
  • ascii_replacements (bool) – Use psuedo-ascii replacements for Unicode
Return type:

str

Returns:

Rendered text

hubugs.template.relative_time(timestamp)

Format a relative time.

Taken from bleeter. Duplication is evil, I know.

Parameters:timestamp (datetime.datetime) – Event to generate relative timestamp against
Return type:str
Returns:Human readable date and time offset

User interface support

hubugs.template.display_bugs(bugs, order, **extras)

Display bugs to users.

Parameters:
  • bugs (list` of ``models.Issue) – Bugs to display
  • order (str) – Sorting order for displaying bugs
  • extras (dict) – Additional values to pass to templates
Return type:

str

Returns:

Rendered template output

hubugs.template.edit_text(edit_type='default', data=None)

Edit data with external editor.

Parameters:
  • edit_type (str) – Template to use in editor
  • data (dict) – Information to pass to template
Return type:

str

Returns:

User supplied text

Raises:
  • EmptyMessageError – No message given
  • EmptyMessageError – Message not edited