Skip to content

Commit

Permalink
fix directory titles when underscores are present (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
svenevs authored Dec 1, 2021
1 parent 7a4aaf5 commit aade90e
Show file tree
Hide file tree
Showing 14 changed files with 384 additions and 10 deletions.
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ v0.2.4
the doxygen-breathe-exhale-sphinx ecosystem (and consequently, encouraging me to
resume work on this project).
- Escape ``*`` in template page titles (:pr:`118`).
- Fix titles / links for directories with underscores (:pr:`127`).

v0.2.3
----------------------------------------------------------------------------------------
Expand Down
20 changes: 13 additions & 7 deletions docs/testing/projects.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,51 @@ Testing Projects Module
.. automodule:: testing.projects
:members:

`` testing.projects.c_maths`` Project
``testing.projects.c_maths`` Project
----------------------------------------------------------------------------------------

.. automodule:: testing.projects.c_maths
:members:

`` testing.projects.cpp with spaces`` Project
``testing.projects.cpp with spaces`` Project
----------------------------------------------------------------------------------------

.. module:: testing.projects.cpp_with_spaces

This cannot be documented because it has spaces in the name and autodoc cannot
complete its import.

`` testing.projects.cpp_fortran_mixed`` Project
``testing.projects.cpp_fortran_mixed`` Project
----------------------------------------------------------------------------------------

.. automodule:: testing.projects.cpp_fortran_mixed
:members:

`` testing.projects.cpp_func_overloads`` Project
``testing.projects.cpp_func_overloads`` Project
----------------------------------------------------------------------------------------

.. automodule:: testing.projects.cpp_func_overloads
:members:

`` testing.projects.cpp_long_names`` Project
``testing.projects.cpp_long_names`` Project
----------------------------------------------------------------------------------------

.. automodule:: testing.projects.cpp_long_names
:members:

`` testing.projects.cpp_nesting`` Project
``testing.projects.cpp_dir_underscores`` Project
----------------------------------------------------------------------------------------

.. automodule:: testing.projects.cpp_dir_underscores
:members:

``testing.projects.cpp_nesting`` Project
----------------------------------------------------------------------------------------

.. automodule:: testing.projects.cpp_nesting
:members:

`` testing.projects.cpp_pimpl`` Project
``testing.projects.cpp_pimpl`` Project
----------------------------------------------------------------------------------------

.. automodule:: testing.projects.cpp_pimpl
Expand Down
6 changes: 6 additions & 0 deletions docs/testing/tests.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ Project Tests
.. automodule:: testing.tests.cpp_long_names
:members:

``cpp_dir_underscores``
----------------------------------------------------------------------------------------

.. automodule:: testing.tests.cpp_dir_underscores
:members:

``cpp_nesting``
----------------------------------------------------------------------------------------

Expand Down
3 changes: 2 additions & 1 deletion exhale/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -2378,7 +2378,8 @@ class view hierarchy (<a href="..."> for the ``createTreeView = True`` option).
if node.kind == "namespace":
title = node.name.split("::")[-1]
else:
title = os.path.basename(unique_id.replace("_", os.sep))
# NOTE: for files, node.name := basename(node.location) aka don't matter
title = os.path.basename(node.name)
else:
unique_id = node.refid

Expand Down
1 change: 1 addition & 0 deletions testing/projects/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ set(EXHALE_PROJECTS
c_maths
cpp_func_overloads
cpp_long_names
cpp_dir_underscores
cpp_nesting
cpp_pimpl
"cpp with spaces"
Expand Down
22 changes: 22 additions & 0 deletions testing/projects/cpp_dir_underscores/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
########################################################################################
# This file is dedicated to the public domain. If your jurisdiction requires a #
# specific license: #
# #
# Copyright (c) Stephen McDowell, 2017-2021 #
# License: CC0 1.0 Universal #
# License Text: https://creativecommons.org/publicdomain/zero/1.0/legalcode #
########################################################################################
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
project(cpp-dir-underscores LANGUAGES CXX)

# "Header only library": add tests and include the directory
target_sources(exhale-projects-unit-tests
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src/tests.cpp
)
target_include_directories(exhale-projects-tests-interface
INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}/include
)

add_open_cpp_coverage_source_dirs(include src)
66 changes: 66 additions & 0 deletions testing/projects/cpp_dir_underscores/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
"""
The ``cpp_dir_underscores`` test project.
It primarily exists to make sure directories with underscores in their titles
get the correct link and title names (since exhale uses underscores internally).
"""

from testing.hierarchies import clike, directory, file, namespace


def default_class_hierarchy_dict():
"""Return the default class hierarchy dictionar."""
return {
namespace("interface_alpha"): {
clike("struct", "Alpha"): {},
namespace("one_two_three"): {
clike("struct", "OneTwoThree"): {},
},
namespace("four_five_six"): {
clike("struct", "FourFiveSix"): {}
}
},
namespace("interface_beta"): {
clike("struct", "Beta"): {}
}
}


def default_file_hierarchy_dict():
"""Return the default file hierarchy dictionary."""
return {
directory("include"): {
directory("interface_alpha"): {
file("alpha.hpp"): {
namespace("interface_alpha"): {
clike("struct", "Alpha"): {},
}
},
directory("one_two_three"): {
file("one_two_three.hpp"): {
namespace("interface_alpha"): {
namespace("one_two_three"): {
clike("struct", "OneTwoThree"): {},
}
}
},
},
directory("__four_five_six__"): {
file("__four_five_six__.hpp"): {
namespace("interface_alpha"): {
namespace("four_five_six"): {
clike("struct", "FourFiveSix"): {}
}
}
}
}
},
directory("interface_beta"): {
file("beta.hpp"): {
namespace("interface_beta"): {
clike("struct", "Beta"): {}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/***************************************************************************************
* This file is dedicated to the public domain. If your jurisdiction requires a *
* specific license: *
* *
* Copyright (c) Stephen McDowell, 2017-2021 *
* License: CC0 1.0 Universal *
* License Text: https://creativecommons.org/publicdomain/zero/1.0/legalcode *
**************************************************************************************/
#pragma once

#include <string>

namespace interface_alpha {
/// The ``four_five_six`` namespace.
namespace four_five_six {
/// The FourFiveSix struct.
struct FourFiveSix {
/// Returns ``"four_five_six"``.
std::string id() const { return "four_five_six"; }
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/***************************************************************************************
* This file is dedicated to the public domain. If your jurisdiction requires a *
* specific license: *
* *
* Copyright (c) Stephen McDowell, 2017-2021 *
* License: CC0 1.0 Universal *
* License Text: https://creativecommons.org/publicdomain/zero/1.0/legalcode *
**************************************************************************************/
#pragma once

#include <string>

/// The ``interface_alpha`` namespace.
namespace interface_alpha {
/// The Alpha struct.
struct Alpha {
/// Returns ``"alpha"``.
std::string id() const { return "alpha"; }
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/***************************************************************************************
* This file is dedicated to the public domain. If your jurisdiction requires a *
* specific license: *
* *
* Copyright (c) Stephen McDowell, 2017-2021 *
* License: CC0 1.0 Universal *
* License Text: https://creativecommons.org/publicdomain/zero/1.0/legalcode *
**************************************************************************************/
#pragma once

#include <string>

namespace interface_alpha {
/// The ``one_two_three`` namespace.
namespace one_two_three {
/// The OneTwoThree struct.
struct OneTwoThree {
/// Returns ``"one_two_three"``.
std::string id() const { return "one_two_three"; }
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/***************************************************************************************
* This file is dedicated to the public domain. If your jurisdiction requires a *
* specific license: *
* *
* Copyright (c) Stephen McDowell, 2017-2021 *
* License: CC0 1.0 Universal *
* License Text: https://creativecommons.org/publicdomain/zero/1.0/legalcode *
**************************************************************************************/
#pragma once

#include <string>

/// The ``interface_beta`` namespace.
namespace interface_beta {
/// The Beta struct.
struct Beta {
/// Returns ``"beta"``.
std::string id() const { return "beta"; }
};
}
41 changes: 41 additions & 0 deletions testing/projects/cpp_dir_underscores/src/tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/***************************************************************************************
* This file is dedicated to the public domain. If your jurisdiction requires a *
* specific license: *
* *
* Copyright (c) Stephen McDowell, 2017-2021 *
* License: CC0 1.0 Universal *
* License Text: https://creativecommons.org/publicdomain/zero/1.0/legalcode *
**************************************************************************************/
#include <catch2/catch.hpp>

/* ================================================================================== */

#include <interface_alpha/alpha.hpp>
TEST_CASE( "interface_alpha/alpha", "[cpp-dir-underscores]" ) {
interface_alpha::Alpha alpha;
REQUIRE( alpha.id() == "alpha" );
}

/* ================================================================================== */

#include <interface_alpha/one_two_three/one_two_three.hpp>
TEST_CASE( "interface_alpha/one_two_three", "[cpp-dir-underscores]") {
interface_alpha::one_two_three::OneTwoThree ott;
REQUIRE( ott.id() == "one_two_three" );
}

/* ================================================================================== */

#include <interface_alpha/__four_five_six__/__four_five_six__.hpp>
TEST_CASE( "interface_alpha/four_five_six", "[cpp-dir-underscores]") {
interface_alpha::four_five_six::FourFiveSix ffs;
REQUIRE( ffs.id() == "four_five_six" );
}

/* ================================================================================== */

#include <interface_beta/beta.hpp>
TEST_CASE( "interface_beta/beta", "[cpp-dir-underscores]") {
interface_beta::Beta beta;
REQUIRE( beta.id() == "beta" );
}
4 changes: 2 additions & 2 deletions testing/tests/configs_tree_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@
Directory <a href="dir_include_nested.html#dir-include-nested">nested</a>
<ul>
<li>
Directory <a href="dir_include_nested_dual_nested.html#dir-include-nested-dual-nested">nested</a>
Directory <a href="dir_include_nested_dual_nested.html#dir-include-nested-dual-nested">dual_nested</a>
<ul>
<li>
Directory <a href="dir_include_nested_dual_nested_one.html#dir-include-nested-dual-nested-one">one</a>
Expand Down Expand Up @@ -337,7 +337,7 @@
nodes: [
{
text: "<span class=\"text-muted\">Directory</span> nested",
text: "<span class=\"text-muted\">Directory</span> dual_nested",
href: "dir_include_nested_dual_nested.html#dir-include-nested-dual-nested",
selectable: false,
tags: ['2'],
Expand Down
Loading

0 comments on commit aade90e

Please # to comment.