<s> import json <EOL> from classytags . core import Tag , Options <EOL> from cms . utils . encoder import SafeJSONEncoder <EOL> from django import template <EOL> from django . utils . safestring import mark_safe <EOL> register = template . Library ( ) <EOL> @ register . filter ( '<STR_LIT>' ) <EOL> def json_filter ( value ) : <EOL> """<STR_LIT>""" <EOL> return mark_safe ( json . dumps ( value , cls = SafeJSONEncoder ) ) <EOL> @ register . filter <EOL> def bool ( value ) : <EOL> if value : <EOL> return '<STR_LIT:true>' <EOL> else : <EOL> return '<STR_LIT:false>' <EOL> class JavascriptString ( Tag ) : <EOL> name = '<STR_LIT>' <EOL> options = Options ( <EOL> blocks = [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ] <EOL> ) <EOL> def render_tag ( self , context , ** kwargs ) : <EOL> try : <EOL> from django . utils . html import escapejs <EOL> except ImportError : <EOL> from django . utils . text import javascript_quote as escapejs <EOL> rendered = self . nodelist . render ( context ) <EOL> return u"<STR_LIT>" % escapejs ( rendered . strip ( ) ) <EOL> register . tag ( JavascriptString ) </s>
