winix/templates/misc.h

87 lines
2.0 KiB
C++
Executable File

/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010-2011, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfile_winix_templates_misc
#define headerfile_winix_templates_misc
#include <vector>
#include <string>
#include "localefilter.h"
#include "ezc.h"
#include "htmltextstream.h"
#include "core/user.h"
namespace TemplatesFunctions
{
typedef Ezc::Functions<HtmlTextStream> EzcFun;
typedef Ezc::Generator<HtmlTextStream> EzcGen;
typedef Ezc::FunInfo<HtmlTextStream> Info;
template<class RawType>
HtmlTextStream::RawText<RawType> R(const RawType & par)
{
return HtmlTextStream::RawText<RawType>(par);
}
//void HtmlEscape(TextStream<std::wstring> & out, const std::wstring & in);
void HtmlEscapeFormTxt(HtmlTextStream & out, const std::wstring & in);
//std::wstring HtmlEscape(const std::wstring & in);
//std::wstring HtmlEscapeFormTxt(const std::wstring & in);
// table: [language][file]
typedef std::vector<std::vector<Ezc::Pattern> > Patterns;
void print_date_nice(Info & i, const tm & rtm);
void print_user_name(Info & i, const User * puser, const std::wstring & guest_name);
// those functions from here are used in the second thread too
template<class StreamType>
void Read(Patterns & patterns, size_t pat, Locale & locale, LocaleFilter & locale_filter,
Ezc::Functions<StreamType> & ezc_fun, const wchar_t * file, bool read_file_as_utf8,
const std::wstring & templates_dir, const std::wstring & templates_dir_default,
bool delete_white = false)
{
size_t i;
size_t len = patterns.size();
for(i=0 ; i<len ; ++i)
{
if( pat < patterns[i].size() )
{
patterns[i][pat].UTF8(read_file_as_utf8);
patterns[i][pat].DeleteWhiteTextItems(delete_white);
patterns[i][pat].Directory(templates_dir, templates_dir_default);
patterns[i][pat].ParseFile(file);
patterns[i][pat].CacheFunctions(ezc_fun);
locale_filter.Filter(patterns[i][pat], locale, i);
}
}
}
} // namespace TemplatesFunctions
#endif