HTML Templating for the Notebook

AUTHORS:

  • Bobby Moretti (2007-07-18): initial version
  • Timothy Clemans and Mike Hansen (2008-10-27): major update
sagenb.notebook.template.clean_name(name)

Converts a string to a safe/clean name by converting non-alphanumeric characters to underscores.

INPUT:

  • name – a string

EXAMPLES:

sage: from sagenb.notebook.template import clean_name
sage: print clean_name('this!is@bad+string')
this_is_bad_string
sagenb.notebook.template.css_escape(string)

Returns a string with all characters not legal in a css name replaced with hyphens (-).

INPUT:

  • string – the string to be escaped.

EXAMPLES:

sage: from sagenb.notebook.template import css_escape
sage: css_escape('abcd')
'abcd'
sage: css_escape('12abcd')
'12abcd'
sage: css_escape(r'\'"abcd\'"')
'---abcd---'
sage: css_escape('my-invalid/identifier')
'my-invalid-identifier'
sage: css_escape(r'quotes"mustbe!escaped')
'quotes-mustbe-escaped'
sagenb.notebook.template.prettify_time_ago(t)

Converts seconds to a meaningful string.

INPUT

  • t – time in seconds
sagenb.notebook.template.template(filename, **user_context)

Returns HTML, CSS, etc., for a template file rendered in the given context.

INPUT:

  • filename - a string; the filename of the template relative to sagenb/data/templates
  • user_context - a dictionary; the context in which to evaluate the file’s template variables

OUTPUT:

  • a string - the rendered HTML, CSS, etc.

EXAMPLES:

sage: from sagenb.notebook.template import template
sage: s = template(os.path.join('html', 'yes_no.html')); type(s)
<type 'unicode'>
sage: 'Yes' in s
True
sage: u = unicode('Are Gröbner bases awesome?','utf-8')
sage: s = template(os.path.join('html', 'yes_no.html'), message=u)
sage: 'Gröbner' in s.encode('utf-8')
True

Previous topic

Notebook Stylesheets (CSS)

Next topic

The Sage Notebook Twisted Web Server

This Page