Skip to content

Commit

Permalink
DOCSP-7988: Add support for project title (#90)
Browse files Browse the repository at this point in the history
* DOCSP-7988: Add support for project title

* DOCSP-7988: Address PR feedback

* DOCSP-7988: Address PR feedback
  • Loading branch information
mango-db authored Jan 28, 2020
1 parent b180c27 commit 0c53820
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Support for defining a project's title (DOCSP-7988)

## [v0.2.0] - 2020-01-23

### Added
Expand Down
3 changes: 3 additions & 0 deletions snooty/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,9 @@ def get_page_ast(self, path: Path) -> SerializableType:
def get_project_name(self) -> str:
return self.config.name

def get_project_title(self) -> str:
return self.config.title

def update(self, path: Path, optional_text: Optional[str] = None) -> None:
diagnostics: Dict[PurePath, List[Diagnostic]] = {path: []}
prefix = get_giza_category(path)
Expand Down
4 changes: 3 additions & 1 deletion snooty/semanticparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ def run(

document: Dict[str, SerializableType] = {}

document.update({"title": self.project_config.title})

self.run_event_parser(
[
(OBJECT_START_EVENT, self.populate_include_nodes),
Expand Down Expand Up @@ -226,7 +228,7 @@ def build_toctree(self) -> Dict[str, SerializableType]:

# Build the toctree
root: Dict[str, SerializableType] = {
"title": self.project_config.name,
"title": self.project_config.title,
"slug": "/",
"children": [],
}
Expand Down
2 changes: 1 addition & 1 deletion snooty/test_semantic_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def test_toctree(backend: Backend) -> None:
],
},
],
"title": "test_data",
"title": "untitled",
"slug": "/",
}

Expand Down
3 changes: 2 additions & 1 deletion snooty/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def test_project() -> None:

# Test missing project behavior
project_config, project_diagnostics = ProjectConfig.open(Path(".").resolve())
assert project_config.name == "untitled"
assert project_config.name == "unnamed"
assert project_config.title == "untitled"
assert len(project_diagnostics) == 0


Expand Down
3 changes: 2 additions & 1 deletion snooty/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ def finish(
class ProjectConfig:
root: Path
name: str
title: str = field(default="untitled")
source: str = field(default="source")
constants: Dict[str, object] = field(default_factory=dict)
intersphinx: List[str] = field(default_factory=list)
Expand Down Expand Up @@ -401,7 +402,7 @@ def open(cls, root: Path) -> Tuple["ProjectConfig", List[Diagnostic]]:

path = path.parent

return cls(root, "untitled"), diagnostics
return cls(root, name="unnamed"), diagnostics

def render_constants(self) -> Tuple["ProjectConfig", List[Diagnostic]]:
if not self.constants:
Expand Down
3 changes: 2 additions & 1 deletion test_data/test_project/snooty.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
name = "test_data"

[constants]
name = "MongoDB"
name = "MongoDB name"
title = "MongoDB title"

[substitutions]
guides = "MongoDB Guides"
5 changes: 3 additions & 2 deletions test_data/test_semantic_parser/snooty.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name = "test_data"
name = "test_name"
toc_landing_pages = ["/page2", "page3"]
intersphinx = ["https://docs.mongodb.com/manual/objects.inv"]

[constants]
name = "MongoDB"
name = "MongoDB name"
title = "MongoDB title"

0 comments on commit 0c53820

Please sign in to comment.