mirror of
https://github.com/KingDuckZ/kamokan.git
synced 2025-02-09 09:23:56 +00:00
Add langmap_dir setting.
Allows users to specify the path to the langmap dir for source-highlight.
This commit is contained in:
parent
fb4d99d62b
commit
0add0720d5
6 changed files with 12 additions and 8 deletions
|
@ -16,15 +16,15 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "list_highlight_langs.hpp"
|
#include "list_highlight_langs.hpp"
|
||||||
|
#include "settings_bag.hpp"
|
||||||
#include <srchilite/langmap.h>
|
#include <srchilite/langmap.h>
|
||||||
#include <boost/range/adaptor/map.hpp>
|
#include <boost/range/adaptor/map.hpp>
|
||||||
#include <boost/range/algorithm/copy.hpp>
|
#include <boost/range/algorithm/copy.hpp>
|
||||||
#include <boost/range/iterator_range_core.hpp>
|
#include <boost/range/iterator_range_core.hpp>
|
||||||
|
|
||||||
namespace tawashi {
|
namespace tawashi {
|
||||||
HighlightLangList list_highlight_langs() {
|
HighlightLangList list_highlight_langs (const SettingsBag& parSettings) {
|
||||||
const char langmap_path[] = "/usr/share/source-highlight";
|
srchilite::LangMap lang_map(parSettings.as_str("langmap_dir"), "lang.map");
|
||||||
srchilite::LangMap lang_map(langmap_path, "lang.map");
|
|
||||||
lang_map.open();
|
lang_map.open();
|
||||||
|
|
||||||
const auto lang_range = boost::make_iterator_range(lang_map.begin(), lang_map.end());
|
const auto lang_range = boost::make_iterator_range(lang_map.begin(), lang_map.end());
|
||||||
|
|
|
@ -21,7 +21,8 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace tawashi {
|
namespace tawashi {
|
||||||
|
class SettingsBag;
|
||||||
typedef std::vector<std::string> HighlightLangList;
|
typedef std::vector<std::string> HighlightLangList;
|
||||||
|
|
||||||
HighlightLangList list_highlight_langs();
|
HighlightLangList list_highlight_langs (const SettingsBag& parSettings);
|
||||||
} //namespace tawashi
|
} //namespace tawashi
|
||||||
|
|
|
@ -64,6 +64,7 @@ namespace {
|
||||||
parSettings.add_default("redis_db", "0");
|
parSettings.add_default("redis_db", "0");
|
||||||
parSettings.add_default("base_uri", "http://127.0.0.1");
|
parSettings.add_default("base_uri", "http://127.0.0.1");
|
||||||
parSettings.add_default("website_root", "html");
|
parSettings.add_default("website_root", "html");
|
||||||
|
parSettings.add_default("langmap_dir", "/usr/share/source-highlight");
|
||||||
}
|
}
|
||||||
} //unnamed namespace
|
} //unnamed namespace
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
namespace tawashi {
|
namespace tawashi {
|
||||||
PastieResponse::PastieResponse (const Kakoune::SafePtr<SettingsBag>& parSettings) :
|
PastieResponse::PastieResponse (const Kakoune::SafePtr<SettingsBag>& parSettings) :
|
||||||
Response(Response::ContentType, "text/html", "", parSettings, true),
|
Response(Response::ContentType, "text/html", "", parSettings, true),
|
||||||
|
m_langmap_dir(parSettings->as_str("langmap_dir")),
|
||||||
m_plain_text(false)
|
m_plain_text(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -37,7 +38,7 @@ namespace tawashi {
|
||||||
m_plain_text = true;
|
m_plain_text = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
srchilite::LangMap lang_map("/usr/share/source-highlight", "lang.map");
|
srchilite::LangMap lang_map(m_langmap_dir, "lang.map");
|
||||||
lang_map.open();
|
lang_map.open();
|
||||||
if (not cgi_env().query_string().empty())
|
if (not cgi_env().query_string().empty())
|
||||||
m_lang_file = lang_map.getFileName(cgi_env().query_string());
|
m_lang_file = lang_map.getFileName(cgi_env().query_string());
|
||||||
|
|
|
@ -31,6 +31,7 @@ namespace tawashi {
|
||||||
virtual void on_send (std::ostream& parStream) override;
|
virtual void on_send (std::ostream& parStream) override;
|
||||||
|
|
||||||
std::string m_lang_file;
|
std::string m_lang_file;
|
||||||
|
std::string m_langmap_dir;
|
||||||
bool m_plain_text;
|
bool m_plain_text;
|
||||||
};
|
};
|
||||||
} //namespace tawashi
|
} //namespace tawashi
|
||||||
|
|
|
@ -89,10 +89,10 @@ namespace tawashi {
|
||||||
return boost::make_optional(buffer.str());
|
return boost::make_optional(buffer.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
mstch::array make_mstch_langmap() {
|
mstch::array make_mstch_langmap (const SettingsBag& parSettings) {
|
||||||
mstch::array retval;
|
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)}});
|
retval.push_back(mstch::map{{"language_name", std::move(lang)}});
|
||||||
}
|
}
|
||||||
return retval;
|
return retval;
|
||||||
|
@ -130,7 +130,7 @@ namespace tawashi {
|
||||||
mstch::map mustache_context {
|
mstch::map mustache_context {
|
||||||
{"version", std::string{STRINGIZE(VERSION_MAJOR) "." STRINGIZE(VERSION_MINOR) "." STRINGIZE(VERSION_PATCH)}},
|
{"version", std::string{STRINGIZE(VERSION_MAJOR) "." STRINGIZE(VERSION_MINOR) "." STRINGIZE(VERSION_PATCH)}},
|
||||||
{"base_uri", m_settings->as_str("base_uri")},
|
{"base_uri", m_settings->as_str("base_uri")},
|
||||||
{"languages", make_mstch_langmap()}
|
{"languages", make_mstch_langmap(*m_settings)}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (m_redis) {
|
if (m_redis) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue