Coverage for src/lcdoc/mkdocs/page_tree/__init__.py: 91.23%

Shortcuts on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

43 statements  

1from mkdocs.config import config_options lp

2from lcdoc.mkdocs.tools import MDPlugin, app lp

3from lcdoc.tools import read_file, write_file lp

4import os lp

5 

6exists = os.path.exists lp

7 

8 

9def url(base, p): lp

10 try: lplp|about/changelog.mdlp|about/coverage.mdlp|about/credits.mdlp|about/navigation.mdlp|features/lp/bash/index.mdlp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/chart/index.mdlp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/flowchart/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/make_badges/index.mdlp|features/lp/plugs/make_file/index.mdlp|features/lp/plugs/markmap/index.mdlp|features/lp/plugs/mermaid/index.mdlp|features/lp/plugs/show_file/index.mdlp|features/lp/plugs/show_src/index.mdlp|features/lp/python/_tech.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/tips.mdlp|features/lp/xterm.mdlp|index.mdlp|task_runner.md

11 return '/' + base + '/' + p.url lplp|about/changelog.mdlp|about/coverage.mdlp|about/credits.mdlp|about/navigation.mdlp|features/lp/bash/index.mdlp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/chart/index.mdlp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/flowchart/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/make_badges/index.mdlp|features/lp/plugs/make_file/index.mdlp|features/lp/plugs/markmap/index.mdlp|features/lp/plugs/mermaid/index.mdlp|features/lp/plugs/show_file/index.mdlp|features/lp/plugs/show_src/index.mdlp|features/lp/python/_tech.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/tips.mdlp|features/lp/xterm.mdlp|index.mdlp|task_runner.md

12 except Exception as ex: lp|about/changelog.mdlp|about/coverage.mdlp|about/credits.mdlp|about/navigation.mdlp|features/lp/bash/index.mdlp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/chart/index.mdlp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/flowchart/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/make_badges/index.mdlp|features/lp/plugs/make_file/index.mdlp|features/lp/plugs/markmap/index.mdlp|features/lp/plugs/mermaid/index.mdlp|features/lp/plugs/show_file/index.mdlp|features/lp/plugs/show_src/index.mdlp|features/lp/python/_tech.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/tips.mdlp|features/lp/xterm.mdlp|index.mdlp|task_runner.md

13 return url(base, p.children[0]) lp|about/changelog.mdlp|about/coverage.mdlp|about/credits.mdlp|about/navigation.mdlp|features/lp/bash/index.mdlp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/chart/index.mdlp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/flowchart/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/make_badges/index.mdlp|features/lp/plugs/make_file/index.mdlp|features/lp/plugs/markmap/index.mdlp|features/lp/plugs/mermaid/index.mdlp|features/lp/plugs/show_file/index.mdlp|features/lp/plugs/show_src/index.mdlp|features/lp/python/_tech.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/tips.mdlp|features/lp/xterm.mdlp|index.mdlp|task_runner.md

14 

15 

16def on_config_add_footer_partial(plugin, config): lp

17 s = '/lcdoc/' lp

18 fnf = __file__.split(s, 1)[0] + s + 'assets/mkdocs/lcd/partials/footer.html' lp

19 s = read_file(fnf) lp

20 d0 = config['theme'].dirs[0] lp

21 fnt = d0 + '/partials/footer.html' lp

22 if not exists(fnt): 22 ↛ 23line 22 didn't jump to line 23, because the condition on line 22 was never truelp

23 os.makedirs(d0 + '/partials', exist_ok=True) 

24 write_file(fnt, s) 

25 else: 

26 so = read_file(fnt) lp

27 if so == s: 27 ↛ 28line 27 didn't jump to line 28, because the condition on line 27 was never truelp

28 return app.info('footer.html alrady replaced') 

29 app.warning('Backing up original footer.html', orig=fnt, backup=fnt + '.orig') lp

30 write_file(fnt + '.org', so) lp

31 write_file(fnt, s) lp

32 app.warning('Have written lcd-page-tree aware footer', fn=fnf) lp

33 

34 

35class PageTreePlugin(MDPlugin): lp

36 config_scheme = (('join_string', config_options.Type(str, default=' - ')),) lp

37 

38 def on_config(self, config): lp

39 on_config_add_footer_partial(self, config) lp

40 

41 def on_pre_page(self, page, config, files): lp

42 # skip if pages are not yet included in the mkdocs config file 

43 if not page.title: lplp|about/changelog.mdlp|about/coverage.mdlp|about/credits.mdlp|about/navigation.mdlp|features/lp/bash/index.mdlp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/chart/index.mdlp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/flowchart/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/make_badges/index.mdlp|features/lp/plugs/make_file/index.mdlp|features/lp/plugs/markmap/index.mdlp|features/lp/plugs/mermaid/index.mdlp|features/lp/plugs/show_file/index.mdlp|features/lp/plugs/show_src/index.mdlp|features/lp/python/_tech.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/tips.mdlp|features/lp/xterm.mdlp|index.mdlp|task_runner.md

44 return page lp|about/navigation.mdlp|index.md

45 base = page.canonical_url.split('/', 4)[3] lplp|about/changelog.mdlp|about/coverage.mdlp|about/credits.mdlp|about/navigation.mdlp|features/lp/bash/index.mdlp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/chart/index.mdlp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/flowchart/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/make_badges/index.mdlp|features/lp/plugs/make_file/index.mdlp|features/lp/plugs/markmap/index.mdlp|features/lp/plugs/mermaid/index.mdlp|features/lp/plugs/show_file/index.mdlp|features/lp/plugs/show_src/index.mdlp|features/lp/python/_tech.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/tips.mdlp|features/lp/xterm.mdlp|index.mdlp|task_runner.md

46 join_str = self.config['join_string'] lplp|about/changelog.mdlp|about/coverage.mdlp|about/credits.mdlp|about/navigation.mdlp|features/lp/bash/index.mdlp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/chart/index.mdlp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/flowchart/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/make_badges/index.mdlp|features/lp/plugs/make_file/index.mdlp|features/lp/plugs/markmap/index.mdlp|features/lp/plugs/mermaid/index.mdlp|features/lp/plugs/show_file/index.mdlp|features/lp/plugs/show_src/index.mdlp|features/lp/python/_tech.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/tips.mdlp|features/lp/xterm.mdlp|index.mdlp|task_runner.md

47 me = [[page.title, url(base, page)]] lplp|about/changelog.mdlp|about/coverage.mdlp|about/credits.mdlp|about/navigation.mdlp|features/lp/bash/index.mdlp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/chart/index.mdlp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/flowchart/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/make_badges/index.mdlp|features/lp/plugs/make_file/index.mdlp|features/lp/plugs/markmap/index.mdlp|features/lp/plugs/mermaid/index.mdlp|features/lp/plugs/show_file/index.mdlp|features/lp/plugs/show_src/index.mdlp|features/lp/python/_tech.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/tips.mdlp|features/lp/xterm.mdlp|index.mdlp|task_runner.md

48 if page.ancestors: lplp|about/changelog.mdlp|about/coverage.mdlp|about/credits.mdlp|about/navigation.mdlp|features/lp/bash/index.mdlp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/chart/index.mdlp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/flowchart/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/make_badges/index.mdlp|features/lp/plugs/make_file/index.mdlp|features/lp/plugs/markmap/index.mdlp|features/lp/plugs/mermaid/index.mdlp|features/lp/plugs/show_file/index.mdlp|features/lp/plugs/show_src/index.mdlp|features/lp/python/_tech.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/tips.mdlp|features/lp/xterm.mdlp|index.mdlp|task_runner.md

49 tree_titles = [(x.title, url(base, x)) for x in page.ancestors[::-1]] + me lp|about/changelog.mdlp|about/coverage.mdlp|about/credits.mdlp|about/navigation.mdlp|features/lp/bash/index.mdlp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/chart/index.mdlp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/flowchart/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/make_badges/index.mdlp|features/lp/plugs/make_file/index.mdlp|features/lp/plugs/markmap/index.mdlp|features/lp/plugs/mermaid/index.mdlp|features/lp/plugs/show_file/index.mdlp|features/lp/plugs/show_src/index.mdlp|features/lp/python/_tech.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/tips.mdlp|features/lp/xterm.mdlp|index.mdlp|task_runner.md

50 page.parent_titles = join_str.join([str(x[0]) for x in tree_titles]) lp|about/changelog.mdlp|about/coverage.mdlp|about/credits.mdlp|about/navigation.mdlp|features/lp/bash/index.mdlp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/chart/index.mdlp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/flowchart/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/make_badges/index.mdlp|features/lp/plugs/make_file/index.mdlp|features/lp/plugs/markmap/index.mdlp|features/lp/plugs/mermaid/index.mdlp|features/lp/plugs/show_file/index.mdlp|features/lp/plugs/show_src/index.mdlp|features/lp/python/_tech.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/tips.mdlp|features/lp/xterm.mdlp|index.mdlp|task_runner.md

51 page.parent_links = tree_titles lp|about/changelog.mdlp|about/coverage.mdlp|about/credits.mdlp|about/navigation.mdlp|features/lp/bash/index.mdlp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/chart/index.mdlp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/flowchart/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/make_badges/index.mdlp|features/lp/plugs/make_file/index.mdlp|features/lp/plugs/markmap/index.mdlp|features/lp/plugs/mermaid/index.mdlp|features/lp/plugs/show_file/index.mdlp|features/lp/plugs/show_src/index.mdlp|features/lp/python/_tech.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/tips.mdlp|features/lp/xterm.mdlp|index.mdlp|task_runner.md

52 else: 

53 page.parent_titles = page.title lp

54 page.parent_links = [] lp

55 

56 return page lplp|about/changelog.mdlp|about/coverage.mdlp|about/credits.mdlp|about/navigation.mdlp|features/lp/bash/index.mdlp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/chart/index.mdlp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/flowchart/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/make_badges/index.mdlp|features/lp/plugs/make_file/index.mdlp|features/lp/plugs/markmap/index.mdlp|features/lp/plugs/mermaid/index.mdlp|features/lp/plugs/show_file/index.mdlp|features/lp/plugs/show_src/index.mdlp|features/lp/python/_tech.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/tips.mdlp|features/lp/xterm.mdlp|index.mdlp|task_runner.md