def test_font_styles(self): c = Converter('Man', file='font_styles.man') c.translate() text = c.html.render() text = c.change_special_symbols(text) doc = tags.html(lang='en') doc = add_head(doc) doc_body = doc.add(tags.body()) lines = [ tags.b('one'), '\ntwo', tags.b('three'), tags.b('four'), tags.i('five'), tags.b('six'), '\nseven eight', tags.b('nine'), '\nten eleven twelve', tags.i('13'), tags.b('14'), tags.i('15'), tags.i('file'), '\n.', tags.small('bbbbb'), tags.small('aaaaaa dfghjhg'), tags.b('--posix'), tags.i('file1 file2') ] with doc_body: paragraph = tags.p() for line in lines: paragraph += line self.assertEqual(doc.render(), text)
def _wrapped_field(self, node, type='text', classes=['form-control'], **kwargs): exceptions = ['BooleanField', 'FileField', 'RadioField', 'SubmitField'] if self.form_type == 'horizontal': classes.append('row') if node.flags.hidden: return raw(node()) if node.type in exceptions: return self.visit(node) if node.errors: classes = ['form-control', 'is-invalid'] wrap = self._wrapper(node) wrap.add(Markup(node.label)) wrap.add(Markup(node(class_=' '.join(classes)))) for error in node.errors: wrap.add(tags.div(error, _class='invalid-feedback')) if node.description: wrap.add( tags.small(node.description, _class='form-text text-muted')) return wrap
def visit_FileField(self, node): wrap = self._wrapper(node) cst = wrap.add(tags.div(cls='custom-file')) cst.add(Markup(node(class_='custom-file-input'))) cst.add(Markup(node.label(class_='custom-file-label'))) if node.description: wrap.add( tags.small(node.description, _class='form-text text-muted')) return wrap
def visit_BooleanField(self, node): wrap = self._wrapper(node, classes=['form-check']) wrap.add( tags.input(type='checkbox', cls='form-check-input', id=node.id)) wrap.add( tags.label(node.label.text, _for=node.id, cls='form-check-label')) if node.description: wrap.add( tags.small(node.description, _class='form-text text-muted')) return wrap
def gen_output(self, fr): # Using <small> improves rendering in RSS feeds wrapper = tags.div(cls="alectryon-output-sticky-wrapper") with tags.small(cls="alectryon-output").add(wrapper): for output in fr.outputs: if isinstance(output, Messages): assert output.messages, "transforms.commit_io_annotations" with tags.div(cls="alectryon-messages"): for message in output.messages: tags.blockquote(self.highlight(message.contents), cls="alectryon-message") if isinstance(output, Goals): assert output.goals, "transforms.commit_io_annotations" with tags.div(cls="alectryon-goals"): self.gen_goals(output.goals[0], output.goals[1:])
def getHTML(title, info=None, body=None, style=None, state=None, theme=None, icon=None): """Provide HTML object :param str title: short name of the notification, e.g.: server error :param str info: some short description if needed, e.g.: It looks like the server is not responding :param body: it can be string or dominate tag object, e.g.: from dominate import tags as dom return getHTML('server error', body=dom.pre(dom.code(result['Message'])) :param str style: additional css style if needed, e.g.: '.card{color:red;}' :param int state: response state code, if needed, e.g.: 404 :param str theme: message color theme, the same that in bootstrap 5, e.g.: 'warning' :param str icon: awesome icon name, e.g.: 'users' :return: str -- HTML document """ html = document("DIRAC - %s" % title) # select the color to the state code if state in [400, 401, 403, 404]: theme = theme or "warning" elif state in [500]: theme = theme or "danger" elif state in [200]: theme = theme or "success" # select the icon to the theme if theme in ["warning", "warn"]: theme = "warning" icon = icon or "exclamation-triangle" elif theme == "info": icon = icon or "info" elif theme == "success": icon = icon or "check" elif theme in ["error", "danger"]: theme = "danger" icon = icon or "times" else: theme = theme or "secondary" icon = icon or "flask" # If body is text wrap it with tags if body and isinstance(body, six.string_types): body = dom.pre( dom.code(traceback.format_exc() if body == "traceback" else body), cls="mt-5") try: diracLogo = collectMetadata(ignoreErrors=True).get("logoURL", "") except Exception: diracLogo = "" # Create head with html.head: # Meta tags dom.meta(charset="utf-8") dom.meta(name="viewport", content="width=device-width, initial-scale=1") # Favicon dom.link(rel="shortcut icon", href="/static/core/img/icons/system/favicon.ico", type="image/x-icon") # Provide awesome icons # https://fontawesome.com/v4.7/license/ dom.script( src= "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/js/all.min.js" ) # Enable bootstrap 5 # https://getbootstrap.com/docs/5.0/getting-started/introduction/ # https://getbootstrap.com/docs/5.0/about/license/ dom.link( rel="stylesheet", integrity= "sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC", href= "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css", crossorigin="anonymous", ) dom.script( src= "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js", integrity= "sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM", crossorigin="anonymous", ) # Provide additional css style = ".card{transition:.3s;}.card:hover{transform:scale(1.03);}" + ( style or "") dom.style(style) # Create body with html: # Background image dom.i( cls="position-absolute bottom-0 start-0 translate-middle-x m-5 fa " "fa-%s text-%s" % (icon, theme), style="font-size:40vw;z-index:-1;", ) # A4 page with align center with dom.div( cls= "row vh-100 vw-100 justify-content-md-center align-items-center m-0" ): with dom.div(cls="container", style="max-width:600px;") as page: # Main panel with dom.div(cls="row align-items-center"): # Logo dom.div(dom.img(src=diracLogo, cls="card-img px-2"), cls="col-md-6 my-3") # Information card with dom.div(cls="col-md-6 my-3"): # Show response state number if state and state != 200: dom.div(dom.h1( state, cls="text-center badge bg-%s text-wrap" % theme), cls="row py-2") # Message title with dom.div(cls="row"): dom.div(dom.i(cls="fa fa-%s text-%s" % (icon, theme)), cls="col-auto") dom.div(title, cls="col-auto ps-0 pb-2 fw-bold") # Description if info: dom.small(dom.i(cls="fa fa-info text-info")) dom.small(info, cls="ps-1") # Add content if body: page.add(body) return html.render()
def add_small(self, line): self.add_paragraph() self.paragraph += tags.small(self.remove_operator(line))