예제 #1
0
파일: manage.py 프로젝트: robgil/pulsar
 def home_page(self, request):
     doc = wsgi.HtmlDocument(media_path='/media/',
                             known_libraries=media_libraries)
     doc.head.scripts.append('require')
     doc.head.scripts.require('jquery', 'd3', 'philosophers.js')
     doc.head.links.append('bootstrap')
     doc.body.append(wsgi.Html('div', cn='philosophers'))
     return doc.http_response(request)
예제 #2
0
파일: html.py 프로젝트: azazel75/pulsar
 def test_meta(self):
     html = wsgi.HtmlDocument()
     meta = html.head.meta
     self.assertEqual(len(meta.children), 1)
     self.assertEqual(meta.tag, None)
     html.head.add_meta(name='bla')
     self.assertEqual(len(meta.children), 2)
     text = meta.render()
     self.assertEqual(text, "<meta charset='utf-8'>\n<meta name='bla'>\n")
예제 #3
0
 def test_html_doc_media(self):
     doc = wsgi.HtmlDocument(media_path='/foo/')
     self.assertEqual(doc.head.scripts.media_path, '/foo/')
     self.assertEqual(doc.head.links.media_path, '/foo/')
     doc.head.title = 'ciao'
     doc.head.media_path = '/assets/'
     self.assertEqual(doc.head.title, 'ciao')
     self.assertEqual(doc.head.scripts.media_path, '/assets/')
     self.assertEqual(doc.head.links.media_path, '/assets/')
예제 #4
0
파일: html.py 프로젝트: azazel75/pulsar
 def test_document_empty_body(self):
     m = wsgi.HtmlDocument(title='test', bla='foo')
     self.assertTrue(m.head)
     self.assertTrue(m.body)
     self.assertEqual(m.head.title, 'test')
     txt = m.render()
     self.assertEqual(
         txt, '\n'.join(('<!DOCTYPE html>', "<html bla='foo'>", '<head>',
                         '<title>test</title>', "<meta charset='utf-8'>",
                         '</head>', '<body>', '</body>', '</html>')))
예제 #5
0
 def test_document(self):
     m = wsgi.HtmlDocument(title='test')
     m.body.append(wsgi.Html('div', 'this is a test'))
     txt = m.to_string()
     self.assertEqual(
         txt, '\n'.join([
             '<!DOCTYPE html>', '<html>', '<head>', '<title>test</title>',
             "<meta charset='utf-8'>", '</head>', '<body>',
             '<div>this is a test</div>', '</body>', '</html>', ''
         ]))
예제 #6
0
 def error(self, failure):
     '''Handle a failure.'''
     if not self._done:
         uri = self.environ['RAW_URI']
         msg = 'Oops! Could not find %s' % uri
         html = wsgi.HtmlDocument(title=msg)
         html.body.append('<h1>%s</h1>' % msg)
         data = html.render()
         resp = wsgi.WsgiResponse(504, data, content_type='text/html')
         self.start_response(resp.status, resp.get_headers(),
                             failure.exc_info)
         self._done = True
         self.queue.put(resp.content[0])
예제 #7
0
파일: html.py 프로젝트: japaks/pulsar
 def testEmptyHtml(self):
     m = wsgi.HtmlDocument(title='test', bla='foo')
     self.assertTrue(m.head)
     self.assertTrue(m.body)
     self.assertEqual(m.head.title, 'test')
     txt = m.render()
     self.assertEqual(
         txt, ''.join([
             '<!DOCTYPE html>\n', "<html data-bla='foo'>\n", '<head>',
             '<title>test</title>'
             "<meta charset='utf-8'>", '</head>\n'
             '<body>', '</body>\n', '</html>'
         ]))
예제 #8
0
파일: manage.py 프로젝트: robgil/pulsar
 def error(self, exc):
     if not self._started:
         request = wsgi.WsgiRequest(self.environ)
         content_type = request.content_types.best_match(
             ('text/html', 'text/plain'))
         uri = self.environ['RAW_URI']
         msg = 'Could not find %s' % uri
         logger.info(msg=msg)
         if content_type == 'text/html':
             html = wsgi.HtmlDocument(title=msg)
             html.body.append('<h1>%s</h1>' % msg)
             data = html.render()
             resp = wsgi.WsgiResponse(504, data, content_type='text/html')
         elif content_type == 'text/plain':
             resp = wsgi.WsgiResponse(504, msg, content_type='text/html')
         else:
             resp = wsgi.WsgiResponse(504, '')
         self.start_response(resp.status, resp.get_headers())
         self._done = True
         self.queue.put_nowait(resp.content[0])
예제 #9
0
파일: html.py 프로젝트: azazel75/pulsar
 def testHead(self):
     html = wsgi.HtmlDocument()
     head = html.head
     self.assertTrue(head.meta)
     self.assertTrue(head.links)
     self.assertTrue(head.scripts)
예제 #10
0
파일: html.py 프로젝트: azazel75/pulsar
 def test_simple(self):
     html = wsgi.HtmlDocument()
     self.assertEqual(len(html.head.children), 5)
     self.assertEqual(len(html.body.children), 0)