From 0add0720d5de015088d3da8c2d8a878ebea0557d Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Sun, 23 Apr 2017 13:57:49 +0100 Subject: [PATCH] Add langmap_dir setting. Allows users to specify the path to the langmap dir for source-highlight. --- src/list_highlight_langs.cpp | 6 +++--- src/list_highlight_langs.hpp | 3 ++- src/main.cpp | 1 + src/pastie_response.cpp | 3 ++- src/pastie_response.hpp | 1 + src/response.cpp | 6 +++--- 6 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/list_highlight_langs.cpp b/src/list_highlight_langs.cpp index f7b367b..5b1b184 100644 --- a/src/list_highlight_langs.cpp +++ b/src/list_highlight_langs.cpp @@ -16,15 +16,15 @@ */ #include "list_highlight_langs.hpp" +#include "settings_bag.hpp" #include #include #include #include namespace tawashi { - HighlightLangList list_highlight_langs() { - const char langmap_path[] = "/usr/share/source-highlight"; - srchilite::LangMap lang_map(langmap_path, "lang.map"); + HighlightLangList list_highlight_langs (const SettingsBag& parSettings) { + srchilite::LangMap lang_map(parSettings.as_str("langmap_dir"), "lang.map"); lang_map.open(); const auto lang_range = boost::make_iterator_range(lang_map.begin(), lang_map.end()); diff --git a/src/list_highlight_langs.hpp b/src/list_highlight_langs.hpp index 76b409b..7a394ba 100644 --- a/src/list_highlight_langs.hpp +++ b/src/list_highlight_langs.hpp @@ -21,7 +21,8 @@ #include namespace tawashi { + class SettingsBag; typedef std::vector HighlightLangList; - HighlightLangList list_highlight_langs(); + HighlightLangList list_highlight_langs (const SettingsBag& parSettings); } //namespace tawashi diff --git a/src/main.cpp b/src/main.cpp index 6d1a5ee..b20c977 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -64,6 +64,7 @@ namespace { parSettings.add_default("redis_db", "0"); parSettings.add_default("base_uri", "http://127.0.0.1"); parSettings.add_default("website_root", "html"); + parSettings.add_default("langmap_dir", "/usr/share/source-highlight"); } } //unnamed namespace diff --git a/src/pastie_response.cpp b/src/pastie_response.cpp index 5ff2aab..78841c7 100644 --- a/src/pastie_response.cpp +++ b/src/pastie_response.cpp @@ -26,6 +26,7 @@ namespace tawashi { PastieResponse::PastieResponse (const Kakoune::SafePtr& parSettings) : Response(Response::ContentType, "text/html", "", parSettings, true), + m_langmap_dir(parSettings->as_str("langmap_dir")), m_plain_text(false) { } @@ -37,7 +38,7 @@ namespace tawashi { m_plain_text = true; } else { - srchilite::LangMap lang_map("/usr/share/source-highlight", "lang.map"); + srchilite::LangMap lang_map(m_langmap_dir, "lang.map"); lang_map.open(); if (not cgi_env().query_string().empty()) m_lang_file = lang_map.getFileName(cgi_env().query_string()); diff --git a/src/pastie_response.hpp b/src/pastie_response.hpp index 2576542..d80fa9c 100644 --- a/src/pastie_response.hpp +++ b/src/pastie_response.hpp @@ -31,6 +31,7 @@ namespace tawashi { virtual void on_send (std::ostream& parStream) override; std::string m_lang_file; + std::string m_langmap_dir; bool m_plain_text; }; } //namespace tawashi diff --git a/src/response.cpp b/src/response.cpp index 5bcfb5f..3e3ce9a 100644 --- a/src/response.cpp +++ b/src/response.cpp @@ -89,10 +89,10 @@ namespace tawashi { return boost::make_optional(buffer.str()); } - mstch::array make_mstch_langmap() { + mstch::array make_mstch_langmap (const SettingsBag& parSettings) { mstch::array retval; - for (auto&& lang : list_highlight_langs()) { + for (auto&& lang : list_highlight_langs(parSettings)) { retval.push_back(mstch::map{{"language_name", std::move(lang)}}); } return retval; @@ -130,7 +130,7 @@ namespace tawashi { mstch::map mustache_context { {"version", std::string{STRINGIZE(VERSION_MAJOR) "." STRINGIZE(VERSION_MINOR) "." STRINGIZE(VERSION_PATCH)}}, {"base_uri", m_settings->as_str("base_uri")}, - {"languages", make_mstch_langmap()} + {"languages", make_mstch_langmap(*m_settings)} }; if (m_redis) {