NoTeX 1.0.0
A modern noteworthy LaTeX template
Loading...
Searching...
No Matches
manager.hpp
Go to the documentation of this file.
1
12
13#pragma once
14
15#include <cstddef>
16#include <filesystem>
17#include <optional>
18#include <string>
19#include <vector>
20
21#include "notex/templates.hpp"
22
23namespace notex {
24
38 std::string notex_version;
40 std::string project_type;
41 std::string main_file = "main.tex";
42 std::string installation_type;
44 std::string theme;
45 std::string bibliography_file;
46};
47
56 std::vector<std::filesystem::path> removed_files;
57 std::vector<std::filesystem::path> removed_directories;
58
61 std::size_t total_removed() const noexcept {
62 return removed_files.size() + removed_directories.size();
63 }
64};
65
74class Manager {
75public:
85 explicit Manager(
86 std::filesystem::path start_dir = std::filesystem::current_path());
87
95 static std::optional<std::filesystem::path> find_project_root(
96 const std::filesystem::path& start_dir);
97
100 const std::filesystem::path& root_dir() const noexcept {
101 return root_dir_;
102 }
103
105 const ProjectConfig& config() const noexcept { return config_; }
106
109 ProjectConfig& config() noexcept { return config_; }
110
115 void save() const;
116
140 static Manager init(const std::filesystem::path& target_dir,
141 templates::ProjectType project_type =
143 bool force = false);
144
158 static void write_config(const std::filesystem::path& root_dir,
159 const ProjectConfig& config);
160
183 static CleanReport clean(const std::filesystem::path& start_dir,
184 bool dry_run = false);
185
189 static std::vector<std::string> available_themes();
190
203 void set_theme(std::string_view theme);
204
221 void add_section(std::string_view title);
222
238 bool remove_section(int number);
239
255 void add_bibliography();
256
265 void remove_bibliography();
266
271 std::vector<std::filesystem::path> project_files() const;
272
278 std::vector<std::string> orphan_sections() const;
279
293 bool reset(bool force = false);
294
310 bool delete_scaffolding(bool remove_all = false, bool force = false);
311
324 void set_config_value(std::string_view key, std::string_view value);
325
326private:
327 static ProjectConfig load_config(
328 const std::filesystem::path& config_file);
329
330 std::filesystem::path root_dir_;
331 ProjectConfig config_;
332};
333
334} // namespace notex
Represents a single NoTeX project: its location and metadata.
Definition manager.hpp:74
bool delete_scaffolding(bool remove_all=false, bool force=false)
Removes NoTeX's own scaffolding from the project.
Definition manager.cpp:707
const std::filesystem::path & root_dir() const noexcept
Definition manager.hpp:100
void add_bibliography()
Adds a bibliography.
Definition manager.cpp:571
std::vector< std::string > orphan_sections() const
Definition manager.cpp:649
static CleanReport clean(const std::filesystem::path &start_dir, bool dry_run=false)
Recursively removes known LaTeX build artefacts from start_dir.
Definition manager.cpp:410
std::vector< std::filesystem::path > project_files() const
Definition manager.cpp:623
void set_config_value(std::string_view key, std::string_view value)
Sets a single whitelisted metadata key directly.
Definition manager.cpp:737
static std::optional< std::filesystem::path > find_project_root(const std::filesystem::path &start_dir)
Searches upward from start_dir for a .notex/ directory, without requiring one to exist.
Definition manager.cpp:279
void save() const
Persists the current metadata back to .notex/notex.json.
Definition manager.cpp:350
void add_section(std::string_view title)
Adds a new section titled title.
Definition manager.cpp:488
void remove_bibliography()
Removes the bibliography commands added by add_bibliography() from the main file.
Definition manager.cpp:602
void set_theme(std::string_view theme)
Switches the project's theme.
Definition manager.cpp:466
Manager(std::filesystem::path start_dir=std::filesystem::current_path())
Locates and loads the project that contains start_dir.
Definition manager.cpp:337
static void write_config(const std::filesystem::path &root_dir, const ProjectConfig &config)
Writes config as <root_dir>/.notex/notex.json, creating <root_dir>/.notex/ first if it does not alrea...
Definition manager.cpp:352
bool reset(bool force=false)
Regenerates the main file from the template, after backing up the previous one to <main_file>....
Definition manager.cpp:674
static std::vector< std::string > available_themes()
Definition manager.cpp:451
ProjectConfig & config() noexcept
Definition manager.hpp:109
static Manager init(const std::filesystem::path &target_dir, templates::ProjectType project_type=templates::ProjectType::MULTI, bool force=false)
Creates a new NoTeX project inside target_dir.
Definition manager.cpp:374
const ProjectConfig & config() const noexcept
Definition manager.hpp:105
bool remove_section(int number)
Removes the section numbered number.
Definition manager.cpp:519
@ MULTI
main.tex plus a sections/ directory of subfiles.
Definition templates.hpp:24
Outcome of a Manager::clean() call.
Definition manager.hpp:55
std::size_t total_removed() const noexcept
Definition manager.hpp:61
Persisted metadata for a single NoTeX project, stored as JSON in .notex/notex.json.
Definition manager.hpp:36
std::string notex_version
Definition manager.hpp:38
std::string main_file
Project's entry .tex file.
Definition manager.hpp:41
int schema_version
Version of this on-disk schema.
Definition manager.hpp:37
std::string theme
Set by the theme command.
Definition manager.hpp:44
std::string installation_type
Definition manager.hpp:42
std::string bibliography_file
Set once a bibliography exists.
Definition manager.hpp:45
std::string project_type
"mono" or "multi"; set by init.
Definition manager.hpp:40
templates: encoded skeletons used to scaffold new NoTeX projects.