Permalink
Browse files

Merge pull request #12668 from aeslaughter/MooseDocs-content-sort-9638

Sort the source page list
  • Loading branch information...
moosebuild committed Jan 10, 2019
2 parents 340a309 + 88d85e5 commit d7d9c8d8f90f3ad38d18612c7ab33d3c390c3e06
@@ -11,6 +11,7 @@
!col! class=s12 m6 l6
## Information and Tools

- [A to Z Index](help/a-to-z.md)
- [Git](git.md)
- [Developer Tools](help/development/index.md)
- [Finite Element Concepts](finite_element_concepts/index.md)
@@ -0,0 +1 @@
!contents a-to-z
@@ -10,6 +10,7 @@

import os
import uuid
import collections
import mooseutils
from MooseDocs.base import components
from MooseDocs.tree import pages, tokens, html
@@ -19,7 +20,7 @@ def make_extension(**kwargs):
return ContentExtension(**kwargs)

Collapsible = tokens.newToken('Collapsible', summary=u'')
ContentToken = tokens.newToken('ContentToken', location=u'')
ContentToken = tokens.newToken('ContentToken', location=u'', level=None)
AtoZToken = tokens.newToken('AtoZToken', location=u'', level=None, buttons=bool)

class ContentExtension(command.CommandExtension):
@@ -37,6 +38,7 @@ def extend(self, reader, renderer):
self.addCommand(reader, AtoZCommand())
renderer.add('Collapsible', RenderCollapsible())
renderer.add('AtoZToken', RenderAtoZ())
renderer.add('ContentToken', RenderContentToken())

class ContentCommand(command.CommandComponent):
COMMAND = 'contents' #TODO: Change this to content after format is working
@@ -46,32 +48,11 @@ class ContentCommand(command.CommandComponent):
def defaultSettings():
settings = command.CommandComponent.defaultSettings()
settings['location'] = (None, "The markdown content directory to build contents.")
settings['level'] = (2, 'Heading level for top-level headings.')
return settings

def createToken(self, parent, info, page):

tree = dict()
tree[(u'',)] = core.UnorderedList(parent, browser_default=False)

location = self.settings['location']

func = lambda p: p.local.startswith(location) and isinstance(p, pages.Source)
nodes = self.translator.findPages(func)
for node in nodes:
key = tuple(node.local.strip(os.sep).replace(location, '').split(os.sep))[:-1]
for i in xrange(1, len(key) + 1):
k = key[:i]
if k not in tree:
col = Collapsible(tree[k[:-1]], summary=k[-1])
li = core.ListItem(col, class_='moose-source-item', tooltip=False)
tree[k] = core.UnorderedList(li, browser_default=False)

for node in nodes:
key = tuple(node.local.strip(os.sep).replace(location, '').split(os.sep))[:-1]
loc = node.relativeDestination(page)
li = core.ListItem(tree[key])
core.Link(li, url=loc, string=node.name, class_='moose-source-item', tooltip=False)

ContentToken(parent, location=self.settings['location'], level=self.settings['level'])
return parent

class AtoZCommand(command.CommandComponent):
@@ -88,6 +69,47 @@ def defaultSettings():
def createToken(self, parent, info, page):
return AtoZToken(parent, level=self.settings['level'], buttons=self.settings['buttons'])

class RenderContentToken(components.RenderComponent):

def createHTML(self, parent, token, page):
pass

def createMaterialize(self, parent, token, page):

location = token['location']
func = lambda p: p.local.startswith(location) and isinstance(p, pages.Source)
nodes = self.translator.findPages(func)
nodes.sort(key=lambda n: n.local)

headings = collections.defaultdict(list)
for node in nodes:
key = tuple(node.local.replace(location, '').strip(os.sep).split(os.sep))
head = key[0] if len(key) > 1 else u''
headings[head].append((node.name, node.relativeDestination(page)))

headings = [(h, items) for h, items in headings.iteritems()]
headings.sort(key=lambda h: h[0])

