Skip to content

Commit

Permalink
feat: make page names dynamic in page functions
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbacsur committed Oct 13, 2024
1 parent ddf0a67 commit be39d51
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/cppx/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,14 @@ void copyAndProcessFiles(const std::filesystem::path& sourceDir, const std::file

if (destinationDir.string().find(".cppx/router") != std::string::npos) {
std::regex functionPattern(R"(\bPage\s+(\w+)\s*\()");
fileContent = std::regex_replace(fileContent, functionPattern, "Page page(");
std::smatch match;

std::string externDeclaration = "extern \"C\" PageFunction getPageFunction() { return &page; }\n";
fileContent += "\n" + externDeclaration;
if (std::regex_search(fileContent, match, functionPattern) && match.size() > 1) {
std::string pageName = match[1].str();
fileContent = std::regex_replace(fileContent, functionPattern, "Page " + pageName + "(");
std::string externDeclaration = "extern \"C\" PageFunction getPageFunction() { return &" + pageName + "; }\n";
fileContent += "\n" + externDeclaration;
}
}

writeFile(destinationPath, fileContent);
Expand Down

0 comments on commit be39d51

Please sign in to comment.