<s> from __future__ import absolute_import <EOL> from django . template import Node , Library , TemplateSyntaxError <EOL> from django . conf import settings <EOL> from django . contrib . staticfiles . storage import staticfiles_storage <EOL> register = Library ( ) <EOL> class MinifiedJSNode ( Node ) : <EOL> def __init__ ( self , sourcefile ) : <EOL> self . sourcefile = sourcefile <EOL> def render ( self , context ) : <EOL> if settings . DEBUG : <EOL> scripts = settings . JS_SPECS [ self . sourcefile ] [ '<STR_LIT>' ] <EOL> else : <EOL> scripts = [ settings . JS_SPECS [ self . sourcefile ] [ '<STR_LIT>' ] ] <EOL> script_urls = [ staticfiles_storage . url ( script ) for script in scripts ] <EOL> script_tags = [ '<STR_LIT>' <EOL> % url for url in script_urls ] <EOL> return '<STR_LIT:\n>' . join ( script_tags ) <EOL> @ register . tag <EOL> def minified_js ( parser , token ) : <EOL> try : <EOL> tag_name , sourcefile = token . split_contents ( ) <EOL> except ValueError : <EOL> raise TemplateSyntaxError ( "<STR_LIT>" % ( tag_name , ) ) <EOL> if not ( sourcefile [ <NUM_LIT:0> ] == sourcefile [ - <NUM_LIT:1> ] and sourcefile [ <NUM_LIT:0> ] in ( '<STR_LIT:">' , "<STR_LIT:'>" ) ) : <EOL> raise TemplateSyntaxError ( "<STR_LIT>" % ( tag_name , ) ) <EOL> sourcefile = sourcefile [ <NUM_LIT:1> : - <NUM_LIT:1> ] <EOL> if sourcefile not in settings . JS_SPECS : <EOL> raise TemplateSyntaxError ( "<STR_LIT>" <EOL> % ( tag_name , sourcefile ) ) <EOL> return MinifiedJSNode ( sourcefile ) </s>
