Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r61444 - in sandbox/SOC/2007/cgi/trunk: boost/cgi/connections boost/cgi/utility libs/cgi/example/fcgi/stencil
From: lists.drrngrvy_at_[hidden]
Date: 2010-04-20 19:59:56


Author: drrngrvy
Date: 2010-04-20 19:59:55 EDT (Tue, 20 Apr 2010)
New Revision: 61444
URL: http://svn.boost.org/trac/boost/changeset/61444

Log:
Tweaks to the Stencil wrapper to support cTemplate 0.97. Breaks backwards compatibility (ie. will not work with cTemplate 0.96 or earlier).
Text files modified:
   sandbox/SOC/2007/cgi/trunk/boost/cgi/connections/anonymous_pipe.hpp | 1
   sandbox/SOC/2007/cgi/trunk/boost/cgi/utility/stencil.hpp | 65 ++++++++++++++-------------------------
   sandbox/SOC/2007/cgi/trunk/libs/cgi/example/fcgi/stencil/main.cpp | 2
   3 files changed, 24 insertions(+), 44 deletions(-)

Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/connections/anonymous_pipe.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/connections/anonymous_pipe.hpp (original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/connections/anonymous_pipe.hpp 2010-04-20 19:59:55 EDT (Tue, 20 Apr 2010)
@@ -17,7 +17,6 @@
 #include "boost/cgi/import/io_service.hpp"
 #include "boost/cgi/detail/push_options.hpp"
 #include "boost/cgi/common/connection_base.hpp"
-
 #include "boost/cgi/common/protocol_traits.hpp"
 
 //////////////////////////////////////////////////////////////////////////

Modified: sandbox/SOC/2007/cgi/trunk/boost/cgi/utility/stencil.hpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/boost/cgi/utility/stencil.hpp (original)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/utility/stencil.hpp 2010-04-20 19:59:55 EDT (Tue, 20 Apr 2010)
@@ -213,16 +213,18 @@
 public:
   typedef stencil self_type;
   typedef boost::cgi::common::response base_type;
- typedef ctemplate::Template stencil_type;
   typedef ctemplate::TemplateDictionary impl_type;
   typedef stencils::section section;
   typedef stencils::dictionary dictionary;
   
   enum reload_option
   {
+ // Don't reload templates from disk.
     cached,
- reload,
- reload_all
+ // Reload templates from disk as and when required.
+ lazy_reload = ctemplate::TemplateCache::LAZY_RELOAD,
+ // Reload all templates in the cache now.
+ immediate_reload = ctemplate::TemplateCache::IMMEDIATE_RELOAD
   };
   
   enum strip
@@ -232,49 +234,33 @@
     strip_whitespace = ctemplate::STRIP_WHITESPACE
   };
 
- enum parse_state
- {
- unused = ctemplate::TS_UNUSED,
- empty = ctemplate::TS_EMPTY,
- error = ctemplate::TS_ERROR,
- ready = ctemplate::TS_READY,
- should_reload = ctemplate::TS_SHOULD_RELOAD
- };
-
   stencil(impl_type* parent_dict)
- : tmpl(NULL)
- , impl(parent_dict->MakeCopy("response"))
+ : impl(parent_dict->MakeCopy("response"))
     , expanded(false)
     , per_expand_data()
   {
   }
   
   stencil(string_type const& root_dir = "")
- : tmpl(NULL)
- , impl(new impl_type("response"))
+ : impl(new impl_type("response"))
     , expanded(false)
     , per_expand_data()
   {
     if (!root_dir.empty())
- ctemplate::Template::SetTemplateRootDirectory(root_dir);
+ ctemplate::mutable_default_template_cache()
+ ->SetTemplateRootDirectory(root_dir);
   }
   
   /// Clear the response buffer.
   void reset(impl_type* use_dict = NULL)
   {
     impl.reset(use_dict ? use_dict : new impl_type("response"));
- tmpl = NULL;
     base_type::reset();
   }
   
   /// Get the implementation type of the template.
   impl_type& native() { return *impl; }
   
- parse_state state()
- {
- return tmpl ? (parse_state)tmpl->state() : unused;
- }
-
   bool expand(
       string_type const& template_name,
       enum reload_option reload_if_changed = cached,
@@ -286,29 +272,25 @@
     // Clear the response body (but not headers).
     clear(false);
 
- if (reload_if_changed == reload_all)
- ctemplate::Template::ReloadAllIfChanged();
-
- // Get hold of the template to output.
- tmpl = ctemplate::Template::GetTemplate(
- template_name,
- (ctemplate::Strip)strip_option
- );
-
- if (!tmpl || state() == error)
- throw template_error(template_name);
- else
- if (reload_if_changed == reload)
- tmpl->ReloadIfChanged();
-
     // Add the response content back into the template.
     set("content", content);
-
- // Expand the template and write it to the response.
+
+ if (reload_if_changed != cached)
+ ctemplate::mutable_default_template_cache()->ReloadAllIfChanged(
+ (ctemplate::TemplateCache::ReloadType)reload_if_changed);
+
     string_type body;
- bool success = tmpl->ExpandWithData(&body, impl.get(), &per_expand_data);
+ bool success = ctemplate::ExpandWithData(
+ template_name, // The filename
+ (ctemplate::Strip)strip_option,
+ impl.get(), // The dictionary
+ &per_expand_data,
+ &body
+ );
+
     if (!success)
       return false;
+
     write(body);
 
     // All ok.
@@ -385,7 +367,6 @@
     return *this;
   }
 
- stencil_type* tmpl;
   boost::scoped_ptr<impl_type> impl;
   bool expanded;
   ctemplate::PerExpandData per_expand_data;

Modified: sandbox/SOC/2007/cgi/trunk/libs/cgi/example/fcgi/stencil/main.cpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/libs/cgi/example/fcgi/stencil/main.cpp (original)
+++ sandbox/SOC/2007/cgi/trunk/libs/cgi/example/fcgi/stencil/main.cpp 2010-04-20 19:59:55 EDT (Tue, 20 Apr 2010)
@@ -106,7 +106,7 @@
   // Expand the response using the specified template.
   // cTemplate has a cache internally, which we can choose to
   // ignore.
- resp.expand("stencil.html", stencil::reload);
+ resp.expand("stencil.html", stencil::lazy_reload);
 
   // Send the response and close the request.
   return commit(req, resp);


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk