diff --git a/docs/css/version-select.css b/docs/css/version-select.css new file mode 100644 index 00000000..56e00f2a --- /dev/null +++ b/docs/css/version-select.css @@ -0,0 +1,5 @@ +#version-selector { + display: block; + margin: -10px auto 0.809em; + padding: 2px; +} diff --git a/docs/js/version-select.js b/docs/js/version-select.js new file mode 100644 index 00000000..3df2a71c --- /dev/null +++ b/docs/js/version-select.js @@ -0,0 +1,64 @@ +window.addEventListener("DOMContentLoaded", function() { + function normalizePath(path) { + var normalized = []; + path.split("/").forEach(function(bit, i) { + if (bit === "." || (bit === "" && i !== 0)) { + return; + } else if (bit === "..") { + if (normalized.length === 1 && normalized[0] === "") { + // We must be trying to .. past the root! + throw new Error("invalid path"); + } else if (normalized.length === 0 || + normalized[normalized.length - 1] === "..") { + normalized.push(".."); + } else { + normalized.pop(); + } + } else { + normalized.push(bit); + } + }); + return normalized.join("/"); + } + + // `base_url` comes from the base.html template for this theme. + var REL_BASE_URL = base_url; + var ABS_BASE_URL = normalizePath(window.location.pathname + "/" + + REL_BASE_URL); + var CURRENT_VERSION = ABS_BASE_URL.split("/").pop(); + + function makeSelect(options, selected) { + var select = document.createElement("select"); + + options.forEach(function(i) { + var option = new Option(i.text, i.value, undefined, + i.value === selected); + select.add(option); + }); + + return select; + } + + var xhr = new XMLHttpRequest(); + xhr.open("GET", REL_BASE_URL + "/../versions.json"); + xhr.onload = function() { + var versions = JSON.parse(this.responseText); + + var realVersion = versions.find(function(i) { + return i.version === CURRENT_VERSION || + i.aliases.includes(CURRENT_VERSION); + }).version; + + var select = makeSelect(versions.map(function(i) { + return {text: i.title, value: i.version}; + }), realVersion); + select.id = "version-selector"; + select.addEventListener("change", function(event) { + window.location.href = REL_BASE_URL + "/../" + this.value; + }); + + var title = document.querySelector("div.wy-side-nav-search"); + title.insertBefore(select, title.querySelector(".icon-home").nextSibling); + }; + xhr.send(); +}); diff --git a/mkdocs.yml b/mkdocs.yml index 9e7da1ab..674045c2 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -4,41 +4,43 @@ site_description: A meta-language for building Domain-Specific Languages (DSLs) site_author: Igor Dejanović repo_url: https://github.com/igordejanovic/textX -google_analytics: ['UA-68681917-1', 'igordejanovic.net'] +google_analytics: [UA-68681917-1, igordejanovic.net] theme: readthedocs -extra_css: ['style.css'] +extra_css: [style.css, css/version-select.css] -pages: +nav: - Home: index.md - User Guide: - - Grammar: grammar.md - - Meta-model: metamodel.md - - Model: model.md - - Scoping: scoping.md - - Multi meta-model: multimetamodel.md - - Parser configuration: parser_config.md - - Visualization: visualization.md - - Error handling: error_handling.md - - Debugging: debugging.md - - textx command: textx_command.md + - Grammar: grammar.md + - Meta-model: metamodel.md + - Model: model.md + - Scoping: scoping.md + - Multi meta-model: multimetamodel.md + - Parser configuration: parser_config.md + - Visualization: visualization.md + - Error handling: error_handling.md + - Debugging: debugging.md + - textx command: textx_command.md - Tutorials: - - Hello World: tutorials/hello_world.md - - Robot: tutorials/robot.md - - Entity: tutorials/entity.md - - State Machine: tutorials/state_machine.md - - Toy language compiler: tutorials/toylanguage.md + - Hello World: tutorials/hello_world.md + - Robot: tutorials/robot.md + - Entity: tutorials/entity.md + - State Machine: tutorials/state_machine.md + - Toy language compiler: tutorials/toylanguage.md - About: - - Comparison: about/comparison.md - - Discuss: about/discuss.md - - Contributing: about/contributing.md - - License: about/license.md + - Comparison: about/comparison.md + - Discuss: about/discuss.md + - Contributing: about/contributing.md + - License: about/license.md - What's new: - - Release 1.5: whatsnew/release_1_5.md + - Release 1.5: whatsnew/release_1_5.md markdown_extensions: - - admonition: - - toc: - permalink: True +- admonition: +- toc: + permalink: true -copyright: Copyright © 2016 Igor Dejanović. +copyright: Copyright © Igor Dejanović. +extra_javascript: +- js/version-select.js