コード例 #1
0
ファイル: devel.py プロジェクト: real-THU/moose-1
 def createHTML(self, token, parent):
     div = html.Tag(parent, 'div', class_='moose-example')
     left = html.Tag(div, 'div', class_='moose-example-code')
     ast = tokens.Code(left, code=token.data)
     self.translator.renderer.process(left, ast)
     html.Tag(div, 'div', class_='moose-example-rendered')
コード例 #2
0
 def createHTML(self, parent, token, page):
     return html.Tag(parent, 'br', close=False)
コード例 #3
0
 def createHTML(self, parent, token, page):  #pylint: disable=no-self-use,unused-argument
     return html.Tag(parent, 'ol', token)
コード例 #4
0
    def createHTML(self, token, parent):

        citep = token.cite == 'citep'
        if citep:
            html.String(parent, content=u'(')

        num_keys = len(token.keys)
        for i, key in enumerate(token.keys):

            if key not in self.extension.database.entries:
                msg = 'Unknown BibTeX key: {}'
                raise exceptions.RenderException(msg, key)

            entry = self.extension.database.entries[key]
            author_found = True
            if not 'author' in entry.persons.keys(
            ) and not 'Author' in entry.persons.keys():
                author_found = False
                entities = ['institution', 'organization']
                for entity in entities:
                    if entity in entry.fields.keys():
                        author_found = True
                        name = ''
                        for word in entry.fields[entity]:
                            if word[0].isupper():
                                name += word[0]
                        entry.persons['author'] = [Person(name)]

            if not author_found:
                msg = 'No author, institution, or organization for {}'
                raise exceptions.RenderException(msg, key)

            a = entry.persons['author']
            n = len(a)
            if n > 2:
                author = '{} et al.'.format(' '.join(a[0].last_names))
                #print 'AUTHOR:', author
            elif n == 2:
                a0 = ' '.join(a[0].last_names)
                a1 = ' '.join(a[1].last_names)
                author = '{} and {}'.format(a0, a1)
            else:
                author = ' '.join(a[0].last_names)

            form = u'{}, {}' if citep else u'{} ({})'
            html.Tag(parent,
                     'a',
                     href='#{}'.format(key),
                     string=form.format(author, entry.fields['year']))

            if citep:
                if num_keys > 1 and i != num_keys - 1:
                    html.String(parent, content=u'; ')
            else:
                if num_keys == 2 and i == 0:
                    html.String(parent, content=u' and ')
                elif num_keys > 2 and i == num_keys - 2:
                    html.String(parent, content=u', and ')
                elif num_keys > 2 and i != num_keys - 1:
                    html.String(parent, content=u', ')

        if citep:
            html.String(parent, content=u')')

        return parent
コード例 #5
0
 def createHTML(self, parent, token, page):  #pylint: disable=no-self-use
     if not token.get('id'):
         token['id'] = token.text('-').lower()
     return html.Tag(parent, 'h{}'.format(token['level']), token)
コード例 #6
0
def _insert_parameter(parent, name, param):
    """
    Insert parameter in to the supplied <ul> tag.

    Input:
        parent[html.Tag]: The 'ul' tag that parameter <li> item is to belong.
        name[str]: The name of the parameter.
        param: The parameter object from JSON dump.
    """

    if param['deprecated']:
        return

    li = html.Tag(parent, 'li')
    header = html.Tag(li, 'div', class_='collapsible-header')
    body = html.Tag(li, 'div', class_='collapsible-body')

    html.Tag(header, 'span', class_='moose-parameter-name', string=name)
    default = _format_default(param)
    if default:
        html.Tag(header,
                 'span',
                 class_='moose-parameter-header-default',
                 string=default)

        p = html.Tag(body, 'p', class_='moose-parameter-description-default')
        html.Tag(p, 'span', string='Default:')
        html.String(p, content=default)

    cpp_type = param['cpp_type']
    p = html.Tag(body, 'p', class_='moose-parameter-description-cpptype')
    html.Tag(p, 'span', string='C++ Type:')
    html.String(p, content=cpp_type)

    if 'options' in param:
        p = html.Tag(body, 'p', class_='moose-parameter-description-options')
        html.Tag(p, 'span', string='Options:')
        html.String(p, content=param['options'])

    p = html.Tag(body, 'p', class_='moose-parameter-description')
    desc = param['description']
    if desc:
        html.Tag(header,
                 'span',
                 class_='moose-parameter-header-description',
                 string=str(desc))
        html.Tag(p, 'span', string='Description:')
        html.String(p, content=str(desc))
コード例 #7
0
ファイル: layout.py プロジェクト: lszeng-hnu/moose
 def createMaterialize(self, parent, token, page):
     row = html.Tag(parent, 'div', token)
     row.addClass('row')
     return row
