Commit 6a83cc79 authored by Jan Köster's avatar Jan Köster
Browse files

more css plugin

parent 9ba921c7
Loading
Loading
Loading
Loading
+2 −0
Changes for plugins/survey/survey.cpp: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -86,6 +86,8 @@ namespace blogi {
        ~Survey() {}

        void initPlugin() {
            Args->theme->registerCss("/theme/public/survey.css", "SURVEY_CSS");

            registerGPO("254f20a3-d22e-4bf5-8bc8-4252cebde29d",
                        "Blogi: Survey Settings",
                        "Controls access to survey management",
+21 −6
Changes for src/theme.cpp: 21 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -207,6 +207,10 @@ blogi::Theme::~Theme(){
    // Destructor implementation
}

void blogi::Theme::registerCss(const std::string &publicPath, const std::string &variableName){
    _pluginCssMap[publicPath] = variableName;
}

std::string blogi::Theme::getLogoUrl(const int tid) const {
    std::string logoUrl;
    try { getConfig(*_Config.TDatabase[tid], "THEME_LOGO_URL", logoUrl); } catch (...) {}
@@ -266,14 +270,25 @@ void blogi::Theme::renderPage(const int tid,const char *name,libhtmlpp::HtmlPage
    // Inline CSS content as template variables to eliminate render-blocking requests
    const std::string prefix_placeholder = "${PREFIX}";
    const std::string& prefix_value = _Config.config.getprefix();

    // Built-in theme CSS mappings
    static const std::map<std::string, std::string> builtinCssMap = {
        {"/theme/public/reset.css",  "RESET_CSS"},
        {"/theme/public/style.css",  "STYLE_CSS"},
        {"/theme/public/mstyle.css", "MSTYLE_CSS"},
    };

    for(const auto& file : _PublicFiles){
        std::string css_key;
        if(file.Path == "/theme/public/reset.css")
            css_key = "RESET_CSS";
        else if(file.Path == "/theme/public/style.css")
            css_key = "STYLE_CSS";
        else if(file.Path == "/theme/public/mstyle.css")
            css_key = "MSTYLE_CSS";

        auto it = builtinCssMap.find(file.Path);
        if(it != builtinCssMap.end())
            css_key = it->second;
        else {
            auto pit = _pluginCssMap.find(file.Path);
            if(pit != _pluginCssMap.end())
                css_key = pit->second;
        }

        if(!css_key.empty()){
            std::string css = file.Content;
+6 −0
Changes for src/theme.h: 6 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -96,11 +96,17 @@ namespace blogi {
        /// Get the logo URL (configured or theme default)
        std::string getLogoUrl(const int tid) const;

        /// Register a plugin CSS file to be inlined as a template variable.
        /// publicPath: e.g. "/theme/public/survey.css"
        /// variableName: template key, e.g. "SURVEY_CSS"
        void registerCss(const std::string &publicPath, const std::string &variableName);

    private:
        ThemeConfig                                        _Config;
        std::vector<ThemeFiles>                             _PublicFiles;
        std::unordered_map<std::string, size_t>             _PublicFileIndex; // lowercase path -> index
        std::string                                        _PrefixLower;     // pre-computed lowercase prefix
        bool                                               _Formated;
        std::map<std::string, std::string>                 _pluginCssMap;    // publicPath -> variable name
    };
};