<s> from django import template <EOL> from django . conf import settings <EOL> import pystache <EOL> import os <EOL> register = template . Library ( ) <EOL> class View ( pystache . View ) : <EOL> template_path = settings . TEMPLATE_DIRS [ <NUM_LIT:0> ] <EOL> def __init__ ( self , template_dir , template_name , context ) : <EOL> self . template_path = template_dir <EOL> self . template_name = template_name <EOL> return super ( View , self ) . __init__ ( context = context ) <EOL> class MustacheNode ( template . Node ) : <EOL> def __init__ ( self , template_name , attr = None ) : <EOL> for template_dir in settings . TEMPLATE_DIRS : <EOL> if os . path . exists ( os . path . join ( template_dir , template_name ) + "<STR_LIT>" ) : <EOL> break <EOL> else : <EOL> raise IOError ( "<STR_LIT>" % ( template_name , str ( settings . TEMPLATE_DIRS ) ) ) <EOL> self . template_path = template_dir <EOL> self . template = template_name <EOL> self . attr = attr <EOL> def render ( self , context ) : <EOL> mcontext = context [ self . attr ] if self . attr else { } <EOL> view = View ( self . template_path , self . template , context = mcontext ) <EOL> return view . render ( ) <EOL> def do_mustache ( parser , token ) : <EOL> """<STR_LIT>""" <EOL> bits = token . split_contents ( ) <EOL> if len ( bits ) not in [ <NUM_LIT:2> , <NUM_LIT:3> ] : <EOL> raise template . TemplateSyntaxError ( "<STR_LIT>" % bits [ <NUM_LIT:0> ] ) <EOL> path = bits [ <NUM_LIT:1> ] <EOL> path = path [ <NUM_LIT:1> : - <NUM_LIT:1> ] <EOL> attrs = bits [ <NUM_LIT:2> : ] <EOL> return MustacheNode ( path , * attrs ) <EOL> register . tag ( "<STR_LIT>" , do_mustache ) </s>
