def _addRequirement(self, parent, info, page, req): item = SQARequirementMatrixItem(parent, requirement=req) self.reader.tokenize(item, req.text, page, MooseDocs.INLINE, info.line, report=False) for token in anytree.PreOrderIter(item): if token.name == 'ErrorToken': msg = common.report_error( "Failed to tokenize SQA requirement.", req.filename, req.text_line, req.text, token['traceback'], u'SQA TOKENIZE ERROR') LOG.critical(msg) p = core.Paragraph(item) tokens.String(p, content=u'Specification: ') with codecs.open(req.filename, encoding='utf-8') as fid: content = fid.read() floats.create_modal_link(p, string=u"{}:{}".format( req.path, req.name), content=core.Code(None, language=u'text', content=content), title=unicode(req.filename)) p = core.Paragraph(item) tokens.String(p, content=u'Details: ') filename = u'{}/{}.md'.format(req.path, req.name) autolink.AutoLink(p, page=unicode(filename))
def _addRequirement(self, parent, info, page, req): reqname = "{}:{}".format(req.path, req.name) if req.path != '.' else req.name item = SQARequirementMatrixItem(parent, label=req.label, reqname=reqname) self.reader.tokenize(item, req.text, page, MooseDocs.INLINE, info.line, report=False) for token in anytree.PreOrderIter(item): if token.name == 'ErrorToken': msg = common.report_error("Failed to tokenize SQA requirement.", req.filename, req.text_line, req.text, token['traceback'], 'SQA TOKENIZE ERROR') LOG.critical(msg) p = core.Paragraph(item) tokens.String(p, content='Specification: ') content = common.read(req.filename) floats.create_modal_link(p, string=reqname, content=core.Code(None, language='text', content=content), title=str(req.filename)) p = core.Paragraph(item) tokens.String(p, content='Documentation: ') filename = getattr(req, info['subcommand']) autolink.AutoLink(p, page=str(filename))
def _addRequirement(self, parent, info, page, req, requirements): reqname = "{}:{}".format(req.path, req.name) if req.path != '.' else req.name item = SQARequirementMatrixItem(parent, label=req.label, reqname=reqname, satisfied=req.satisfied) text = SQARequirementText(item) self.reader.tokenize(text, req.text, page, MooseDocs.INLINE, info.line, report=False) for token in anytree.PreOrderIter(item): if token.name == 'ErrorToken': msg = common.report_error("Failed to tokenize SQA requirement.", req.filename, req.text_line, req.text, token['traceback'], 'SQA TOKENIZE ERROR') LOG.critical(msg) if req.details: details = SQARequirementDetails(item) for detail in req.details: ditem = SQARequirementDetailItem(details) text = SQARequirementText(ditem) self.reader.tokenize(text, detail.text, page, MooseDocs.INLINE, info.line, \ report=False) if self.settings['link']: if self.settings['link-spec']: p = SQARequirementSpecification(item, spec_path=req.path, spec_name=req.name) hit_root = mooseutils.hit_load(req.filename) h = hit_root.find(req.name) content = h.render() floats.create_modal_link(p, title=reqname, string=reqname, content=core.Code(None, language='text', content=content)) if self.settings['link-design'] and req.design: p = SQARequirementDesign(item, filename=req.filename, design=req.design, line=req.design_line) if self.settings['link-issues'] and req.issues: p = SQARequirementIssues(item, filename=req.filename, issues=req.issues, line=req.issues_line) if self.settings.get('link-prerequisites', False) and req.prerequisites: labels = [] for prereq in req.prerequisites: for other in requirements: if (other.name == prereq) and (other.path == req.path): labels.append((other.path, other.name, other.label)) for detail in other.details: if (detail.name == prereq) and (detail.path == req.path): labels.append((other.path, other.name, other.label)) SQARequirementPrequisites(item, specs=labels)
def _addRequirement(self, parent, info, page, req, requirements): item = SQARequirementMatrixItem(parent, label=unicode(req.label), satisfied=req.satisfied, id_=req.path) self.reader.tokenize(item, req.text, page) if self.settings['link']: if self.settings['link-spec']: p = core.Paragraph(item) tokens.String(p, content=u'Specification: ') with codecs.open(req.filename, encoding='utf-8') as fid: content = fid.read() floats.create_modal_link( p, url=u"#", title=tokens.String(None, content=unicode(req.filename)), content=core.Code(None, language=u'text', code=content), string=u"{}:{}".format(req.path, req.name), tooltip=False) if self.settings['link-design'] and req.design: p = core.Paragraph(item) tokens.String(p, content=u'Design: ') for design in req.design: autolink.AutoLink(p, page=unicode(design)) if self.settings['link-issues'] and req.issues: p = core.Paragraph(item) tokens.String(p, content=u'Issues: ') for issue in req.issues: if issue.startswith('#'): url = u"https://github.com/idaholab/moose/issues/{}".format( issue[1:]) else: url = u"https://github.com/idaholab/moose/commit/{}".format( issue[1:]) core.Link(p, url=url, string=unicode(issue)) core.Space(p) if self.settings['link-prerequisites'] and req.prerequisites: labels = [] for prereq in req.prerequisites: for other in requirements: if other.name == prereq: labels.append(other.label) p = core.Paragraph(item) tokens.String(p, content=u'Prerequisites: {}'.format( ' '.join(labels)))
def _addRequirement(self, parent, info, page, req, requirements): item = SQARequirementMatrixItem(parent, requirement=req) text = SQARequirementText(item) self.reader.tokenize(text, req.text, page, MooseDocs.INLINE, info.line, report=False) for token in anytree.PreOrderIter(item): if token.name == 'ErrorToken': msg = common.report_error( "Failed to tokenize SQA requirement.", req.filename, req.text_line, req.text, token['traceback'], u'SQA TOKENIZE ERROR') LOG.critical(msg) if self.settings['link']: if self.settings['link-spec']: p = SQARequirementSpecification(item, spec_path=req.path, spec_name=req.name) with codecs.open(req.filename, encoding='utf-8') as fid: content = fid.read() floats.create_modal_link(p, title=req.filename, content=core.Code(None, language=u'text', content=content), string=u"{}:{}".format( req.path, req.name)) if self.settings['link-design'] and req.design: p = SQARequirementDesign(item, design=req.design) if self.settings['link-issues'] and req.issues: p = SQARequirementIssues(item, issues=req.issues) if self.settings['link-prerequisites'] and req.prerequisites: labels = [] for prereq in req.prerequisites: for other in requirements: if (other.name == prereq) and (other.path == req.path): labels.append( (other.path, other.name, other.label)) SQARequirementPrequisites(item, specs=labels)
def _addRequirement(self, parent, info, page, req, requirements): item = SQARequirementMatrixItem(parent, label=unicode(req.label), satisfied=req.satisfied, id_=req.path) self.reader.tokenize(item, req.text, page) if self.settings['link']: if self.settings['link-spec']: p = core.Paragraph(item) tokens.String(p, content=u'Specification: ') with codecs.open(req.filename, encoding='utf-8') as fid: content = fid.read() floats.create_modal_link(p, url=u"#", title=tokens.String(None, content=unicode(req.filename)), content=core.Code(None, language=u'text', code=content), string=u"{}:{}".format(req.path, req.name), tooltip=False) if self.settings['link-design'] and req.design: p = core.Paragraph(item) tokens.String(p, content=u'Design: ') for design in req.design: autolink.AutoLink(p, page=unicode(design)) if self.settings['link-issues'] and req.issues: p = core.Paragraph(item) tokens.String(p, content=u'Issues: ') for issue in req.issues: if issue.startswith('#'): url = u"https://github.com/idaholab/moose/issues/{}".format(issue[1:]) else: url = u"https://github.com/idaholab/moose/commit/{}".format(issue[1:]) core.Link(p, url=url, string=unicode(issue)) core.Space(p) if self.settings['link-prerequisites'] and req.prerequisites: labels = [] for prereq in req.prerequisites: for other in requirements: if other.name == prereq: labels.append(other.label) p = core.Paragraph(item) tokens.String(p, content=u'Prerequisites: {}'.format(' '.join(labels)))
def _createFieldError(self, parent, token, page, modal_flag): """Helper for creating error alert.""" filename = page.local key = token['key'] err = alert.AlertToken(None, brand=u'error') alert_title = alert.AlertTitle(err, brand=u'error', string=u'Missing Template Item: "{}"'.format(key)) alert_content = alert.AlertContent(err, brand=u'error') token.copyToToken(alert_content) if modal_flag: modal_content = tokens.Token(None) core.Paragraph(modal_content, string=u"The document must include the \"{0}\" template item, this can "\ u"be included by add adding the following to the markdown " \ u"file ({1}):".format(key, filename)) core.Code(modal_content, content=u"!template! item key={0}\nInclude text (in MooseDocs format) " \ u"regarding the \"{0}\" template item here.\n" \ u"!template-end!".format(key)) link = floats.create_modal_link(alert_title, title=u'Missing Template Item "{}"'.format(key), content=modal_content) materialicon.Icon(link, icon=u'help_outline', class_='small', style='float:right;color:white;margin-bottom:5px;') self.renderer.render(parent, err, page)
def createTokenHelper(key, parent, info, page, use_key_in_modal=False): match = PAGE_LINK_RE.search(info[key]) bookmark = match.group('bookmark')[1:] if match.group('bookmark') else u'' filename = match.group('filename') # The link is local (i.e., [#foo]), the heading will be gathered on render because it # could be after the current position. if (filename is None) and (bookmark != u''): return LocalLink(parent, bookmark=bookmark) elif filename is not None: return AutoLink(parent, page=filename, bookmark=bookmark) else: source = common.project_find(info[key]) if len(source) == 1: src = unicode(source[0]) content = common.fix_moose_header(common.read(os.path.join(MooseDocs.ROOT_DIR, src))) code = core.Code(None, language=common.get_language(src), content=content) local = src.replace(MooseDocs.ROOT_DIR, '') link = floats.create_modal_link(parent, content=code, title=local) if use_key_in_modal: tokens.String(link, content=os.path.basename(info[key])) return link return None
def createTokenHelper(key, parent, info, page, use_key_in_modal=False): match = PAGE_LINK_RE.search(info[key]) bookmark = match.group('bookmark')[1:] if match.group('bookmark') else u'' filename = match.group('filename') # The link is local (i.e., [#foo]), the heading will be gathered on render because it # could be after the current position. if (filename is None) and (bookmark != u''): return LocalLink(parent, bookmark=bookmark) elif filename is not None: return AutoLink(parent, page=filename, bookmark=bookmark) else: source = common.project_find(info[key]) if len(source) == 1: src = unicode(source[0]) content = common.fix_moose_header( common.read(os.path.join(MooseDocs.ROOT_DIR, src))) code = core.Code(None, language=common.get_language(src), content=content) local = src.replace(MooseDocs.ROOT_DIR, '') link = floats.create_modal_link(parent, content=code, title=local) if use_key_in_modal: tokens.String(link, content=os.path.basename(info[key])) return link return None
def createTokenFromSyntax(self, parent, info, page, obj): item = self.extension.database.get(obj.name, None) attr = getattr(item, self.SUBCOMMAND, None) if item and attr: self.createHeading(parent, page) ul = core.UnorderedList(parent, class_='moose-list-{}'.format(self.SUBCOMMAND)) for filename in attr: filename = unicode(filename) li = core.ListItem(ul) lang = common.get_language(filename) content = common.fix_moose_header(common.read(os.path.join(MooseDocs.ROOT_DIR, filename))) code = core.Code(None, language=lang, code=content) floats.create_modal_link(li, url=filename, content=code, title=filename, string=filename) return parent
def createToken(self, parent, info, page): """ Build the tokens needed for displaying code listing. """ filename = common.check_filenames(info['subcommand']) flt = floats.create_float(parent, self.extension, self.reader, page, self.settings, token_type=Listing) # Create code token lang = self.settings.get('language') content = self.extractContent(filename) lang = lang if lang else common.get_language(filename) code = core.Code(flt, style="max-height:{};".format( self.settings['max-height']), content=content, language=lang) if flt is parent: code.attributes.update(**self.attributes) if flt is not parent: code.name = 'ListingCode' # Add bottom modal link = self.settings['link'] link = link if link is not None else self.extension['modal-link'] if link: rel_filename = os.path.relpath(filename, MooseDocs.ROOT_DIR) # Get the complete file content = common.read(filename) settings = common.get_settings_as_dict( common.extractContentSettings()) settings['strip-header'] = False content, _ = common.extractContent(content, settings) # Create modal for display the files a popup code = core.Code(None, language=lang, content=content) link = floats.create_modal_link( flt, url=unicode(rel_filename), content=code, title=unicode(filename), string=u'({})'.format(rel_filename)) link.name = 'ListingLink' link['data-tooltip'] = unicode(rel_filename) return parent
def _addRequirement(self, parent, info, page, req): item = SQARequirementMatrixItem(parent, label=unicode(req.label), satisfied=req.satisfied, id_=req.path) self.reader.tokenize(item, req.text, page, line=info.line) p = core.Paragraph(item) tokens.String(p, content=u'Specification: ') with codecs.open(req.filename, encoding='utf-8') as fid: content = fid.read() floats.create_modal_link(p, tooltip=False, url=u"#", string=u"{}:{}".format(req.path, req.name), title=tokens.String(None, content=unicode(req.filename)), content=core.Code(None, language=u'text', code=content)) p = core.Paragraph(item) tokens.String(p, content=u'Details: ') filename = u'{}/{}.md'.format(req.path, req.name) autolink.AutoLink(p, page=unicode(filename))
def createMaterialize(self, parent, token, page): key = token.key func = lambda n: isinstance(n, SQADocumentItem) and (n.key == key) replacement = anytree.search.find(token.root, filter_=func, maxlevel=2) if replacement: self.renderer.render(parent, replacement, page) # Remove item so it doesn't render again replacement.parent = None for child in replacement: child.parent = None # else: filename = page.local err = alert.AlertToken(None, brand=u'error') alert_title = alert.AlertTitle( err, brand=u'error', string=u'Missing Template Item "{}"'.format(key)) alert_content = alert.AlertContent(err, brand=u'error') modal_content = tokens.Token(None) core.Paragraph(modal_content, string=u"The document must include the \"{0}\" template item, this can "\ u"be included by add adding the following to the markdown " \ u"file ({1}):".format(key, filename)) core.Code(modal_content, code=u"!sqa! item key={0}\nInclude text (in MooseDocs format) " \ u"regarding the \"{0}\" template item here.\n" \ u"!sqa-end!".format(key)) link = floats.create_modal_link( alert_title, title=u'Missing Template Item "{}"'.format(key), content=modal_content) materialicon.IconToken(link, icon=u'help_outline', class_=u'material-icons moose-help') for child in token.children: child.parent = alert_content self.renderer.render(parent, err, page)
def _addRequirement(self, parent, info, page, req): item = SQARequirementMatrixItem(parent, label=unicode(req.label), satisfied=req.satisfied, id_=req.path) self.reader.tokenize(item, req.text, page, line=info.line) p = core.Paragraph(item) tokens.String(p, content=u'Specification: ') with codecs.open(req.filename, encoding='utf-8') as fid: content = fid.read() floats.create_modal_link( p, tooltip=False, url=u"#", string=u"{}:{}".format(req.path, req.name), title=tokens.String(None, content=unicode(req.filename)), content=core.Code(None, language=u'text', code=content)) p = core.Paragraph(item) tokens.String(p, content=u'Details: ') filename = u'{}/{}.md'.format(req.path, req.name) autolink.AutoLink(p, page=unicode(filename))
def createToken(self, parent, info, page): """ Build the tokens needed for displaying code listing. """ filename = common.check_filenames(info['subcommand']) flt = floats.create_float(parent, self.extension, self.reader, page, self.settings, token_type=Listing) # Create code token lang = self.settings.get('language') content = self.extractContent(filename) lang = lang if lang else common.get_language(filename) code = core.Code(flt, style="max-height:{};".format(self.settings['max-height']), content=content, language=lang) if flt is parent: code.attributes.update(**self.attributes) if flt is not parent: code.name = 'ListingCode' # Add bottom modal link = self.settings['link'] link = link if link is not None else self.extension['modal-link'] if link: rel_filename = os.path.relpath(filename, MooseDocs.ROOT_DIR) # Get the complete file content = common.read(filename) settings = common.get_settings_as_dict(common.extractContentSettings()) settings['strip-header'] = False content, _ = common.extractContent(content, settings) # Create modal for display the files a popup code = core.Code(None, language=lang, content=content) link = floats.create_modal_link(flt, url=unicode(rel_filename), content=code, title=unicode(filename), string=u'({})'.format(rel_filename)) link.name = 'ListingLink' link['data-tooltip'] = unicode(rel_filename) return parent
def createMaterialize(self, parent, token, page): key = token.key func = lambda n: isinstance(n, SQADocumentItem) and (n.key == key) replacement = anytree.search.find(token.root, filter_=func, maxlevel=2) if replacement: self.renderer.render(parent, replacement, page) # Remove item so it doesn't render again replacement.parent = None for child in replacement: child.parent = None # else: filename = page.local err = alert.AlertToken(None, brand=u'error') alert_title = alert.AlertTitle(err, brand=u'error', string=u'Missing Template Item "{}"'.format(key)) alert_content = alert.AlertContent(err, brand=u'error') modal_content = tokens.Token(None) core.Paragraph(modal_content, string=u"The document must include the \"{0}\" template item, this can "\ u"be included by add adding the following to the markdown " \ u"file ({1}):".format(key, filename)) core.Code(modal_content, code=u"!sqa! item key={0}\nInclude text (in MooseDocs format) " \ u"regarding the \"{0}\" template item here.\n" \ u"!sqa-end!".format(key)) link = floats.create_modal_link(alert_title, title=u'Missing Template Item "{}"'.format(key), content=modal_content) materialicon.IconToken(link, icon=u'help_outline', class_=u'material-icons moose-help') for child in token.children: child.parent = alert_content self.renderer.render(parent, err, page)
def _addRequirement(self, parent, info, page, req, requirements): item = SQARequirementMatrixItem(parent, label=unicode(req.label), satisfied=req.satisfied, id_=req.path) self.reader.tokenize(item, req.text, page, MooseDocs.INLINE, info.line, report=False) for token in anytree.PreOrderIter(item): if token.name == 'ErrorToken': msg = common.report_error( "Failed to tokenize SQA requirement.", req.filename, req.text_line, req.text, token['traceback'], u'SQA TOKENIZE ERROR') LOG.critical(msg) if self.settings['link']: if self.settings['link-spec']: p = core.Paragraph(item) tokens.String(p, content=u'Specification: ') with codecs.open(req.filename, encoding='utf-8') as fid: content = fid.read() floats.create_modal_link(p, title=req.filename, content=core.Code(None, language=u'text', content=content), string=u"{}:{}".format( req.path, req.name)) if self.settings['link-design'] and req.design: p = core.Paragraph(item) tokens.String(p, content=u'Design: ') for design in req.design: autolink.AutoLink(p, page=unicode(design)) if self.settings['link-issues'] and req.issues: p = core.Paragraph(item) tokens.String(p, content=u'Issue(s): ') for issue in req.issues: if issue.startswith('#'): url = u"https://github.com/idaholab/moose/issues/{}".format( issue[1:]) else: url = u"https://github.com/idaholab/moose/commit/{}".format( issue[1:]) core.Link(p, url=url, string=unicode(issue)) core.Space(p) if self.settings['link-prerequisites'] and req.prerequisites: labels = [] for prereq in req.prerequisites: for other in requirements: if other.name == prereq: labels.append(other.label) p = core.Paragraph(item) tokens.String(p, content=u'Prerequisites: {}'.format( ' '.join(labels)))