diff options
author | Nicolas "Pixel" Noble <pixel@nobis-crew.org> | 2013-08-02 10:27:19 +0200 |
---|---|---|
committer | Nicolas "Pixel" Noble <pixel@nobis-crew.org> | 2013-08-02 10:27:19 +0200 |
commit | c6dd17a1435db36eeaff24e40a7cc212ee7214a0 (patch) | |
tree | 15502debbc8827e3d917d6a498723abb40a3c73e | |
parent | 9b6dc4d5d83f8acbd82459a0296eb256f632ea02 (diff) |
Using SimpleContext in SimpleMustache's setTemplate, as it reads from a Handle using readU8. We'll switch readU8 to use a Future.
-rw-r--r-- | src/HttpServer.cc | 21 | ||||
-rw-r--r-- | src/SimpleMustache.cc | 1 | ||||
-rw-r--r-- | tests/test-Http.cc | 17 |
3 files changed, 26 insertions, 13 deletions
diff --git a/src/HttpServer.cc b/src/HttpServer.cc index 357bb26..2bc0710 100644 --- a/src/HttpServer.cc +++ b/src/HttpServer.cc @@ -83,16 +83,23 @@ class HttpWorker : public Task { Balau::SimpleMustache Balau::HttpWorker::m_errorTemplate; -class SetDefaultTemplate : public Balau::AtStart { - public: - SetDefaultTemplate() : AtStart(0) { } - virtual void doStart(); +namespace { + +class SetDefaultTemplateTask : public Balau::Task { static const Balau::String m_defaultErrorTemplate; + virtual const char * getName() const { return "SetDefaultTemplateTask"; } + virtual void Do() { Balau::HttpWorker::buildErrorTemplate(m_defaultErrorTemplate); } +}; + +class SetDefaultTemplate : public Balau::AtStartAsTask { + public: + SetDefaultTemplate() : AtStartAsTask(0) { } + virtual Balau::Task * createStartTask() { return new SetDefaultTemplateTask(); } }; static SetDefaultTemplate setDefaultTemplate; -const Balau::String SetDefaultTemplate::m_defaultErrorTemplate( +const Balau::String SetDefaultTemplateTask::m_defaultErrorTemplate( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n" "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" @@ -116,9 +123,7 @@ const Balau::String SetDefaultTemplate::m_defaultErrorTemplate( "</html>\n" ); -void SetDefaultTemplate::doStart() { - Balau::HttpWorker::buildErrorTemplate(m_defaultErrorTemplate); -} +}; Balau::HttpWorker::HttpWorker(IO<Handle> io, void * _server) : m_socket(new WriteOnly(io)), m_strm(new BStream(io)) { m_server = (HttpServer *) _server; diff --git a/src/SimpleMustache.cc b/src/SimpleMustache.cc index d2db99f..6f7acdc 100644 --- a/src/SimpleMustache.cc +++ b/src/SimpleMustache.cc @@ -116,6 +116,7 @@ void Balau::SimpleMustache::Context::empty(bool skipFirst) { static const Balau::Regex changing("^(.*) +(.*)$"); void Balau::SimpleMustache::setTemplate(IO<Handle> _h) { + Task::SimpleContext simpleContext; empty(); IO<BStream> h(new BStream(_h)); h->detach(); diff --git a/tests/test-Http.cc b/tests/test-Http.cc index cd183ce..1ea040b 100644 --- a/tests/test-Http.cc +++ b/tests/test-Http.cc @@ -25,13 +25,20 @@ const char htmlTemplateStr[] = "</html>\n" ; -class TestHtmlTemplate : public AtStart { - public: - TestHtmlTemplate() : AtStart(10), htmlTemplate(m_template) { } - virtual void doStart() { m_template.setTemplate(htmlTemplateStr); } +class TestHtmlTemplateTask : public Task { + virtual void Do() { m_template.setTemplate(htmlTemplateStr); } + virtual const char * getName() const { return "TestHtmlTemplateTask"; } + SimpleMustache & m_template; +public: + TestHtmlTemplateTask(SimpleMustache & htmlTemplate) : m_template(htmlTemplate) { } +}; +class TestHtmlTemplate : public AtStartAsTask { + public: + TestHtmlTemplate() : AtStartAsTask(10), htmlTemplate(m_template) { } + virtual Task * createStartTask() { return new TestHtmlTemplateTask(m_template); } const SimpleMustache & htmlTemplate; - private: + public: SimpleMustache m_template; }; |