Beispiel #1
0
 def generateSearchIndex(self, doc):
     """Generate the search index."""
     js = ['window.searchData = [']
     for entry in doc.top_level_entries.itervalues():
         akas, subentries = '', ''
         if hasattr(entry, 'akas'):
             akas = ','.join(entry.akas)
         if hasattr(entry, 'subentries'):
             subentries = []
             for t in entry.subentries.values():
                 for s in t:
                     sID = s.title
                     title = proc_doc.splitSecondLevelEntry(s.title)[1]
                     subentries.append({
                         'type': s.kind,
                         'name': s.name,
                         'title': title,
                         'id': sID
                     })
         js.append(
             '  {title:%s,name:%s,text:%s,akas:%s,subentries:%s,loc:%s,langEntity:%s},'
             % (repr(entry.title), repr(
                 entry.name), repr(""), repr(akas), repr(subentries),
                repr(self.path_converter.convert(
                    entry.name)[0]), repr(entry.kind)))
     js.append('];')
     with open(os.path.join(self.out_dirs['js'], 'search.data.js'),
               'wb') as f:
         f.write('\n'.join(js))
Beispiel #2
0
 def _translateLink(self, a_node):
     if not a_node.attrs.get('href', '').startswith('seqan:'):
         return
     target = a_node.attrs['href'][6:]
     target_path, target_title, target_obj = self.path_converter.convert(target)
     # Shorten path title if not manually specified.
     if (a_node.children and a_node.plainText == target_title and
        self.doc.local_name_counter.get(target_title, 1) <= 1):
         short_title = proc_doc.splitSecondLevelEntry(target_title)[1]
         a_node.children = [proc_doc.TextNode(text=short_title)]
     if target_title:
         target_title = proc_doc.TextNode(text=target_title)
     else:
         target_title = proc_doc.TextNode(text=target)
     # TODO(holtgrew): Catch target_title being None, target_path not found!
     if target_path is not None:
         if target_obj:
             a_node.attrs['data-lang-entity'] = target_obj.kind
         a_node.attrs['href'] = target_path
         if not a_node.children:
             a_node.addChild(target_title)
     else:
         class_attr = a_node.attrs.get('class', '')
         if class_attr:
             class_attr += ' '
         class_attr += 'error'
         a_node.attrs['class'] = class_attr
         if a_node.attrs.get('href'):
             del a_node.attrs['href']
Beispiel #3
0
 def _translateLink(self, a_node):
     if not a_node.attrs.get('href', '').startswith('seqan:'):
         return
     target = a_node.attrs['href'][6:]
     target_path, target_title, target_obj = self.path_converter.convert(
         target)
     # Shorten path title if not manually specified.
     if (a_node.children and a_node.plainText == target_title
             and self.doc.local_name_counter.get(target_title, 1) <= 1):
         short_title = proc_doc.splitSecondLevelEntry(target_title)[1]
         a_node.children = [proc_doc.TextNode(text=short_title)]
     if target_title:
         target_title = proc_doc.TextNode(text=target_title)
     else:
         target_title = proc_doc.TextNode(text=target)
     # TODO(holtgrew): Catch target_title being None, target_path not found!
     if target_path is not None:
         if target_obj:
             a_node.attrs['data-lang-entity'] = target_obj.kind
         a_node.attrs['href'] = target_path
         if not a_node.children:
             a_node.addChild(target_title)
     else:
         class_attr = a_node.attrs.get('class', '')
         if class_attr:
             class_attr += ' '
         class_attr += 'error'
         a_node.attrs['class'] = class_attr
         if a_node.attrs.get('href'):
             del a_node.attrs['href']
Beispiel #4
0
    def generateSearchIndex(self, doc):
        """Generate the search index."""
        js = ['window.searchData = [']
        js_module = ['window.searchDataModule = [']
        for entry in doc.top_level_entries.itervalues():
            akas, subentries, headerfile = '', '', ''
            if hasattr(entry, 'akas'):
                akas = ','.join(entry.akas)
            if hasattr(entry, 'subentries'):
                subentries = []
                for t in entry.subentries.values():
                    for s in t:
                        sID = s.title
                        title = proc_doc.splitSecondLevelEntry(s.title)[1]
                        subentries.append({
                            'type': s.kind,
                            'name': s.name,
                            'title': title,
                            'id': sID
                        })
            if hasattr(entry, 'headerfiles') and len(entry.headerfiles) > 0:
                headerfile = entry.headerfiles[0]
                headerfile = headerfile[headerfile.find("/") + 1:-3]

            if entry in self.doc.doc_processor.topLevelEntry_filenames:
                delimiter = "/include/seqan/"
                srcfile = self.doc.doc_processor.topLevelEntry_filenames[entry]
                srcfile = srcfile[srcfile.find(delimiter) + len(delimiter):]
            else:
                srcfile = ""

            js.append(
                '  {title:%s,name:%s,text:%s,akas:%s,subentries:%s,loc:%s,langEntity:%s},'
                % (repr(entry.title), repr(
                    entry.name), repr(""), repr(akas), repr(subentries),
                   repr(self.path_converter.convert(
                       entry.name)[0]), repr(entry.kind)))
            js_module.append('  {definedIn:%s,srcfile:%s},' %
                             (repr(headerfile), repr(srcfile)))
        js.append('];')
        js_module.append('];')

        with open(os.path.join(self.out_dirs['js'], 'search.data.js'),
                  'wb') as f:
            f.write('\n'.join(js))
        with open(os.path.join(self.out_dirs['js'], 'search.data.module.js'),
                  'wb') as f:
            f.write('\n'.join(js_module))