コード例 #8
0
ファイル: core.py プロジェクト: LiuPengPeter/moose-1
 def createHTML(self, parent, token, page): #pylint: disable=no-self-use
     div = html.Tag(parent, 'div', token)
     div.addClass("moose-exception")
     html.String(div, content=token.info[0])
     return div
コード例 #9
0
ファイル: core.py プロジェクト: LiuPengPeter/moose-1
    def createMaterialize(self, parent, token, page): #pylint: disable=no-self-use

        id_ = uuid.uuid4()
        a = html.Tag(parent, 'a', class_="moose-exception modal-trigger", href='#{}'.format(id_))
        if token.info:
            html.String(a, content=token.info[0])

        modal = html.Tag(parent.root, 'div', id_=id_, class_="modal")
        content = html.Tag(modal, 'div', class_="modal-content")
        head = html.Tag(content, 'h2')
        html.String(head, content=u'Tokenize Error')
        p = html.Tag(content, 'p')

        html.String(p, content=unicode(token['message']))
        html.Tag(p, 'br', close=False)
        if token.info:
            html.String(p, content=u'{}:{}'.format(page.local, token.info.line))
        html.Tag(p, 'br', close=False)

        if token.info:
            pre = html.Tag(content, 'pre')
            code = html.Tag(pre, 'code', class_="language-markdown")
            html.String(code, content=token.info[0], escape=True)

        footer = html.Tag(modal, 'div', class_="modal-footer grey lighten-3")
        done = html.Tag(footer, 'a', class_="modal-action modal-close btn-flat")
        html.String(done, content=u"Done")

        trace = token.get('traceback', None)
        if trace is not None:
            pre = html.Tag(content, 'pre', style="font-size:80%;")
            html.String(pre, content=trace, escape=True)

        return content
コード例 #10
0
 def createMaterialize(self, parent, token, page):  #pylint: disable=no-self-use,unused-argument
     i = html.Tag(parent,
                  'i',
                  class_='material-icons moose-inline-icon',
                  **token.attributes)
     html.String(i, content=token['icon'], hide=True)
コード例 #11
0
 def createMaterialize(self, parent, token, page):  #pylint: disable=no-self-use,unused-argument
     div = html.Tag(parent, 'div', class_='icon-block')
     return div
コード例 #12
0
ファイル: bibtex.py プロジェクト: llarsen71/moose
    def createHTML(self, parent, token, page):

        cite = token['cite']
        if cite == 'nocite':
            return parent

        citep = cite == 'citep'
        if citep:
            html.String(parent, content=u'(')

        num_keys = len(token['keys'])
        for i, key in enumerate(token['keys']):

            if key not in self.extension.database.entries:
                LOG.error('Unknown BibTeX key: %s', key)
                html.Tag(parent, 'span', string=key, style='color:red;')
                continue

            entry = self.extension.database.entries[key]
            author_found = True
            if not 'author' in entry.persons.keys(
            ) and not 'Author' in entry.persons.keys():
                author_found = False
                entities = ['institution', 'organization']
                for entity in entities:
                    if entity in entry.fields.keys():
                        author_found = True
                        name = ''
                        for word in entry.fields[entity]:
                            if word[0].isupper():
                                name += word[0]
                        entry.persons['author'] = [Person(name)]

            if not author_found:
                msg = 'No author, institution, or organization for {}'
                raise exceptions.MooseDocsException(msg, key)

            a = entry.persons['author']
            n = len(a)
            if n > 2:
                author = '{} et al.'.format(' '.join(a[0].last_names))
            elif n == 2:
                a0 = ' '.join(a[0].last_names)
                a1 = ' '.join(a[1].last_names)
                author = '{} and {}'.format(a0, a1)
            else:
                author = ' '.join(a[0].last_names)
            author = LatexNodes2Text().latex_to_text(author)

            form = u'{}, {}' if citep else u'{} ({})'
            html.Tag(parent,
                     'a',
                     href='#{}'.format(key),
                     string=form.format(author, entry.fields['year']))

            if citep:
                if num_keys > 1 and i != num_keys - 1:
                    html.String(parent, content=u'; ')
            else:
                if num_keys == 2 and i == 0:
                    html.String(parent, content=u' and ')
                elif num_keys > 2 and i == num_keys - 2:
                    html.String(parent, content=u', and ')
                elif num_keys > 2 and i != num_keys - 1:
                    html.String(parent, content=u', ')

        if citep:
            html.String(parent, content=u')')

        return parent
コード例 #13
0
 def createHTML(self, token, parent):  #pylint: disable=unused-argument
     return html.Tag(parent, self.__tag)
コード例 #14
0
 def createHTML(self, token, parent):  #pylint: disable=no-self-use
     div = html.Tag(parent, 'div', **token.attributes)
     div.addClass('moose-table-div')
     tbl = html.Tag(div, 'table')
     return tbl
