Commit 257cbd4a by Chris Jerdonek

Merge pull request #29 (3) "docstrings"

From: https://github.com/kennethreitz/pystache/commit/e501ec273df9af0e2fe3e9752b19d0d94cc3884e
Into: issue_29

This commit stubs out docstrings for some methods.

Conflicts:
	pystache/view.py
parents 98d8b403 e501ec27
...@@ -68,6 +68,12 @@ class Template(object): ...@@ -68,6 +68,12 @@ class Template(object):
self._compile_regexps() self._compile_regexps()
def _compile_regexps(self): def _compile_regexps(self):
"""
Compile and set the regular expression attributes.
This method uses the current values for the otag and ctag attributes.
"""
tags = { tags = {
'otag': re.escape(self.otag), 'otag': re.escape(self.otag),
'ctag': re.escape(self.ctag) 'ctag': re.escape(self.ctag)
...@@ -194,6 +200,10 @@ class Template(object): ...@@ -194,6 +200,10 @@ class Template(object):
return literal(self.view.get(tag_name, '')) return literal(self.view.get(tag_name, ''))
def render(self, encoding=None): def render(self, encoding=None):
"""
Return the template rendered using the current view context.
"""
template = self._render_sections(self.template, self.view) template = self._render_sections(self.template, self.view)
result = self._render_tags(template) result = self._render_tags(template)
......
...@@ -51,6 +51,10 @@ class View(object): ...@@ -51,6 +51,10 @@ class View(object):
self.context_list = [context] self.context_list = [context]
def get(self, attr, default=None): def get(self, attr, default=None):
"""
Return the value for the given attribute.
"""
attr = get_or_attr(self.context_list, attr, getattr(self, attr, default)) attr = get_or_attr(self.context_list, attr, getattr(self, attr, default))
if hasattr(attr, '__call__') and type(attr) is UnboundMethodType: if hasattr(attr, '__call__') and type(attr) is UnboundMethodType:
...@@ -64,6 +68,10 @@ class View(object): ...@@ -64,6 +68,10 @@ class View(object):
encoding=self.template_encoding, extension=self.template_extension) encoding=self.template_encoding, extension=self.template_extension)
def get_template(self, template_name): def get_template(self, template_name):
"""
Return the current template after setting it, if necessary.
"""
if not self.template: if not self.template:
template_name = self._get_template_name(template_name) template_name = self._get_template_name(template_name)
self.template = self.load_template(template_name) self.template = self.load_template(template_name)
...@@ -102,6 +110,10 @@ class View(object): ...@@ -102,6 +110,10 @@ class View(object):
return context return context
def render(self, encoding=None): def render(self, encoding=None):
"""
Return the view rendered using the current context.
"""
template = Template(self.get_template(self.template_name), self) template = Template(self.get_template(self.template_name), self)
return template.render(encoding=encoding) return template.render(encoding=encoding)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment