Ejemplo n.º 1
0
    def test_list_bundles_unset(self):
        from ptah.mustache import list_bundles

        config = Configurator()
        request = self.make_request()
        request.registry = config.registry

        self.assertEqual(list_bundles(request), [])
Ejemplo n.º 2
0
    def test_list_bundles(self):
        from ptah.mustache import list_bundles

        self.config.register_mustache_bundle(
            'test-bundle', 'ptah:tests/bundle/')

        self.assertIn(
            ('test-bundle',
             'http://example.com/_mustache/test-bundle.js'),
            list_bundles(self.request))
Ejemplo n.º 3
0
Archivo: amd.py Proyecto: webmaven/ptah
def amd_init(request):
    specname = request.matchdict['specname']
    storage = request.registry.get(ID_AMD_MODULE)
    spec = request.registry.get(ID_AMD_SPEC, {}).get(specname)
    if spec is None and specname != '_':
        return HTTPNotFound()

    js = []

    if spec is None:
        spec = {}

    if storage:
        for name, path in storage.items():
            info = spec.get(name)
            if info and 'path' in info:
                url = request.route_url(
                    'ptah-amd-spec', specname=specname, name=info['name'])
            else:
                url = '%s'%request.static_url(path)

            js.append('"%s": "%s"'%(name, url[:-3]))

    for name, url in list_bundles(request):
        info = spec.get(name)
        if info and 'path' in info:
            url = request.route_url(
                'ptah-amd-spec', specname=specname, name=info['name'])

        js.append('"%s":"%s"'%(name, url[:-3]))

    options = {'ptah_host': request.application_url,
               'ptah_dt': {'short': 'm/d/yy h:MM TT',
                           'medium': 'mmm d, yyyy h:MM:ss TT',
                           'full': 'mmmm, d, yyyy h:MM:ss TT Z'}
               }

    response = request.response
    response.content_type = 'application/javascript'
    response.text = text_type(amd_init_tmpl%{
        'app_url': request.application_url,
        'mods': ',\n'.join(sorted(js)),
        'exrta': '\n'.join('var %s = %s'%(name, json.dumps(val))
                           for name, val in options.items())})
    return response