def generate_code(self, g): g.writeline('(iskratch.Application.$extend({') with g.indented_block(): g.writeline('setupSprites : function(rt) {') with g.indented_block(): for sprite in self.sprites: sprite.generate_code(g) g.writeline('},') g.writeline('preloadImages : function(rt, readyFunc) {') with g.indented_block(): if g.images: g.writeline('var loaded = 0;') g.writeline('function probeLoaded() {') with g.indented_block(): g.writeline('if (++loaded == %d) readyFunc();' % len(g.images)) g.writeline('}') for image in g.images: g.writeline('%s = this.loadImage(%s, probeLoaded);' % (g.image_var(image), dump_json(image))) else: g.writeline('readFunc();') g.writeline('},') g.writeline('preloadSounds : function(rt) {') with g.indented_block(): for sound in g.sounds: g.writeline('%s = this.loadSound(%s);' % (g.sound_var(sound), dump_json(sound))) g.writeline('}') g.write('}))')
def generate_code(self, g): msg = dump_json(self.message) g.writeline('rt.subscribeToMessage(%s, function() {' % msg) with g.subframe(): for node in self.body: node.generate_code(g) g.writeline('});')
def GET(self, url): web.header("Content-Type","X-JSON") object = get_object(url) key_name = object.key().name() object = eval(pformat(object._entity)) object['key_name'] = key_name return dump_json(object)
def generate_code(self, g): temp = g.next_identifier() kc = dump_json(get_key_code(self.key)) g.writeline('rt.subscribeKeyDown(%s, function() {' % kc) with g.indented_block(): g.writeline('var %s = function() {' % temp) with g.subframe(): for node in self.body: node.generate_code(g) g.writeline('if (rt.isKeyDown(%s)) rt.defer(%s);' % (kc, temp)) g.writeline('};') g.writeline('rt.defer(%s);' % temp) g.writeline('});')
def sound_var(self, sound): return 'rt.stash[%s]' % dump_json('sound/' + sound)
def list(self, name): return 'rt.stash[%s]' % dump_json('list/splite/list/%s/%s' % (self.name, name))
def __init__(self, data, *args, **kw): #default = kw.get("json_encoder", None) #if default: # del kw['json_encoder'] Response.__init__(self, dump_json(data, cls=LazyEncoder), *args, **kw)
def jsonified(**values): """Returns a json response""" return current_app.response_class(dump_json(values), mimetype='application/json')
def run(self): compile_catalog.run(self) po_files = [] js_files = [] if not self.input_file: if self.locale: po_files.append( (self.locale, os.path.join(self.directory, self.locale, 'LC_MESSAGES', self.domain + '.po'))) js_files.append( os.path.join(self.directory, self.locale, 'LC_MESSAGES', self.domain + '.js')) else: for locale in os.listdir(self.directory): po_file = os.path.join(self.directory, locale, 'LC_MESSAGES', self.domain + '.po') if os.path.exists(po_file): po_files.append((locale, po_file)) js_files.append( os.path.join(self.directory, locale, 'LC_MESSAGES', self.domain + '.js')) else: po_files.append((self.locale, self.input_file)) if self.output_file: js_files.append(self.output_file) else: js_files.append( os.path.join(self.directory, self.locale, 'LC_MESSAGES', self.domain + '.js')) for js_file, (locale, po_file) in zip(js_files, po_files): infile = open(po_file, 'r') try: catalog = read_po(infile, locale) finally: infile.close() if catalog.fuzzy and not self.use_fuzzy: continue log.info('writing JavaScript strings in catalog %r to %r', po_file, js_file) jscatalog = {} for message in catalog: if any(x[0].endswith('.js') for x in message.locations): msgid = message.id if isinstance(msgid, (list, tuple)): msgid = msgid[0] jscatalog[msgid] = message.string outfile = open(js_file, 'wb') try: outfile.write('Solace.TRANSLATIONS.load(') dump_json( dict(messages=jscatalog, plural_expr=catalog.plural_expr, locale=str(catalog.locale), domain=str(self.domain)), outfile) outfile.write(');\n') finally: outfile.close()
def generate_code(self, g): g.write(dump_json(self.value))
def edit_template(page): header = render.header(site_globals, is_admin(), view_editor()) footer = render.footer() script = 'window.client_params = %s;' % dump_json(client_params) return render.editor(header, footer, page, site_globals, script)
def base_template(page): script = 'window.client_params = %s;' % dump_json(client_params) header = render.header(site_globals, is_admin(), view_editor()) # return render.base( header, render.footer(), page, site_globals, script, client_params.css)
def __init__(self, data, *args, **kw): wzResponse.__init__(self, dump_json(data), *args, **kw)
def generate_code(self, g): g.writeline('rt.sendMessage(%s);' % dump_json(self.message))
def image_var(self, image): return 'rt.stash[%s]' % dump_json('image/' + image)
def jsonified(**values): """return a json response""" return current_app.response_class( dump_json(values), mimetype = "text/json" )
def var(self): return 'rt.stash[%s]' % dump_json('sprite/' + self.name)
def jsonified(**values): """return a json response""" return current_app.response_class(dump_json(values), mimetype="text/json")
def variable(self, name): return 'rt.stash[%s]' % dump_json('var/spite/%s/%s' % (self.name, name))
def run(self): compile_catalog.run(self) po_files = [] js_files = [] if not self.input_file: if self.locale: po_files.append((self.locale, os.path.join(self.directory, self.locale, 'LC_MESSAGES', self.domain + '.po'))) js_files.append(os.path.join(self.directory, self.locale, 'LC_MESSAGES', self.domain + '.js')) else: for locale in os.listdir(self.directory): po_file = os.path.join(self.directory, locale, 'LC_MESSAGES', self.domain + '.po') if os.path.exists(po_file): po_files.append((locale, po_file)) js_files.append(os.path.join(self.directory, locale, 'LC_MESSAGES', self.domain + '.js')) else: po_files.append((self.locale, self.input_file)) if self.output_file: js_files.append(self.output_file) else: js_files.append(os.path.join(self.directory, self.locale, 'LC_MESSAGES', self.domain + '.js')) for js_file, (locale, po_file) in zip(js_files, po_files): infile = open(po_file, 'r') try: catalog = read_po(infile, locale) finally: infile.close() if catalog.fuzzy and not self.use_fuzzy: continue log.info('writing JavaScript strings in catalog %r to %r', po_file, js_file) jscatalog = {} for message in catalog: if any(x[0].endswith('.js') for x in message.locations): msgid = message.id if isinstance(msgid, (list, tuple)): msgid = msgid[0] jscatalog[msgid] = message.string outfile = open(js_file, 'wb') try: outfile.write('Solace.TRANSLATIONS.load('); dump_json(dict( messages=jscatalog, plural_expr=catalog.plural_expr, locale=str(catalog.locale), domain=str(self.domain) ), outfile) outfile.write(');\n') finally: outfile.close()
def get_body(self, environ): """Get the body.""" return dump_json({'error': self.get_description(environ)})