Example #1
0
def execute(context):
	if not context:
		print "Context must be defined!"
		return
	try: tmp = context['Name']
	except KeyError as e:
		print "Context name required to determine what template to use..."
		return
	try: tmp = context['ModuleName']
	except KeyError as e:
		# Tries to guess the ModuleName based on the Name of the template.
		names = string.split(context['Name'], "/", 2)
		# Convert the first letter to uppercase.
		modName = string.upper(names[0][:1]) + names[0][1:]

		context['ModuleName'] = {}
		context['ModuleName'][modName] = True
	try: tmp = context['Title']
	except KeyError as e:
		print "Warning: no title will be set for page"
		
	# Actual rendering part.
	# TODO: Add mobile ability.
	view = View(context=context)
	view.template_file = 'tmpl/desktop/'+context['Name']
	return view.render()
Example #2
0
    def render_partial(self, tag_name=None, context=None):
        """Renders a partial within the current context."""
        # Import view here to avoid import loop
        from pystache.view import View

        view = View(context=context)
        view.template_name = tag_name

        return view.render()
Example #3
0
    def render_partial(self, tag_name=None, context=None):
        """Renders a partial within the current context."""
        # Import view here to avoid import loop
        from pystache.view import View

        view = View(context=context)
        view.template_name = tag_name

        return view.render()
Example #4
0
    def test_init__kwargs_does_not_modify_context(self):
        """
        Test that passing **kwargs does not modify the passed context.

        """
        context = {"foo": "bar"}
        view = View(context=context, fuzz="buzz")
        self.assertEquals(context, {"foo": "bar"})
Example #5
0
    def __init__(self, template=None, context=None, **kwargs):
        from pystache.view import View

        self.template = template

        if kwargs:
            context.update(kwargs)

        self.view = context if isinstance(context, View) else View(
            context=context)
        self._compile_regexps()
Example #6
0
def render(template, context=None, path=None, **kwargs):
    context = context and context.copy() or {}
    context.update(kwargs)
    view = View(context=context)
    view.template_path = path
    return Template(template, view).render()