Skip to content

Commit

Permalink
TemplateMeta is now TemplateRenderer
Browse files Browse the repository at this point in the history
  • Loading branch information
DeaSTL committed Feb 6, 2024
1 parent 16e6138 commit 04670f6
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 36 deletions.
4 changes: 2 additions & 2 deletions include/Frate/Project/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Frate::Project {
Config() = default;
bool loaded_json{false};
std::filesystem::path template_path;
TemplateMeta current_template;
TemplateRenderer current_template;
std::vector<std::filesystem::path> template_files;
std::vector<std::filesystem::path> script_files;
std::string name{"default"};
Expand All @@ -40,7 +40,7 @@ namespace Frate::Project {

//Moving to local
[[deprecated("Use Local::build_command")]]
std::string build_command{"cmake --build ."};
std::string build_command{"cmake"};
[[deprecated("Use Local::test_command")]]
std::string test_command{"ctest"};
[[deprecated("Use Local::run_command")]]
Expand Down
14 changes: 7 additions & 7 deletions include/Frate/Template/Manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Frate::Project {
std::string branch;

std::unordered_map<std::string,
std::unordered_map<std::string, TemplateMeta>>
std::unordered_map<std::string, TemplateRenderer>>
installed;

bool index_loaded = false;
Expand All @@ -26,7 +26,7 @@ namespace Frate::Project {
* @param hash the hash of the template if it is installed
* @return true if the template is installed
*/
Project::TemplateMeta &find_template(const std::string &name,
Project::TemplateRenderer &find_template(const std::string &name,
std::string &hash);
/*
* Checks if a template specifed is installed
Expand All @@ -53,17 +53,17 @@ namespace Frate::Project {
/*
* Installs a template based on the local index, if hash is not provided then it will defult to the latest hash
*/
TemplateMeta install(TemplateIndexEntry &entry);
TemplateRenderer install(TemplateIndexEntry &entry);
/*
* Install the local latest based on the latest hash in the index is
* installed
* If there is no templates installed for the git url specified name then it will
* install that template
* @param git url of the template to install
*/
TemplateMeta getLatest(std::string &git_url);
TemplateMeta get(std::string &name,std::string &hash);
TemplateMeta promptList();
TemplateRenderer getLatest(std::string &git_url);
TemplateRenderer get(std::string &name,std::string &hash);
TemplateRenderer promptList();
/*
* Uninstalls a template
* @param name the name of the template to uninstall
Expand Down Expand Up @@ -96,7 +96,7 @@ namespace Frate::Project {
* @return a vector of TemplateMeta objects
*/
std::unordered_map<std::string,
std::unordered_map<std::string, TemplateMeta>> &
std::unordered_map<std::string, TemplateRenderer>> &
getInstalled();
/*
* Grabs the current index from the the github repo, if called more than
Expand Down
14 changes: 7 additions & 7 deletions include/Frate/Template/Meta.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Frate::Lua {
namespace Frate::Project {
class Config;

class TemplateMeta {
class TemplateRenderer {
private:
std::string name;
std::string description;
Expand Down Expand Up @@ -52,13 +52,13 @@ namespace Frate::Project {
void run_prompts(std::shared_ptr<Config> config);

public:
TemplateMeta();
TemplateMeta(const nlohmann::json &json_obj);
TemplateMeta(TemplateIndexEntry &entry);
friend void from_json(const nlohmann::json &json_obj, TemplateMeta &temp);
friend void to_json(nlohmann::json &json_obj, const TemplateMeta &temp);
TemplateRenderer();
TemplateRenderer(const nlohmann::json &json_obj);
TemplateRenderer(TemplateIndexEntry &entry);
friend void from_json(const nlohmann::json &json_obj, TemplateRenderer &temp);
friend void to_json(nlohmann::json &json_obj, const TemplateRenderer &temp);
friend std::ostream &operator<<(std::ostream &os_stream,
const TemplateMeta &temp);
const TemplateRenderer &temp);
/*
* Builds the template into the the project path
* and transfers the template config to the project config
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Actions/New.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace Frate::Command::New {
bool create(std::shared_ptr<Command::Interface> inter) {
Utils::info << "Creating Project" << std::endl;

Project::TemplateMeta current_template;
Project::TemplateRenderer current_template;

inter->templates->installAll();

Expand Down
1 change: 0 additions & 1 deletion src/Command/Actions/Run.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ namespace Frate::Command::Run {

bool run(std::shared_ptr<Interface> inter) {
options(inter);
// inter->loadProjectJson();
inter->pro->load();
inter->pro->current_template.refresh(inter->pro, inter->local);
std::cout << "Running project: " << inter->pro->name << std::endl;
Expand Down
12 changes: 6 additions & 6 deletions src/Template/Manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ namespace Frate::Project {
return is_installed(entry.getName(), branch);
}

Project::TemplateMeta &TemplateManager::find_template(const std::string &name,
Project::TemplateRenderer &TemplateManager::find_template(const std::string &name,
std::string &hash) {
if (!is_installed(name, hash)) {
throw TemplateNotInstalled("Template not installed");
Expand Down Expand Up @@ -168,7 +168,7 @@ namespace Frate::Project {
}

std::unordered_map<std::string,
std::unordered_map<std::string, Project::TemplateMeta>> &
std::unordered_map<std::string, Project::TemplateRenderer>> &
TemplateManager::getInstalled() {
return installed;
}
Expand Down Expand Up @@ -227,7 +227,7 @@ namespace Frate::Project {
}
}

TemplateMeta TemplateManager::getLatest(std::string &git_url) {
TemplateRenderer TemplateManager::getLatest(std::string &git_url) {
load_index();

for (TemplateIndexEntry template_info : index) {
Expand All @@ -244,7 +244,7 @@ namespace Frate::Project {
throw TemplateNotFoundInIndex("Template " + git_url + " not found in index");
}

TemplateMeta TemplateManager::promptList(){
TemplateRenderer TemplateManager::promptList(){

load_index();

Expand All @@ -270,7 +270,7 @@ namespace Frate::Project {
}
throw TemplateNotFoundInIndex("Template " + template_name + " not found in index");
};
TemplateMeta TemplateManager::get(std::string &name, std::string &hash) {
TemplateRenderer TemplateManager::get(std::string &name, std::string &hash) {

load_index();
for (TemplateIndexEntry template_info : index) {
Expand All @@ -290,7 +290,7 @@ namespace Frate::Project {
throw TemplateNotFoundInIndex("Template " + name + " not found in index");
}

TemplateMeta TemplateManager::install(TemplateIndexEntry &template_info) {
TemplateRenderer TemplateManager::install(TemplateIndexEntry &template_info) {
Utils::info << "Installing template: " << template_info.getName() << " on branch: " << branch << std::endl;


Expand Down
24 changes: 12 additions & 12 deletions src/Template/Meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@
namespace Frate::Project {
using std::filesystem::directory_entry;

TemplateMeta::TemplateMeta(const nlohmann::json &json_obj): install_path(Constants::INSTALLED_TEMPLATE_PATH / this->name / this->hash) {
TemplateRenderer::TemplateRenderer(const nlohmann::json &json_obj): install_path(Constants::INSTALLED_TEMPLATE_PATH / this->name / this->hash) {
Utils::verbose << "Creating template meta from json with contents: "
<< json_obj << std::endl;
from_json(json_obj, *this);
}

TemplateMeta::TemplateMeta(): install_path(Constants::INSTALLED_TEMPLATE_PATH / this->name / this->hash) {
TemplateRenderer::TemplateRenderer(): install_path(Constants::INSTALLED_TEMPLATE_PATH / this->name / this->hash) {
}

TemplateMeta::TemplateMeta(TemplateIndexEntry &entry)
TemplateRenderer::TemplateRenderer(TemplateIndexEntry &entry)
: name(entry.getName()), description(entry.getDescription()),
hash(entry.getBranchHash(Constants::TEMPLATE_BRANCH)), git(entry.getGit()),
install_path(Constants::INSTALLED_TEMPLATE_PATH / this->name /
this->hash) {}

void from_json(const nlohmann::json &json_obj, TemplateMeta &temp) {
void from_json(const nlohmann::json &json_obj, TemplateRenderer &temp) {
FROM_JSON_FIELD(temp, name);
FROM_JSON_FIELD(temp, description);
FROM_JSON_FIELD(temp, hash);
Expand All @@ -39,22 +39,22 @@ namespace Frate::Project {
temp.install_path = Constants::INSTALLED_TEMPLATE_PATH / temp.name / temp.hash;
}

void to_json(nlohmann::json &json_obj, const TemplateMeta &temp) {
void to_json(nlohmann::json &json_obj, const TemplateRenderer &temp) {
TO_JSON_FIELD(temp, name);
TO_JSON_FIELD(temp, description);
TO_JSON_FIELD(temp, hash);
TO_JSON_FIELD(temp, git);
}

std::ostream &operator<<(std::ostream &os_stream, const TemplateMeta &temp) {
std::ostream &operator<<(std::ostream &os_stream, const TemplateRenderer &temp) {
os_stream << "Name: " << temp.name << std::endl;
os_stream << "Description: " << temp.description << std::endl;
os_stream << "Hash: " << temp.hash << std::endl;
os_stream << "Git: " << temp.git << std::endl;
return os_stream;
}

void TemplateMeta::build(std::shared_ptr<Config> config, std::shared_ptr<Local> local) {
void TemplateRenderer::build(std::shared_ptr<Config> config, std::shared_ptr<Local> local) {

Utils::verbose << "Building template from template at: " << install_path
<< std::endl;
Expand Down Expand Up @@ -108,7 +108,7 @@ namespace Frate::Project {
render(config,local);
}

void TemplateMeta::refresh(std::shared_ptr<Config> config, std::shared_ptr<Local> local) {
void TemplateRenderer::refresh(std::shared_ptr<Config> config, std::shared_ptr<Local> local) {

std::filesystem::path override_path = config->path / "override";

Expand Down Expand Up @@ -144,7 +144,7 @@ namespace Frate::Project {
render(config,local);
}

void TemplateMeta::load_scripts() {
void TemplateRenderer::load_scripts() {
if (file_map.empty()) {
throw TemplateFileMapEmpty("File map is empty");
}
Expand Down Expand Up @@ -206,7 +206,7 @@ namespace Frate::Project {
scripts_loaded = true;
}

void TemplateMeta::run_prompts(std::shared_ptr<Config> config){
void TemplateRenderer::run_prompts(std::shared_ptr<Config> config){
for (auto [key, tmpl_prompt] : config->prompts) {
Utils::CLI::Prompt prompt(tmpl_prompt.text, tmpl_prompt.default_value);
if (tmpl_prompt.type == "bool") {
Expand All @@ -230,7 +230,7 @@ namespace Frate::Project {
}

}
void TemplateMeta::install_cpm(std::shared_ptr<Config> config) {
void TemplateRenderer::install_cpm(std::shared_ptr<Config> config) {
std::string cpm;

cpm = Utils::fetchText("https://raw.githubusercontent.com/cpm-cmake/"
Expand All @@ -250,7 +250,7 @@ namespace Frate::Project {
cpm_file << cpm;
}

void TemplateMeta::render(std::shared_ptr<Config> config, std::shared_ptr<Local> local) {
void TemplateRenderer::render(std::shared_ptr<Config> config, std::shared_ptr<Local> local) {
Utils::info << "Rendering template" << std::endl;
Utils::verbose << *this << std::endl;
this->env = std::make_shared<Lua::TemplateEnvironment>(config,local);
Expand Down

0 comments on commit 04670f6

Please sign in to comment.