# Build lists
for head, items in headings:

if head:
html.Tag(parent, 'h{}'.format(token['level']),
class_='moose-a-to-z',
string=unicode(head))

row = html.Tag(parent, 'div', class_='row')

for chunk in mooseutils.make_chunks(items, 3):
col = html.Tag(row, 'div', class_='col s12 m6 l4')
ul = html.Tag(col, 'ul', class_='moose-a-to-z')
for text, href in chunk:
li = html.Tag(ul, 'li')
html.Tag(li, 'a', href=href, string=unicode(text.replace('.md', '')))

def createLatex(self, parent, token, page):
return None

class RenderCollapsible(components.RenderComponent):
def createHTML(self, parent, token, page):

@@ -100,7 +122,6 @@ def createHTML(self, parent, token, page):
def createLatex(self, parent, token, page):
pass


class RenderAtoZ(components.RenderComponent):
def createHTML(self, parent, token, page):
pass
@@ -1 +1 @@
<!DOCTYPE html><head><link href="../contrib/katex/katex.min.css" rel="stylesheet" type="text/css"></link><script src="../contrib/katex/katex.min.js" type="text/javascript"></script><script src="../contrib/plotly/plotly.min.js" type="text/javascript"></script></head><body><h1 id="content-extension">Content Extension</h1><ul><details><summary><span class="moose-section-icon"></span><span>folder</span></summary><li class="moose-source-item"><ul><li><a class="moose-source-item" href="folder/folder.html">folder.md</a></li><li><a class="moose-source-item" href="folder/index.html">index.md</a></li></ul></li></details><li><a class="moose-source-item" href="devel.html">devel.md</a></li><li><a class="moose-source-item" href="layout.html">layout.md</a></li><li><a class="moose-source-item" href="table.html">table.md</a></li><li><a class="moose-source-item" href="preamble.html">preamble.md</a></li><li><a class="moose-source-item" href="core.html">core.md</a></li><li><a class="moose-source-item" href="config.html">config.md</a></li><li><a class="moose-source-item" href="listing_include.html">listing_include.md</a></li><li><a class="moose-source-item" href="navigation.html">navigation.md</a></li><li><a class="moose-source-item" href="package.html">package.md</a></li><li><a class="moose-source-item" href="media.html">media.md</a></li><li><a class="moose-source-item" href="include.html">include.md</a></li><li><a class="moose-source-item" href="first.html">first.md</a></li><li><a class="moose-source-item" href="listing.html">listing.md</a></li><li><a class="moose-source-item" href="plotly.html">plotly.md</a></li><li><a class="moose-source-item" href="content.html">content.md</a></li><li><a class="moose-source-item" href="katex.html">katex.md</a></li><li><a class="moose-source-item" href="katex_include.html">katex_include.md</a></li><li><a class="moose-source-item" href="alert.html">alert.md</a></li><li><a class="moose-source-item" href="materialicon.html">materialicon.md</a></li><li><a class="moose-source-item" href="amendments.html">amendments.md</a></li><li><a class="moose-source-item" href="common.html">common.md</a></li><li><a class="moose-source-item" href="bibtex.html">bibtex.md</a></li><li><a class="moose-source-item" href="second.html">second.md</a></li><li><a class="moose-source-item" href="autolink.html">autolink.md</a></li><li><a class="moose-source-item" href="appsyntax.html">appsyntax.md</a></li><li><a class="moose-source-item" href="gallery.html">gallery.md</a></li><li><a class="moose-source-item" href="acronym.html">acronym.md</a></li></ul></body>
<!DOCTYPE html><head><link href="../contrib/katex/katex.min.css" rel="stylesheet" type="text/css"></link><script src="../contrib/katex/katex.min.js" type="text/javascript"></script><script src="../contrib/plotly/plotly.min.js" type="text/javascript"></script></head><body><h1 id="content-extension">Content Extension</h1></body>
Oops, something went wrong.

0 comments on commit d7d9c8d

Please sign in to comment.