Esempio n. 1
0
 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('}))')
Esempio n. 2
0
 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('});')
Esempio n. 3
0
 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)
Esempio n. 4
0
 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('});')
Esempio n. 5
0
 def sound_var(self, sound):
     return 'rt.stash[%s]' % dump_json('sound/' + sound)
Esempio n. 6
0
 def list(self, name):
     return 'rt.stash[%s]' % dump_json('list/splite/list/%s/%s' % (self.name, name))
Esempio n. 7
0
 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)
Esempio n. 8
0
def jsonified(**values):
    """Returns a json response"""
    return current_app.response_class(dump_json(values),
                                      mimetype='application/json')
Esempio n. 9
0
    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()
Esempio n. 10
0
 def generate_code(self, g):
     g.write(dump_json(self.value))
Esempio n. 11
0
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)
Esempio n. 12
0
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)
Esempio n. 13
0
 def __init__(self, data, *args, **kw):
     wzResponse.__init__(self, dump_json(data), *args, **kw)
Esempio n. 14
0
def jsonified(**values):
    """Returns a json response"""
    return current_app.response_class(dump_json(values),
                                      mimetype='application/json')
Esempio n. 15
0
 def generate_code(self, g):
     g.writeline('rt.sendMessage(%s);' % dump_json(self.message))
Esempio n. 16
0
 def image_var(self, image):
     return 'rt.stash[%s]' % dump_json('image/' + image)
Esempio n. 17
0
def jsonified(**values):
	"""return a json response"""
	return current_app.response_class(
			dump_json(values),
			mimetype = "text/json"
			)
Esempio n. 18
0
 def var(self):
     return 'rt.stash[%s]' % dump_json('sprite/' + self.name)
Esempio n. 19
0
def jsonified(**values):
    """return a json response"""
    return current_app.response_class(dump_json(values), mimetype="text/json")
Esempio n. 20
0
 def variable(self, name):
     return 'rt.stash[%s]' % dump_json('var/spite/%s/%s' % (self.name, name))
Esempio n. 21
0
    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()
Esempio n. 22
0
    def get_body(self, environ):
        """Get the body."""

        return dump_json({'error': self.get_description(environ)})