def init(self): self( Center()(H2()('Via Livorno 9, 41012 Carpi (MO)')), Div(id='map_container')( Meta(name="viewport", content="initial-scale=1.0, user-scalable=no"), Meta(charset="utf-8"), Css({'#map': {'height': '62vh', "box-sizing": "content-box"}}), Div(id='map'), Script(src=url_for('static', filename='js/gmap.js'))(), Script(src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCE74FjhQ39oEwV9kuBI8qedSFOKBWypyQ&callback=initMap", async=bool, defer=bool) ) )
def test_page(self): self.maxDiff = None expected = '<!DOCTYPE HTML><html><head><meta charset="utf-8"/><link href="my.css" type="text/css" ' \ 'rel="stylesheet"/><title>test_title</title></head><body><div class="linkBox"><a href="www.' \ 'foo.com">www.foo.com</a></div><p>This is foo</p><p>This is Bar</p><p>Have you met my friend Baz?' \ '</p>Lorem ipsum dolor sit amet, consectetur adipiscing elit</body></html>' my_text_list = [ 'This is foo', 'This is Bar', 'Have you met my friend Baz?' ] another_list = [ 'Lorem ipsum ', 'dolor sit amet, ', 'consectetur adipiscing elit' ] page = Html( )( # add tags inside the one you created calling the parent Head()( # add multiple tags in one call Meta( charset='utf-8' ), # add tag attributes using kwargs in tag initialization Link(href="my.css", typ="text/css", rel="stylesheet"), Title('test_title')), body=Body() ( # give them a name so you can navigate the DOM with those names Div(klass='linkBox')(A(href='www.foo.com')), (P()(text) for text in my_text_list), # tag insertion accepts generators another_list # add text from a list, str.join is used in rendering )) self.assertEqual(Counter(page.render()), Counter(expected))
def init(self): self.head(self.css(), self.js()) self.head(Meta(charset="utf-8"), Meta(name="viewport", content="width=device-width, initial-scale=1, shrink-to-fit=no",)) self.head.title(self.default_init['title']) self.body( Div(id='bg')(Img(src=url_for('static', filename='img/bg.jpg'))), Div(klass='container')( Div(id='title', klass='row no-gutters align-items-end justify-content-around')( Div(klass='col-md bigLetter')('E', Div(klass='menuItem', link="/chi_siamo")('Chi Siamo')), Div(klass='col-md bigLetter')('k', Div(klass='menuItem', link="/eventi")('Eventi')), Div(klass='col-md bigLetter')('i', Div(klass='menuItem', link="/galleria")('Galleria')), Div(klass='col-md bigLetter')('d', Div(klass='menuItem', link="/contatti")('Contatti')), Div(klass='col-md bigLetter')('n', Div(klass='menuItem', link="/dove_siamo")('Dove Siamo')), Div(klass='col-md bigLetter')('a', Div(klass='menuItem', link="/rottura_del_silenzio")('Rottura Del Silenzio')), ), Div(id='content_container', klass='row no-gutters align-items-start justify-content-center content_container')(Div(id='content', klass="col-md")( self._get_analytics() )) ) )
def init(self): from pprint import pprint pprint(self.__dict__) self.head(self.css()) self.head( Meta(charset="utf-8"), Meta( name="viewport", content="width=device-width, initial-scale=1, shrink-to-fit=no" ), Title()(f'{self.app.config.project_name} - {self.page_title}')) self.content_title = Div( klass='d-flex justify-content-between flex-wrap ' 'flex-md-nowrap align-items-center pb-2 mb-3 border-bottom')( H1(klass='h2')(self.page_title), self.breadcrumb) self.content = Div( klass= 'd-flex justify-content-between flex-wrap pb-2 mb-3 flex-md-nowrap' ) self.body( Nav(klass='navbar navbar-dark sticky-top bg-dark flex-md-nowrap p-0' )(A(klass='navbar-brand col-sm-3 col-md-2 mr-0', href='/app')(self.app.config.project_name), Input(klass='form-control form-control-dark w-100', typ='text', placeholder='Search', **{'aria-label': 'Search'}), Ul(klass='navbar-nav px-3')(Li(klass='nav-item text-nowrap')( A(klass='nav-link', href='/signout')('Sign out')))), Div(klass="container-fluid")(Div(klass='row')(Nav( klass='col-md-2 d-none d-md-block bg-light sidebar' )(Div(klass='sidebar-sticky')( Ul(klass='nav flex-column') (Li(klass='nav-item')(A(klass='nav-link active', href='/app')( I(klass='fas fa-home' ), ' Dashboard', Span(klass='sr-only') ('(current)') )), Li(klass= 'nav-item sidebar-heading d-flex justify-content-between ' 'align-items-center px-3 mt-4 mb-1 text-muted') (A(klass='nav-link', href='/app/processes')( I(klass="fas fa-chalkboard-teacher"), ' Processes ', ), A(klass='navbar-toggler collapsed', **{ "data-toggle": "collapse", "data-target": "#processesList", "aria-expanded": "false" })(I(klass="fas fa-plus-circle navbar-toggler-icon"))), Div(klass="collapse", id="processesList")(Ul(klass="nav flex-column")( Li(klass='nav-item')(A( href=f'/app/processes/{process.name.lower()}', klass='nav-link')(I( klass=f'fas {process.icon}'), ' ' + process.name.title())) for process in self.app.processes.values()))), H6(klass='sidebar-heading d-flex justify-content-between ' 'align-items-center px-3 mt-4 mb-1 text-muted')( Span()('Saved Links')), )), Main( role='main', klass= 'col-md-9 ml-sm-auto col-lg-10 pt-3 px-4' )(self.content_title, self.content))), self.js())
from tempy.tags import Html, Head, Body, Meta, Link, Div, P, A my_text_list = ['This is foo', 'This is Bar', 'Have you met my friend Baz?'] another_list = [ 'Lorem ipsum ', 'dolor sit amet, ', 'consectetur adipiscing elit' ] # make tags instantiating TemPy objects page = Html()( # add tags inside the one you created calling the parent Head()( # add multiple tags in one call Meta(charset='utf-8' ), # add tag attributes using kwargs in tag initialization Link(href="my.css", typ="text/css", rel="stylesheet")), body=Body() ( # give them a name so you can navigate the DOM with those names Div(klass='linkBox')(A(href='www.foo.com')), (P()(text) for text in my_text_list), # tag insertion accepts generators another_list # add text from a list, str.join is used in rendering )) # add tags and content later page[1][0](A(href='www.bar.com')) # calling the tag page[1][0].append(A(href='www.baz.com')) # using the API link = A().append_to( page.body[0]) # access the body as if it's a page attribute page.body( testDiv=Div() ) # WARNING! Correct ordering with named Tag insertion is ensured with Python >= 3.5 (because kwargs are ordered) link.attr(href='www.python.org')( 'This is a link to Python.' ) # Add attributes and content to already placed tags