def test_unicode_attributes(): """unicode and string coercion in attributes""" template = T.html[ T.head[T.title[my_name()]], T.body[ T.span(id='удерживать')["Coerce byte string to Unicode"], T.span(id='не оставляющий сомнений')["Explicit Unicode object"] ] ] output = flatten(template) assert output == ('<html><head><title>test_unicode_attributes</title></head><body>' '<span id="удерживать">Coerce byte string to Unicode</span>' '<span id="не оставляющий сомнений">Explicit Unicode object</span>' '</body></html>')
def renderSignatureLoot(self, signatureKey): result = Modal( id='lootModal', content=[ T.div(id='containers')[ T.div(class_='buttons')[ T.button(type='button', class_='btn btn-success', **{'data-level': 'trivial'})['+ Debris'], T.button(type='button', class_='btn btn-success', **{'data-level': 'easy'})['+ Rubble'], T.button(type='button', class_='btn btn-warning', **{'data-level': 'medium'})['+ Remains'], T.button(type='button', class_='btn btn-danger', **{'data-level': 'hard'})['+ Ruins'], ], T.div(id='contentPaste')[ Panel( heading='Paste content of container below', content=[ T.div(class_='row')[ T.div(class_='col-xs-9')[ T.textarea(class_="form-control", rows="2"), ], T.div(class_='col-xs-3')[ T.button(class_='btn btn-default')['Submit'], T.div(class_='ajaxLoader', style='white-space: nowrap')[ T.img(src='/static/images/ajax-loader.gif'), ' Processing' ], ], ], ] ), ], T.div(class_='row container-list')[ T.div(class_='col-xs-3 blueprint')[ T.div(class_='thumbnail')[ T.img(src='#'), T.div(class_='caption')[ T.strong()['Lorem ipsum'], T.div(class_='totalWorth')['Lorem ipsum'], ], T.a(href='#', title='Delete', **{'data-toggle': 'tooltip', 'data-placement': 'top'})[ T.span(class_='glyphicon glyphicon-remove-circle') ] ] ] ], ] ], heading=['Loot for signature ', T.strong[signatureKey]], ) return result
def renderStandardField(self, field): additionalClasses = set() feedbackIcon = None if field.flags.required: feedbackIcon = 'glyphicon-asterisk' if field.errors: additionalClasses.add('has-error') feedbackIcon = 'glyphicon-remove' if feedbackIcon is not None: additionalClasses.add('has-feedback') classes = ' %s' % ' '.join(additionalClasses) return ( T.div(class_="form-group%s" % classes)[ T.label(class_="col-sm-3 control-label")[field.label], T.div(class_="col-sm-9")[ field(class_='form-control'), C.when(feedbackIcon)[ T.span(class_='glyphicon form-control-feedback %s' % feedbackIcon), ], C.when(field.errors)[ T.span(class_='help-block')[ T.ul[ [T.li[err] for err in field.errors] ] ] ] ], ], )
def test_dom_traversal_from_macro(): """macro abuse: self-traversing template""" template = ( assign('selectors', []), macro('css_sep', lambda attr: attr == 'class' and '.' or '#' ), macro('get_selectors', lambda tag, is_tag: selectors.extend([ # @UndefinedVariable "%s%s%s { }" % (tag.name, css_sep(_k.strip('_')), _v) # @UndefinedVariable for _k, _v in tag.attrs.items() if _k.strip('_') in ('id', 'class') ]) ), macro('extract_css', lambda tag: tag.walk(get_selectors, True) and tag # @UndefinedVariable ), macro('css_results', lambda selectors: T.pre['\n'.join(selectors)] ), T.html[ T.head[T.title['macro madness']], T.body[extract_css(# @UndefinedVariable T.div('class', 'text', 'id', 'main-content')[ T.img('src', '/images/breve-logo.png', 'alt', 'breve logo'), T.br, T.span (class_='bold') [ """Hello from Breve!""" ] ] ), css_results(selectors)] # @UndefinedVariable ] ) output = flatten(template) assert output == ('<html><head><title>macro madness</title></head>' '<body><div class="text" id="main-content">' '<img src="/images/breve-logo.png" alt="breve logo"></img>' '<br /><span class="bold">Hello from Breve!</span></div>' '<pre>div.text { }\ndiv#main-content { }\nspan.bold { }</pre>' '</body></html>')
def Modal(id, content, heading=None, footer=None): result = [] result.append(T.div(class_='modal fade', id=id, tabindex='-1', role='dialog')[ T.div(class_='modal-dialog')[ T.div(class_='modal-content')[ T.div(class_='modal-header')[ T.button(type='button', class_='close', **{'data-dismiss': 'modal'})[ T.span[entities.times], T.span(class_='sr-only')['Close'] ], T.h4(class_='modal-title')[heading] ], T.div(class_='modal-body')[ content ], C.when(footer is not None)[ T.div(class_='modal-footer')[footer] ] ] ] ]) return result
def renderNavbar(self, tag, data): """ :type data: (werkzeug.routing.MapAdapter, None) """ (url, unused) = data currentEndpoint = url.match()[0] burgerToggle = lambda targetId: ( T.button(class_='navbar-toggle', **{'data-toggle': 'collapse', 'data-target': '#%s' % targetId})[ T.span(class_='sr-only')['Toggle navigation'], T.span(class_='icon-bar'), T.span(class_='icon-bar'), T.span(class_='icon-bar'), ] ) mainNavigation = lambda: ( forEach(self.modules, lambda mod: ( T.li(class_='active' if currentEndpoint in mod.endpoints else None)[ T.a(href=url.build(mod.pages[0].endpoint))[mod.name] ] )) ) html = ( T.nav(class_='navbar navbar-default', role='navigation')[ T.div(class_='container-fluid')[ T.div(class_='navbar-header')[ burgerToggle('mainNavCollapse'), T.span(class_='navbar-brand')['Rudykocur Maxwell'] ], T.div(class_='collapse navbar-collapse', id='mainNavCollapse')[ T.ul(class_="nav navbar-nav")[ mainNavigation() ], T.ul(class_="nav navbar-nav navbar-right")[ T.li(class_='dropdown')[ T.a(href='#', class_='dropdown-toggle', **{'data-toggle': 'dropdown'})[ 'Characters', ' ', T.span(class_='caret') ], T.ul(class_='dropdown-menu', role='menu')[ T.li(role='presentation', class_='dropdown-header')['Account: Rudykocur'], T.li[T.a(href='#')['Rudykocur Maxwell']], T.li[T.a(href='#')['Imaginary Profile']], T.li(role='presentation', class_='divider'), T.li(role='presentation', class_='dropdown-header')['Account: Generic'], T.li[T.a(href='#')['All Skills V']], ], ], T.li[ T.a(href=url.build('logout'))['Logout'] ] ] ] ] ] ) return tag[html]