1
0
Fork 0
mirror of https://github.com/KingDuckZ/kamokan.git synced 2024-11-27 00:43:47 +00:00

Export the list of supported languages to mustache.

This commit is contained in:
King_DuckZ 2017-04-21 20:56:18 +01:00
parent 3cd4aa461e
commit 4a194abd3a
5 changed files with 75 additions and 2 deletions

View file

@ -13,7 +13,7 @@
<select name="Language" class="selectBox">
<option value="None" selected="selected">None </option>
{{#languages}}
<option value="{{html_language_name}}">{{language_name}}</option>
<option value="{{language_name}}">{{language_name}}</option>
{{/languages}}
</select>

View file

@ -26,6 +26,7 @@ add_executable(${PROJECT_NAME}
ini_file.cpp
pathname/pathname.cpp
response_factory.cpp
list_highlight_langs.cpp
)
configure_file(

View file

@ -0,0 +1,34 @@
/* Copyright 2017, Michele Santullo
* This file is part of "tawashi".
*
* "tawashi" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* "tawashi" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with "tawashi". If not, see <http://www.gnu.org/licenses/>.
*/
#include "list_highlight_langs.hpp"
#include <srchilite/langmap.h>
#include <boost/range/adaptor/map.hpp>
#include <boost/range/algorithm/copy.hpp>
#include <boost/range/iterator_range_core.hpp>
namespace tawashi {
HighlightLangList list_highlight_langs() {
const char langmap_path[] = "/usr/share/source-highlight";
srchilite::LangMap lang_map(langmap_path, "lang.map");
lang_map.open();
const auto lang_range = boost::make_iterator_range(lang_map.begin(), lang_map.end());
return boost::copy_range<HighlightLangList>(lang_range | boost::adaptors::map_values);
}
} //namespace tawashi

View file

@ -0,0 +1,27 @@
/* Copyright 2017, Michele Santullo
* This file is part of "tawashi".
*
* "tawashi" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* "tawashi" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with "tawashi". If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vector>
#include <string>
namespace tawashi {
typedef std::vector<std::string> HighlightLangList;
HighlightLangList list_highlight_langs();
} //namespace tawashi

View file

@ -21,6 +21,7 @@
#include "tawashiConfig.h"
#include "duckhandy/stringize.h"
#include "pathname/pathname.hpp"
#include "list_highlight_langs.hpp"
#include <utility>
#include <cassert>
#include <fstream>
@ -87,6 +88,15 @@ namespace tawashi {
buffer << if_mstch.rdbuf();
return boost::make_optional(buffer.str());
}
mstch::array make_mstch_langmap() {
mstch::array retval;
for (auto&& lang : list_highlight_langs()) {
retval.push_back(mstch::map{{"language_name", std::move(lang)}});
}
return retval;
}
} //unnamed namespace
Response::Response (Types parRespType, std::string&& parValue, std::string&& parPageBaseName, const IniFile& parIni, bool parWantRedis) :
@ -119,7 +129,8 @@ namespace tawashi {
void Response::send() {
mstch::map mustache_context {
{"version", std::string{STRINGIZE(VERSION_MAJOR) "." STRINGIZE(VERSION_MINOR) "." STRINGIZE(VERSION_PATCH)}},
{"base_uri", std::string(m_base_uri.data(), m_base_uri.size())}
{"base_uri", std::string(m_base_uri.data(), m_base_uri.size())},
{"languages", make_mstch_langmap()}
};
if (m_redis)