def test_theme(self): mytheme = tempfile.mkdtemp() custom = tempfile.mkdtemp() configs = [ dict(), # default theme {"theme": "readthedocs"}, # builtin theme {"theme_dir": mytheme}, # custom only {"theme": "cosmo", "theme_dir": custom}, # builtin and custom ] abs_path = os.path.abspath(os.path.dirname(__file__)) mkdocs_dir = os.path.abspath(os.path.join(abs_path, '..', '..')) theme_dir = os.path.abspath(os.path.join(mkdocs_dir, 'themes')) search_asset_dir = os.path.abspath(os.path.join( mkdocs_dir, 'assets', 'search')) results = ( [os.path.join(theme_dir, 'mkdocs'), search_asset_dir], [os.path.join(theme_dir, 'readthedocs'), search_asset_dir], [mytheme, search_asset_dir], [custom, os.path.join(theme_dir, 'cosmo'), search_asset_dir], ) for config_contents, result in six.moves.zip(configs, results): c = config.Config(schema=( ('theme', config_options.Theme(default='mkdocs')), ('theme_dir', config_options.ThemeDir(exists=True)), )) c.load_dict(config_contents) c.validate() self.assertEqual(c['theme_dir'], result)
('site_description', config_options.Type(utils.string_types)), # The name of the author to add to the HTML meta tags ('site_author', config_options.Type(utils.string_types)), # The MkDocs theme for the documentation. ('theme', config_options.Theme(default='mkdocs')), # The directory containing the documentation markdown. ('docs_dir', config_options.Dir(default='docs', exists=True)), # The directory where the site will be built to ('site_dir', config_options.SiteDir(default='site')), # The directory of a theme to use if not using one of the builtin MkDocs # themes. ('theme_dir', config_options.ThemeDir(exists=True)), # A copyright notice to add to the footer of documentation. ('copyright', config_options.Type(utils.string_types)), # set of values for Google analytics containing the account IO and domain, # this should look like, ['UA-27795084-5', 'mkdocs.org'] ('google_analytics', config_options.Type(list, length=2)), # The address on which to serve the live reloading docs server. ('dev_addr', config_options.IpAddress(default='127.0.0.1:8000')), # If `True`, use `<page_name>/index.hmtl` style files with hyperlinks to # the directory.If `False`, use `<page_name>.html style file with # hyperlinks to the file. # True generates nicer URLs, but False is useful if browsing the output on
def test_theme(self): with TemporaryDirectory() as mytheme, TemporaryDirectory() as custom: configs = [ dict(), # default theme { "theme": "readthedocs" }, # builtin theme { "theme_dir": mytheme }, # custom only { "theme": "readthedocs", "theme_dir": custom }, # builtin and custom { "theme": { 'name': 'readthedocs' } }, # builtin as complex { "theme": { 'name': None, 'custom_dir': mytheme } }, # custom only as complex { "theme": { 'name': 'readthedocs', 'custom_dir': custom } }, # builtin and custom as complex { # user defined variables 'theme': { 'name': 'mkdocs', 'static_templates': ['foo.html'], 'show_sidebar': False, 'some_var': 'bar' } } ] mkdocs_dir = os.path.abspath(os.path.dirname(mkdocs.__file__)) mkdocs_templates_dir = os.path.join(mkdocs_dir, 'templates') theme_dir = os.path.abspath(os.path.join(mkdocs_dir, 'themes')) results = ({ 'dirs': [os.path.join(theme_dir, 'mkdocs'), mkdocs_templates_dir], 'static_templates': ['404.html', 'sitemap.xml'], 'vars': { 'include_search_page': False, 'search_index_only': False } }, { 'dirs': [os.path.join(theme_dir, 'readthedocs'), mkdocs_templates_dir], 'static_templates': ['404.html', 'sitemap.xml'], 'vars': { 'include_search_page': True, 'search_index_only': False } }, { 'dirs': [mytheme, mkdocs_templates_dir], 'static_templates': ['sitemap.xml'], 'vars': {} }, { 'dirs': [ custom, os.path.join(theme_dir, 'readthedocs'), mkdocs_templates_dir ], 'static_templates': ['404.html', 'sitemap.xml'], 'vars': { 'include_search_page': True, 'search_index_only': False } }, { 'dirs': [os.path.join(theme_dir, 'readthedocs'), mkdocs_templates_dir], 'static_templates': ['404.html', 'sitemap.xml'], 'vars': { 'include_search_page': True, 'search_index_only': False } }, { 'dirs': [mytheme, mkdocs_templates_dir], 'static_templates': ['sitemap.xml'], 'vars': {} }, { 'dirs': [ custom, os.path.join(theme_dir, 'readthedocs'), mkdocs_templates_dir ], 'static_templates': ['404.html', 'sitemap.xml'], 'vars': { 'include_search_page': True, 'search_index_only': False } }, { 'dirs': [os.path.join(theme_dir, 'mkdocs'), mkdocs_templates_dir], 'static_templates': ['404.html', 'sitemap.xml', 'foo.html'], 'vars': { 'show_sidebar': False, 'some_var': 'bar', 'include_search_page': False, 'search_index_only': False } }) for config_contents, result in zip(configs, results): c = config.Config(schema=( ('theme', config_options.Theme(default='mkdocs')), ('theme_dir', config_options.ThemeDir(exists=True)), )) c.load_dict(config_contents) errors, warnings = c.validate() self.assertEqual(len(errors), 0) self.assertEqual(c['theme'].dirs, result['dirs']) self.assertEqual(c['theme'].static_templates, set(result['static_templates'])) self.assertEqual( dict([(k, c['theme'][k]) for k in iter(c['theme'])]), result['vars'])