some work on dependency injection
git-svn-id: svn://ttmath.org/publicrep/winix/branches/0.7.x@1147 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
@@ -56,7 +56,8 @@ IndexPatterns index_patterns; // patterns for main index templates (those fr
|
||||
ChangePatterns change_patterns; // patterns for change_template mount option (storage is in 'patterns' too)
|
||||
PatternCacher pattern_cacher; // patterns for user items (files with an executable bit set)
|
||||
|
||||
Locale locale;
|
||||
Locale locale; // IMPROVE ME will be moved to a better place
|
||||
|
||||
EzcFun ezc_functions;
|
||||
Ezc::Blocks ezc_blocks;
|
||||
Ezc::Objects<HtmlTextStream> ezc_objects;
|
||||
@@ -73,12 +74,16 @@ const HtmlTextStream empty_stream;
|
||||
// en empty stack item for templates functions
|
||||
Ezc::Stack empty_stack;
|
||||
|
||||
Db * db;
|
||||
Cur * cur;
|
||||
Config * config;
|
||||
System * system;
|
||||
Functions * functions;
|
||||
SessionManager * session_manager;
|
||||
Db * db = nullptr;
|
||||
Cur * cur = nullptr;
|
||||
Config * config = nullptr;
|
||||
System * system = nullptr;
|
||||
Functions * functions = nullptr;
|
||||
SessionManager * session_manager = nullptr;
|
||||
|
||||
|
||||
Log log; // temporarily for ezc functions
|
||||
Plugin * plugin = nullptr; // temporarily for ezc functions
|
||||
|
||||
|
||||
// generator used by content() function
|
||||
@@ -778,7 +783,7 @@ void Templates::CreateFunctions()
|
||||
ezc_functions.Insert("content", content);
|
||||
|
||||
|
||||
plugin.Call((Session*)0, WINIX_TEMPLATES_CREATEFUNCTIONS, &ezc_functions, &ezc_objects);
|
||||
plugin->Call((Session*)0, WINIX_TEMPLATES_CREATEFUNCTIONS, &ezc_functions, &ezc_objects);
|
||||
|
||||
|
||||
Ezc::Objects<HtmlTextStream>::Iterator i = ezc_objects.Begin();
|
||||
@@ -806,14 +811,12 @@ void Templates::CreateFunctions()
|
||||
|
||||
void Templates::ReadLocale()
|
||||
{
|
||||
using namespace TemplatesFunctions;
|
||||
TemplatesFunctions::locale.SetLocaleFiles(config->locale_files);
|
||||
TemplatesFunctions::locale.SetLocaleMaxId(config->locale_max_id);
|
||||
TemplatesFunctions::locale.SetDefLang(config->locale_default_id);
|
||||
TemplatesFunctions::locale.Read(config->locale_dir, config->locale_dir_default);
|
||||
|
||||
locale.SetLocaleFiles(config->locale_files);
|
||||
locale.SetLocaleMaxId(config->locale_max_id);
|
||||
locale.SetDefLang(config->locale_default_id);
|
||||
locale.Read(config->locale_dir, config->locale_dir_default);
|
||||
|
||||
log << log3 << "Templates: there are " << locale.Size() << " locales" << logend;
|
||||
log << log3 << "Templates: there are " << TemplatesFunctions::locale.Size() << " locales" << logend;
|
||||
}
|
||||
|
||||
|
||||
@@ -891,15 +894,15 @@ using namespace TemplatesFunctions;
|
||||
|
||||
if( config->html_filter_orphans )
|
||||
{
|
||||
html_filter.OrphansMode(config->html_filter_orphans_mode);
|
||||
html_filter.OrphansMode(config->html_filter_orphans_mode_str);
|
||||
|
||||
for(size_t i=0 ; i<locale.Size() ; ++i)
|
||||
for(size_t i=0 ; i<TemplatesFunctions::locale.Size() ; ++i)
|
||||
{
|
||||
if( locale.IsKeyByIndex(L"html_lang_attr_value", i, false) &&
|
||||
locale.IsListByIndex(L"language_orphans", i, false) )
|
||||
if( TemplatesFunctions::locale.IsKeyByIndex(L"html_lang_attr_value", i, false) &&
|
||||
TemplatesFunctions::locale.IsListByIndex(L"language_orphans", i, false) )
|
||||
{
|
||||
html_filter.AssignOrphans(locale.GetByIndex(L"html_lang_attr_value", i, false),
|
||||
locale.GetListByIndex(L"language_orphans", i, false));
|
||||
html_filter.AssignOrphans(TemplatesFunctions::locale.GetByIndex(L"html_lang_attr_value", i, false),
|
||||
TemplatesFunctions::locale.GetListByIndex(L"language_orphans", i, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -969,7 +972,7 @@ using namespace TemplatesFunctions;
|
||||
ReadIndexTemplates();
|
||||
ReadChangeTemplates();
|
||||
|
||||
plugin.Call((Session*)0, WINIX_ADD_TEMPLATE);
|
||||
plugin->Call((Session*)0, WINIX_ADD_TEMPLATE);
|
||||
|
||||
patterns.RebuildCache();
|
||||
ezc_blocks.CacheObjects(ezc_objects);
|
||||
@@ -980,7 +983,7 @@ using namespace TemplatesFunctions;
|
||||
SetHtmlFilter();
|
||||
|
||||
log << log3 << "Templates: there are " << patterns.Size() << " patterns"
|
||||
<< " (" << (locale.Size() * patterns.Size()) << " for all locales)" << logend;
|
||||
<< " (" << (TemplatesFunctions::locale.Size() * patterns.Size()) << " for all locales)" << logend;
|
||||
}
|
||||
|
||||
|
||||
@@ -1025,16 +1028,16 @@ using namespace TemplatesFunctions;
|
||||
|
||||
if( template_name == config->templates_index )
|
||||
{
|
||||
index = patterns.Get(pat_index, locale.GetCurLang());
|
||||
index = patterns.Get(pat_index, TemplatesFunctions::locale.GetCurLang());
|
||||
}
|
||||
else
|
||||
if( template_name == config->templates_index_raw )
|
||||
{
|
||||
index = patterns.Get(pat_index_raw, locale.GetCurLang());
|
||||
index = patterns.Get(pat_index_raw, TemplatesFunctions::locale.GetCurLang());
|
||||
}
|
||||
else
|
||||
{
|
||||
index = index_patterns.Get(template_name, locale.GetCurLang());
|
||||
index = index_patterns.Get(template_name, TemplatesFunctions::locale.GetCurLang());
|
||||
}
|
||||
|
||||
if( index )
|
||||
@@ -1070,7 +1073,7 @@ using namespace TemplatesFunctions;
|
||||
|
||||
if( !index )
|
||||
{
|
||||
index = change_patterns.Get(cur->mount->dir_id, config->templates_index, locale.GetCurLang());
|
||||
index = change_patterns.Get(cur->mount->dir_id, config->templates_index, TemplatesFunctions::locale.GetCurLang());
|
||||
|
||||
if( index )
|
||||
log << log3 << "Templates: index template taken from change_patterns" << logend;
|
||||
@@ -1078,7 +1081,7 @@ using namespace TemplatesFunctions;
|
||||
|
||||
if( !index )
|
||||
{
|
||||
index = patterns.Get(pat_index, locale.GetCurLang());
|
||||
index = patterns.Get(pat_index, TemplatesFunctions::locale.GetCurLang());
|
||||
|
||||
if( index )
|
||||
log << log3 << "Templates: index template taken from: " << config->templates_index << logend;
|
||||
@@ -1170,6 +1173,24 @@ void Templates::SetSessionManager(SessionManager * psession_manager)
|
||||
}
|
||||
|
||||
|
||||
void Templates::set_dependency(WinixRequest * winix_request)
|
||||
{
|
||||
WinixRequest::set_dependency(winix_request);
|
||||
TemplatesFunctions::locale.set_dependency(winix_request);
|
||||
TemplatesFunctions::change_patterns.set_dependency(winix_request);
|
||||
TemplatesFunctions::patterns.set_dependency(winix_request);
|
||||
TemplatesFunctions::index_patterns.set_dependency(winix_request);
|
||||
TemplatesFunctions::pattern_cacher.set_dependency(winix_request);
|
||||
TemplatesFunctions::locale_filter.set_dependency(winix_request);
|
||||
TemplatesFunctions::html_filter.set_dependency(winix_request);
|
||||
|
||||
log.SetDependency(&this->log);
|
||||
log.Init(config->log_level, config->log_save_each_line, config->log_request);
|
||||
|
||||
plugin = winix_request->get_plugin();
|
||||
}
|
||||
|
||||
|
||||
Templates::Templates()
|
||||
{
|
||||
using namespace TemplatesFunctions;
|
||||
@@ -1178,7 +1199,7 @@ Templates::Templates()
|
||||
patterns.SetEzcFunctions(&ezc_functions);
|
||||
patterns.SetEzcBlocks(&ezc_blocks);
|
||||
|
||||
patterns.SetLocale(&locale);
|
||||
patterns.SetLocale(&TemplatesFunctions::locale);
|
||||
patterns.SetLocaleFilter(&locale_filter);
|
||||
|
||||
index_patterns.SetPatterns(&patterns);
|
||||
|
||||
Reference in New Issue
Block a user