|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r59885 - website/public_html/beta/common/code
From: daniel_james_at_[hidden]
Date: 2010-02-25 03:41:23
Author: danieljames
Date: 2010-02-25 03:41:22 EST (Thu, 25 Feb 2010)
New Revision: 59885
URL: http://svn.boost.org/trac/boost/changeset/59885
Log:
Bundle the 'init' and 'content' methods into classes.
I'm not sure exactly where I'm going here, but I'm trying to create
something more composable, which is why I used the name 'filter'.
Text files modified:
website/public_html/beta/common/code/boost_archive.php | 136 +++++++++++++++++++++++++---------------
1 files changed, 85 insertions(+), 51 deletions(-)
Modified: website/public_html/beta/common/code/boost_archive.php
==============================================================================
--- website/public_html/beta/common/code/boost_archive.php (original)
+++ website/public_html/beta/common/code/boost_archive.php 2010-02-25 03:41:22 EST (Thu, 25 Feb 2010)
@@ -13,6 +13,7 @@
var $file_ = NULL;
var $archive_ = NULL;
var $extractor_ = NULL;
+ var $extractor_instance_ = NULL;
var $type_ = NULL;
var $preprocess_ = NULL;
var $title_ = NULL;
@@ -75,12 +76,14 @@
if (! $this->extractor_)
{
# File doesn't exist, or we don't know how to handle it.
- $this->extractor_ = '404';
- $this->_init_404();
+ $this->extractor_ = 'h404';
+ $this->extractor_instance_ = new h404_filter;
+ $this->extractor_instance_->init($this);
}
else if ($get_as_raw || $this->extractor_ == 'raw')
{
$this->_extract_raw($unzip);
+ $this->extractor_instance_ = new raw_filter;
//~ print "--- $unzip";
}
else
@@ -88,15 +91,15 @@
/* We pre-extract so we can get this like meta tag information
before we have to print it out. */
$this->content_ = $this->_extract_string($unzip);
- $f = '_init_'.$this->extractor_;
- $this->$f();
+ $extractor_name = $this->extractor_.'_filter';
+ $this->extractor_instance_ = new $extractor_name;
+ $this->extractor_instance_->init($this);
if($this->preprocess_) {
$this->content_ = call_user_func($this->preprocess_, $this->content_);
}
if ($this->extractor_ == 'simple')
{
- $f = '_content_'.$this->extractor_;
- $this->$f();
+ $this->extractor_instance_->content($this);
}
}
}
@@ -158,38 +161,48 @@
function content()
{
- if ($this->extractor_)
+ if ($this->extractor_instance_)
{
- $f = '_content_'.$this->extractor_;
- $this->$f();
+ $this->extractor_instance_->content($this);
}
}
+}
+
+class raw_filter
+{
+ // No methods, since they shouldn't be called at the moment.
+}
- function _init_text()
+class text_filter
+{
+ function init($archive)
{
- $this->title_ = htmlentities($this->key_);
+ $archive->title_ = htmlentities($archive->key_);
}
- function _content_text()
+ function content($archive)
{
- print "<h3>".htmlentities($this->key_)."</h3>\n";
+ print "<h3>".htmlentities($archive->key_)."</h3>\n";
print "<pre>\n";
- print htmlentities($this->content_);
+ print htmlentities($archive->content_);
print "</pre>\n";
}
+}
- function _init_cpp()
+class cpp_filter
+{
+ function init($archive)
{
- $this->title_ = htmlentities($this->key_);
+ $archive->title_ = htmlentities($archive->key_);
}
- function _content_cpp()
+ function content($archive)
{
- $text = htmlentities($this->content_);
+ $text = htmlentities($archive->content_);
- print "<h3>".htmlentities($this->key_)."</h3>\n";
+ print "<h3>".htmlentities($archive->key_)."</h3>\n";
print "<pre>\n";
- $root = dirname(preg_replace('@([^/]+/)@','../',$this->key_));
+ $root = dirname(preg_replace('@([^/]+/)@','../',$archive->key_));
$text = preg_replace(
'@(#[ ]*include[ ]+<)(boost[^&]+)@Ssm',
'${1}${2}',
@@ -201,25 +214,28 @@
print $text;
print "</pre>\n";
}
+}
- function _init_html_pre()
+class html_base
+{
+ function init($archive)
{
- preg_match('@text/html; charset=([^\s"\']+)@i',$this->content_,$charset);
+ preg_match('@text/html; charset=([^\s"\']+)@i',$archive->content_,$charset);
if (isset($charset[1]))
{
- $this->charset_ = $charset[1];
+ $archive->charset_ = $charset[1];
}
- preg_match('@<title>([^<]+)</title>@i',$this->content_,$title);
+ preg_match('@<title>([^<]+)</title>@i',$archive->content_,$title);
if (isset($title[1]))
{
- $this->title_ = $title[1];
+ $archive->title_ = $title[1];
}
}
- function _content_html_pre()
+ function content($archive)
{
- $text = $this->content_;
+ $text = $archive->content_;
$text = preg_replace(
'@href="?http://www.boost.org/?([^"\s]*)"?@i',
@@ -244,15 +260,18 @@
return $text;
}
+}
- function _init_boost_book_html()
+class boost_book_filter extends html_base
+{
+ function init($archive)
{
- $this->_init_html_pre();
+ parent::init($archive);
}
- function _content_boost_book_html()
+ function content($archive)
{
- $text = $this->_content_html_pre();
+ $text = parent::content($archive);
$text = substr($text,strpos($text,'<div class="spirit-nav">'));
$text = substr($text,0,strpos($text,'</body>'));
@@ -274,15 +293,18 @@
print $text;
}
+}
- function _init_boost_libs_html()
+class boost_libs_filter extends html_base
+{
+ function init($archive)
{
- $this->_init_html_pre();
+ parent::init($archive);
}
- function _content_boost_libs_html()
+ function content($archive)
{
- $text = $this->_content_html_pre();
+ $text = parent::content($archive);
preg_match('@<body[^>]*>@i',$text,$body_begin,PREG_OFFSET_CAPTURE);
preg_match('@</body>@i',$text,$body_end,PREG_OFFSET_CAPTURE);
@@ -451,15 +473,18 @@
print $text;
}
+}
- function _init_boost_frame1_html()
+class boost_frame1_filter extends html_base
+{
+ function init($archive)
{
- $this->_init_html_pre();
+ parent::init($archive);
}
- function _content_boost_frame1_html()
+ function content($archive)
{
- $text = $this->_content_html_pre();
+ $text = parent::content($archive);
$text = substr($text,strpos($text,'<div class="spirit-nav">'));
$text = substr($text,0,strpos($text,'</body>'));
@@ -478,23 +503,29 @@
print $text;
}
-
- function _init_simple()
+}
+
+class simple_filter extends html_base
+{
+ function init($archive)
{
}
- function _content_simple()
+ function content($archive)
{
- print $this->_content_html_pre();
+ print parent::content($archive);
}
+}
- function _init_basic()
+class basic_filter extends html_base
+{
+ function init($archive)
{
}
- function _content_basic()
+ function content($archive)
{
- $text = $this->_content_html_pre();
+ $text = parent::content($archive);
$is_xhtml = preg_match('@<!DOCTYPE[^>]*xhtml_at_i', $text);
$tag_end = $is_xhtml ? '/>' : '>';
@@ -529,21 +560,24 @@
}
}
}
+}
- function _init_404()
+class h404_filter
+{
+ function init($archive)
{
header("HTTP/1.0 404 Not Found");
}
- function _content_404()
+ function content($archive)
{
# This might also be an error extracting the file, or because we don't
# know how to deal with the file. It would be good to give a better
# error in those cases.
- print '<h1>404 Not Found</h1><p>File "' . $this->file_ . '"not found.</p>';
- if($this->content_) {
- print '<p>Unzip error: '.htmlentities($this->content_).'</p>';
+ print '<h1>404 Not Found</h1><p>File "' . $archive->file_ . '"not found.</p>';
+ if($archive->content_) {
+ print '<p>Unzip error: '.htmlentities($archive->content_).'</p>';
}
}
}
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