1
0
Fork 0
mirror of https://github.com/KingDuckZ/kamokan.git synced 2025-02-13 09:33:56 +00:00

Use partials in html.

This commit is contained in:
King_DuckZ 2017-04-21 19:01:13 +01:00
parent 279bd19f00
commit 73c3d2f04d
6 changed files with 65 additions and 76 deletions

13
html/head.mustache Normal file
View file

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Tawashi</title>
<meta charset="UTF-8"/>
<meta name="description" content="Tawashi, text storage site." />
<meta name="keywords" content="text storage, pastebin, source code snippets, code review" />
<meta name="author" content="Unknown" />
<link rel="stylesheet" href="tawashi.css" />
<link rel="icon" href="icon" />
</head>

View file

@ -1,29 +1,8 @@
<!DOCTYPE html> {{> head}}
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Tawashi</title>
<meta charset="UTF-8"/>
<meta name="description" content="Tawashi, text storage site." />
<meta name="keywords" content="text storage, pastebin, source code snippets, code review" />
<meta name="author" content="Unknown" />
<link rel="stylesheet" href="tawashi.css" />
<link rel="icon" href="icon" />
</head>
<body> <body>
<form action="{{base_uri}}/paste.cgi" method="post" accept-charset="UTF-8"> <form action="{{base_uri}}/paste.cgi" method="post" accept-charset="UTF-8">
<div id="topbar"> {{> topbar}}
<p id="version">tawashi {{version}}</p>
<a href="index.html"><img src="Pictures/tawashi-icon-new.png" alt="tawashi icon" class="icon"></a>
<a href="save.html"><input type="image" src="Pictures/save-ink-t.png" alt="Submit" class="icon-green" title="Save"/></a>
<a href="index.html"><img src="Pictures/new-ink-t.png" alt="new icon" class="icon-green" title="New"/></a>
<a href="edit.html"><img src="Pictures/edit-ink-t.png" alt="duplicate and edit icon" class="icon-green" title="Duplicate and Edit"/></a>
<a href="text.html"><img src="Pictures/text-ink-t.png" alt="text icon" class="icon-green" title="Text only"/></a>
<img src="Pictures/C++-icon.jpeg" alt="c++ icon" class="icon-right"/>
<a href=""><img src="Pictures/github-icon.jpeg" alt="github icon" class="icon-right" /></a>
</div>
<div id="content"> <div id="content">
<textarea type="text" id="PasteTextBox" name="pastie" placeholder=">Text..." autofocus required autocomplete="off" name="text"></textarea> <textarea type="text" id="PasteTextBox" name="pastie" placeholder=">Text..." autofocus required autocomplete="off" name="text"></textarea>
@ -33,10 +12,9 @@
<p class="title">Syntax Highlighting:</p> <p class="title">Syntax Highlighting:</p>
<select name="Language" class="selectBox"> <select name="Language" class="selectBox">
<option value="None" selected="selected">None </option> <option value="None" selected="selected">None </option>
<option value="C++">C++</option> {{#languages}}
<option value="D">D</option> <option value="{{html_language_name}}">{{language_name}}</option>
<option value="HTML">HTML</option> {{/languages}}
<option value="CSS">CSS</option>
</select> </select>
<p class="title">Paste Expiration:</p> <p class="title">Paste Expiration:</p>

View file

@ -1,31 +1,10 @@
<!DOCTYPE html> {{> head}}
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Tawashi</title>
<meta charset="UTF-8"/>
<meta name="description" content="Tawashi, text storage site." />
<meta name="keywords" content="text storage, pastebin, source code snippets, code review" />
<meta name="author" content="Unknown" />
<link rel="stylesheet" href="tawashi.css" />
<link rel="icon" href="icon" />
</head>
<body> <body>
<div id="topbar"> {{> topbar}}
<p id="version">tawashi 1.0.0</p>
<a href="index.html"><img src="Pictures/tawashi-icon-new.png" alt="tawashi icon" class="icon"></a>
<a href="save.html"><input type="image" src="Pictures/save-ink-t.png" alt="Submit" class="icon-green" title="Save"/></a>
<a href="index.html"><img src="Pictures/new-ink-t.png" alt="new icon" class="icon-green" title="New"/></a>
<a href=""><img src="Pictures/edit-ink-t.png" alt="duplicate and edit icon" class="icon-green" title="Duplicate and Edit"/></a>
<a href=""><img src="Pictures/text-ink-t.png" alt="text icon" class="icon-green" title="Text only"/></a>
<img src="Pictures/C++-icon.jpeg" alt="c++ icon" class="icon-right"/>
<a href=""><img src="Pictures/github-icon.jpeg" alt="github icon" class="icon-right" /></a>
</div>
<div id="content"> <div id="content">
<p></p> <p>{{pastie}}</p>
</div> </div>
</body> </body>

View file

@ -1,16 +1,4 @@
<!DOCTYPE html> {{>head}}
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Tawashi</title>
<meta charset="UTF-8"/>
<meta name="description" content="Tawashi, text storage site." />
<meta name="keywords" content="text storage, pastebin, source code snippets, code review" />
<meta name="author" content="Unknown" />
<link rel="stylesheet" href="tawashi.css" />
<link rel="icon" href="icon" />
</head>
<body> <body>
<div id="topbar"> <div id="topbar">

10
html/topbar.mustache Normal file
View file

@ -0,0 +1,10 @@
<div id="topbar">
<p id="version">tawashi {{version}}</p>
<a href="index.html"><img src="Pictures/tawashi-icon-new.png" alt="tawashi icon" class="icon"></a>
<a href="save.html"><input type="image" src="Pictures/save-ink-t.png" alt="Submit" class="icon-green" title="Save"/></a>
<a href="index.html"><img src="Pictures/new-ink-t.png" alt="new icon" class="icon-green" title="New"/></a>
<a href="edit.html"><img src="Pictures/edit-ink-t.png" alt="duplicate and edit icon" class="icon-green" title="Duplicate and Edit"/></a>
<a href="text.html"><img src="Pictures/text-ink-t.png" alt="text icon" class="icon-green" title="Text only"/></a>
<img src="Pictures/C++-icon.jpeg" alt="c++ icon" class="icon-right"/>
<a href=""><img src="Pictures/github-icon.jpeg" alt="github icon" class="icon-right" /></a>
</div>

View file

@ -25,6 +25,8 @@
#include <cassert> #include <cassert>
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
#include <functional>
#include <boost/optional.hpp>
namespace tawashi { namespace tawashi {
namespace { namespace {
@ -67,6 +69,24 @@ namespace tawashi {
throw std::runtime_error("Unknown setting for \"redis_mode\", valid settings are \"inet\" or \"sock\""); throw std::runtime_error("Unknown setting for \"redis_mode\", valid settings are \"inet\" or \"sock\"");
} }
} }
boost::optional<std::string> load_whole_file (const std::string& parWebsiteRoot, const char* parSuffix, const std::string& parName, bool parThrow) {
std::ostringstream oss;
oss << parWebsiteRoot << parName << parSuffix;
std::cerr << "Trying to load \"" << oss.str() << "\"\n";
std::ifstream if_mstch(oss.str(), std::ios::binary | std::ios::in);
if (not if_mstch) {
if (parThrow)
throw std::runtime_error(std::string("File \"") + oss.str() + "\" not found");
else
return boost::optional<std::string>();
}
std::ostringstream buffer;
buffer << if_mstch.rdbuf();
return boost::make_optional(buffer.str());
}
} //unnamed namespace } //unnamed namespace
Response::Response (Types parRespType, std::string&& parValue, std::string&& parPageBaseName, const IniFile& parIni, bool parWantRedis) : Response::Response (Types parRespType, std::string&& parValue, std::string&& parPageBaseName, const IniFile& parIni, bool parWantRedis) :
@ -121,7 +141,17 @@ namespace tawashi {
std::ostringstream stream_out; std::ostringstream stream_out;
if (ContentType == m_resp_type) if (ContentType == m_resp_type)
this->on_send(stream_out); this->on_send(stream_out);
std::cout << mstch::render(stream_out.str(), mustache_context); std::cout << mstch::render(
stream_out.str(),
mustache_context,
std::bind(
&load_whole_file,
std::cref(m_website_root),
".mustache",
std::placeholders::_1,
false
)
);
std::cout.flush(); std::cout.flush();
} }
@ -145,17 +175,8 @@ namespace tawashi {
} }
std::string Response::load_mustache() const { std::string Response::load_mustache() const {
std::ostringstream oss; boost::optional<std::string> content = load_whole_file(m_website_root, ".html.mstch", page_basename(), true);
oss << m_website_root << page_basename() << ".html.mstch"; return *content;
std::cerr << "Trying to load \"" << oss.str() << "\"\n";
std::ifstream if_mstch(oss.str(), std::ios::binary | std::ios::in);
if (!if_mstch)
throw std::runtime_error(std::string("File \"") + oss.str() + "\" not found");
std::ostringstream buffer;
buffer << if_mstch.rdbuf();
return buffer.str();
} }
redis::IncRedis& Response::redis() const { redis::IncRedis& Response::redis() const {