Quantcast
Channel: Mako: Ticket Query
Viewing all articles
Browse latest Browse all 38

#160: add source namespace to get_def() ?

$
0
0

When render() is called, runtime will pull out the requested namespace after _populate_self_namespace is called and effectively run whatever named def relative to that namespace, such as self.

The feature would look like:

classTemplate(object):# ...defget_def(self, name, via_namespace=None):# ...

Below is not the patch but this is the kind of tinkering we'd need

  • mako/runtime.py

    diff -r b03678de9faf mako/runtime.py
    a b  
    575575                            **_kwargs_for_callable(callable_, data)) 
    576576    return context._pop_buffer().getvalue() 
    577577 
     578def _get_self(tmpl, callable_, args, data, as_unicode=False): 
     579    buf = util.StringIO() 
     580    context = Context(buf, **data) 
     581    context._outputting_as_unicode = as_unicode 
     582    context._with_template = tmpl 
     583    (inherit, lclcontext) = _populate_self_namespace(context, tmpl) 
     584    return buf, context._data['self'] 
     585 
    578586def _kwargs_for_callable(callable_, data): 
    579587    argspec = inspect.getargspec(callable_) 
    580588    # for normal pages, **pageargs is usually present 
     
    609617        # otherwise, call the actual rendering method specified 
    610618        (inherit, lclcontext) = _populate_self_namespace(context, tmpl.parent) 
    611619        _exec_template(callable_, context, args=args, kwargs=kwargs) 
    612   
     620 
    613621def _exec_template(callable_, context, args=None, kwargs=None): 
    614622    """execute a rendering callable given the callable, a 
    615623    Context, and optional explicit arguments 
  • mako/template.py

    diff -r b03678de9faf mako/template.py
    a b  
    304304                                context,  
    305305                                *args,  
    306306                                **kwargs) 
    307   
     307 
     308    def get_self(self, *args, **data): 
     309        return runtime._get_self( 
     310            self,  
     311            self.callable_, 
     312            args,  
     313            data 
     314        ) 
     315 
    308316    def has_def(self, name): 
    309317        return hasattr(self.module, "render_%s" % name) 
    310318  

Viewing all articles
Browse latest Browse all 38

Trending Articles