mirror of
https://github.com/Relintai/rcpp_framework.git
synced 2025-05-06 17:51:36 +02:00
Renamed the article struct in PagedArticle to PagedArticleEntry, and moved it to it's own file. Also made it inherit from reference.
This commit is contained in:
parent
3361d576de
commit
01c43bf369
@ -11,7 +11,7 @@
|
|||||||
void PagedArticle::handle_request_main(Request *request) {
|
void PagedArticle::handle_request_main(Request *request) {
|
||||||
const String r = request->get_current_path_segment();
|
const String r = request->get_current_path_segment();
|
||||||
|
|
||||||
Article *s = pages[r];
|
PagedArticleEntry *s = pages[r];
|
||||||
|
|
||||||
if (s == nullptr) {
|
if (s == nullptr) {
|
||||||
request->send_error(404);
|
request->send_error(404);
|
||||||
@ -94,7 +94,7 @@ void PagedArticle::load() {
|
|||||||
String ff = folder + "/" + fn;
|
String ff = folder + "/" + fn;
|
||||||
String wp = base_path + "/" + fn;
|
String wp = base_path + "/" + fn;
|
||||||
|
|
||||||
Article *a = load_folder(np, wp);
|
PagedArticleEntry *a = load_folder(np, wp);
|
||||||
|
|
||||||
if (a) {
|
if (a) {
|
||||||
|
|
||||||
@ -116,7 +116,7 @@ void PagedArticle::load() {
|
|||||||
generate_summaries();
|
generate_summaries();
|
||||||
}
|
}
|
||||||
|
|
||||||
Article *PagedArticle::load_folder(const String &folder, const String &path) {
|
PagedArticleEntry *PagedArticle::load_folder(const String &folder, const String &path) {
|
||||||
printf("PagedArticle: loading: %s\n", folder.c_str());
|
printf("PagedArticle: loading: %s\n", folder.c_str());
|
||||||
|
|
||||||
Vector<String> files;
|
Vector<String> files;
|
||||||
@ -152,7 +152,7 @@ Article *PagedArticle::load_folder(const String &folder, const String &path) {
|
|||||||
//todo
|
//todo
|
||||||
//std::sort(files.begin(), files.end());
|
//std::sort(files.begin(), files.end());
|
||||||
|
|
||||||
Article *article = new Article();
|
PagedArticleEntry *article = new PagedArticleEntry();
|
||||||
|
|
||||||
for (uint32_t i = 0; i < files.size(); ++i) {
|
for (uint32_t i = 0; i < files.size(); ++i) {
|
||||||
String file_path = folder;
|
String file_path = folder;
|
||||||
@ -202,12 +202,12 @@ Article *PagedArticle::load_folder(const String &folder, const String &path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PagedArticle::generate_summaries() {
|
void PagedArticle::generate_summaries() {
|
||||||
for (std::map<String, Article *>::iterator it = pages.begin(); it != pages.end(); ++it) {
|
for (std::map<String, PagedArticleEntry *>::iterator it = pages.begin(); it != pages.end(); ++it) {
|
||||||
generate_summary((*it).second);
|
generate_summary((*it).second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PagedArticle::generate_summary(Article *article) {
|
void PagedArticle::generate_summary(PagedArticleEntry *article) {
|
||||||
if (article->summary_page != "") {
|
if (article->summary_page != "") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -9,26 +9,7 @@
|
|||||||
#include "core/http/web_node.h"
|
#include "core/http/web_node.h"
|
||||||
|
|
||||||
#include "core/http/request.h"
|
#include "core/http/request.h"
|
||||||
|
#include "paged_article_entry.h"
|
||||||
struct Article {
|
|
||||||
String url;
|
|
||||||
String summary_page;
|
|
||||||
std::map<String, String *> pages;
|
|
||||||
FileCache *file_cache;
|
|
||||||
|
|
||||||
Article() {
|
|
||||||
file_cache = new FileCache();
|
|
||||||
}
|
|
||||||
~Article() {
|
|
||||||
for (std::map<String, String *>::iterator it = pages.begin(); it != pages.end(); ++it) {
|
|
||||||
delete ((*it).second);
|
|
||||||
}
|
|
||||||
|
|
||||||
pages.clear();
|
|
||||||
|
|
||||||
delete file_cache;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class PagedArticle : public WebNode {
|
class PagedArticle : public WebNode {
|
||||||
RCPP_OBJECT(PagedArticle, WebNode);
|
RCPP_OBJECT(PagedArticle, WebNode);
|
||||||
@ -37,14 +18,14 @@ public:
|
|||||||
void handle_request_main(Request *request);
|
void handle_request_main(Request *request);
|
||||||
|
|
||||||
void load();
|
void load();
|
||||||
Article *load_folder(const String &folder, const String &path);
|
PagedArticleEntry *load_folder(const String &folder, const String &path);
|
||||||
void generate_summaries();
|
void generate_summaries();
|
||||||
void generate_summary(Article *article);
|
void generate_summary(PagedArticleEntry *article);
|
||||||
|
|
||||||
PagedArticle();
|
PagedArticle();
|
||||||
~PagedArticle();
|
~PagedArticle();
|
||||||
|
|
||||||
std::map<String, Article *> pages;
|
std::map<String, PagedArticleEntry *> pages;
|
||||||
String folder;
|
String folder;
|
||||||
String base_path;
|
String base_path;
|
||||||
};
|
};
|
||||||
|
2
modules/paged_article/paged_article_entry.cpp
Normal file
2
modules/paged_article/paged_article_entry.cpp
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
#include "paged_article_entry.h"
|
||||||
|
|
37
modules/paged_article/paged_article_entry.h
Normal file
37
modules/paged_article/paged_article_entry.h
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#ifndef PAGED_ARTICLE_ENTRY_H
|
||||||
|
#define PAGED_ARTICLE_ENTRY_H
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include "core/containers/vector.h"
|
||||||
|
#include "core/string.h"
|
||||||
|
|
||||||
|
#include "core/file_cache.h"
|
||||||
|
#include "core/http/web_node.h"
|
||||||
|
|
||||||
|
#include "core/http/request.h"
|
||||||
|
|
||||||
|
#include "core/reference.h"
|
||||||
|
|
||||||
|
class PagedArticleEntry : public Reference {
|
||||||
|
RCPP_OBJECT(PagedArticleEntry, Reference);
|
||||||
|
public:
|
||||||
|
String url;
|
||||||
|
String summary_page;
|
||||||
|
std::map<String, String *> pages;
|
||||||
|
FileCache *file_cache;
|
||||||
|
|
||||||
|
PagedArticleEntry() {
|
||||||
|
file_cache = new FileCache();
|
||||||
|
}
|
||||||
|
~PagedArticleEntry() {
|
||||||
|
for (std::map<String, String *>::iterator it = pages.begin(); it != pages.end(); ++it) {
|
||||||
|
delete ((*it).second);
|
||||||
|
}
|
||||||
|
|
||||||
|
pages.clear();
|
||||||
|
|
||||||
|
delete file_cache;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user