Beispiel #5
0
 def convert(self, name):
     """Return None, None on failure path, title otherwise."""
     if self.doc.top_level_entries.get(name):
         entry = self.doc.top_level_entries.get(name)
         path = '%s_%s.html' % (entry.kind, escapeName(entry.name))
         title = None
         if entry.kind == 'page':
             title = list(entry.title.children)
         return path, title
     elif self.doc.entries.get(name):
         first, second = proc_doc.splitSecondLevelEntry(name)
         entry = self.doc.top_level_entries.get(first)
         path = '%s_%s.html#%s' % (entry.kind, escapeName(entry.name), escapeName(name))
         return path, name
     else:
         return None, None
Beispiel #6
0
 def convert(self, name):
     """Return None, None on failure path, title otherwise."""
     if self.doc.top_level_entries.get(name):
         entry = self.doc.top_level_entries.get(name)
         path = '%s_%s.html' % (entry.kind, escapeName(entry.name))
         title = None
         if entry.kind == 'page':
             title = list(entry.title.children)
         return path, title
     elif self.doc.entries.get(name):
         first, second = proc_doc.splitSecondLevelEntry(name)
         entry = self.doc.top_level_entries.get(first)
         path = '%s_%s.html#%s' % (entry.kind, escapeName(
             entry.name), escapeName(name))
         return path, name
     else:
         return None, None
Beispiel #7
0
 def generateSearchIndex(self, doc):
     """Generate the search index."""
     js = ['window.searchData = [']
     for entry in doc.top_level_entries.itervalues():
         akas, subentries = '', ''
         if hasattr(entry, 'akas'):
             akas = ','.join(entry.akas)
         if hasattr(entry, 'subentries'):
             xs = []
             for lst in entry.subentries.values():
                 xs += lst
             subentries = ','.join(['%s %s' % (s.kind, proc_doc.splitSecondLevelEntry(s.title)[1]) for s in xs])
         js.append('  {title:%s,text:%s,akas:%s,subentries:%s,loc:%s,langEntity:%s},' %
                   (repr(entry.name), repr(""), repr(akas), repr(subentries),
                    repr(self.path_converter.convert(entry.name)[0]),
                    repr(entry.kind)))
     js.append('];')
     with open(os.path.join(self.out_dirs['js'], 'search.data.js'), 'wb') as f:
         f.write('\n'.join(js))
Beispiel #8
0
    def generateSearchIndex(self, doc):
        """Generate the search index."""
        js = ['window.searchData = [']
        js_module = ['window.searchDataModule = [']
        for entry in doc.top_level_entries.itervalues():
            akas, subentries, headerfile = '', '', ''
            if hasattr(entry, 'akas'):
                akas = ','.join(entry.akas)
            if hasattr(entry, 'subentries'):
                subentries = []
                for t in entry.subentries.values():
                    for s in t:
                        sID = s.title
                        title = proc_doc.splitSecondLevelEntry(s.title)[1]
                        subentries.append({'type': s.kind, 'name': s.name, 'title': title, 'id': sID})
            if hasattr(entry, 'headerfiles') and len(entry.headerfiles) > 0 :
                headerfile = entry.headerfiles[0]
                headerfile = headerfile[headerfile.find("/")+1:-3]

            if entry in self.doc.doc_processor.topLevelEntry_filenames:
                delimiter = "/include/seqan/"
                srcfile = self.doc.doc_processor.topLevelEntry_filenames[entry]
                srcfile = srcfile[srcfile.find(delimiter)+len(delimiter):]
            else :
                srcfile = ""

            js.append('  {title:%s,name:%s,text:%s,akas:%s,subentries:%s,loc:%s,langEntity:%s},' %
                      (repr(entry.title), repr(entry.name), repr(""), repr(akas), repr(subentries),
                       repr(self.path_converter.convert(entry.name)[0]), repr(entry.kind)))
            js_module.append('  {definedIn:%s,srcfile:%s},' % (repr(headerfile), repr(srcfile)))
        js.append('];')
        js_module.append('];')

        with open(os.path.join(self.out_dirs['js'], 'search.data.js'), 'wb') as f:
            f.write('\n'.join(js))
        with open(os.path.join(self.out_dirs['js'], 'search.data.module.js'), 'wb') as f:
            f.write('\n'.join(js_module))