コード例 #15
0
 def createMaterialize(self, parent, token, page):
     class_ = 'collection-header' if token['header'] else 'collection-item'
     return html.Tag(parent, 'li', class_=class_)
コード例 #16
0
ファイル: core.py プロジェクト: LiuPengPeter/moose-1
 def createHTML(self, parent, token, page):
     return html.Tag(parent, 'p', class_='moose-disabled')
コード例 #17
0
 def createHTML(self, parent, token, page):
     return html.Tag(parent, 'span', class_='moose-parameter-name')
コード例 #18
0
 def testTag(self):
     tag = html.Tag(None, 'section')
     self.assertEqual(tag.write(), '<section></section>')
コード例 #19
0
ファイル: layout.py プロジェクト: lszeng-hnu/moose
 def createHTML(self, parent, token, page):
     row = html.Tag(parent, 'div', token)
     row.addClass('moose-row')
     row.addStyle('display:flex')
     return row
コード例 #20
0
 def testTagString(self):
     tag = html.Tag(None, 'h1')
     html.String(content='foo', parent=tag)
     self.assertEqual(tag.write(), '<h1>foo</h1>')
コード例 #21
0
ファイル: layout.py プロジェクト: lszeng-hnu/moose
 def createHTML(self, parent, token, page):
     col = html.Tag(parent, 'div', token)
     col.addStyle('flex:{};'.format(token['width']))
     col.addClass('moose-column')
     return col
コード例 #22
0
ファイル: floats.py プロジェクト: chrisjsewell/moose
 def createHTML(self, parent, token, page):  #pylint: disable=no-self-use
     div = html.Tag(parent, 'div', token)
     div.addClass('moose-float-div')
     return div
コード例 #23
0
 def createHTML(self, parent, token, page):  #pylint: disable=no-self-use
     return html.Tag(parent, 'img', token, src=token['src'])
コード例 #24
0
ファイル: floats.py プロジェクト: chrisjsewell/moose
 def createMaterialize(self, parent, token, page):
     return html.Tag(parent, 'h4')
コード例 #25
0
 def createHTML(self, parent, token, page):  #pylint: disable=no-self-use
     code = html.Tag(parent, 'code')
     html.String(code, content=token['content'], escape=True)
     return code
コード例 #26
0
 def createHTML(self, parent, token, page):
     div = html.Tag(parent, 'div', token, class_='moose-syntax-list')
     return div
コード例 #27
0
 def createHTML(self, parent, token, page):  #pylint: disable=no-self-use
     return html.Tag(parent, 'a', token, href=token['url'])
コード例 #28
0
 def createMaterialize(self, parent, token, page):
     collection = html.Tag(
         parent, 'ul', class_='moose-syntax-list collection with-header')
     return collection
コード例 #29
0
 def createHTML(self, parent, token, page):  #pylint: disable=no-self-use
     return html.Tag(parent, 'sub', token)
コード例 #30
0
ファイル: renderers.py プロジェクト: ypachaur/moose
    def _addSearch(self, config, nav, root_page): #pylint: disable=no-self-use
        """
        Add search bar to the navigation bar.

        Inputs:
            nav[html.Tag]: The <div> containing the navigation for the page being generated.
            root_page[page.PageNodeBase]: The current page being converted.

        TODO:  The content of this method and most of the other methods in this class should be
               moved to extensions. The extension should create a SearchToken at the top level
               of the AST (i.e., in preTokenize). The render method should inject the search in to
               the navigation bar (which could be another but require extension). Doing this
               would make this class much simpler and keep the overall design almost exclusively
               plugin based. The MaterializeRender should be as close to as empty as possible.
        """

        # Do nothing if navigation is not provided
        search = config.get('search', True)
        if (not search) or (root_page is None):
            return

        # Search button
        btn = html.Tag(nav, 'a', class_="modal-trigger", href="#moose-search")
        html.Tag(btn, 'i', string=u'search', class_="material-icons")

        # Search modal
        div = html.Tag(nav.root.find('header'), 'div', id_="moose-search",
                       class_="modal modal-fixed-footer moose-search-modal")
        container = html.Tag(div, 'div',
                             class_="modal-content container moose-search-modal-content")
        row = html.Tag(container, 'div', class_="row")
        col = html.Tag(row, 'div', class_="col l12")
        box_div = html.Tag(col, 'div', class_="input-field")
        box = html.Tag(box_div, 'input', type_='text', id_="moose-search-box",
                       onkeyup="mooseSearch()", autocomplete="off")
        html.Tag(box, 'label', for_="search", string=unicode(config['home']))
        result_wrapper = html.Tag(row, 'div')
        html.Tag(result_wrapper, 'div', id_="moose-search-results", class_="col s12")
        footer = html.Tag(div, 'div', class_="modal-footer")
        html.Tag(footer, 'a', href='#!', class_="modal-action modal-close btn-flat",
                 string=u'Close')