Skip to content

Commit

Permalink
simple nginx buildout for benchmarking
Browse files Browse the repository at this point in the history
svn path=/diazo/trunk/; revision=44882
  • Loading branch information
lrowe committed Dec 18, 2009
1 parent b9617f2 commit 92752e1
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 0 deletions.
13 changes: 13 additions & 0 deletions examples/content.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<html>
<head>
<title>A very simple XDV example</title>
</head>
<body>
<div id="content" class="foo">
<div id="byline">To Drop, By <a href="foo">Some Person.</a>
</div>
<p>I have some content <em>in here</em> to merge.</p>
<p>Perhaps an image will be in here later.</p>
</div>
</body>
</html>
24 changes: 24 additions & 0 deletions examples/nginx/nginx.conf.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
worker_processes 2;

events {
# worker_connections 1024;
}

http {
include ${buildout:directory}/etc/mime.types;
gzip on;

server {
listen ${nginx-conf:port};
server_name localhost;
root ${nginx-conf:root};
autoindex on;

location /styled {
alias ${nginx-conf:root};
xslt_stylesheet ${nginx-conf:root}/theme.xsl;
xslt_html_parser on;
xslt_types text/html;
}
}
}
10 changes: 10 additions & 0 deletions examples/rules.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<rules xmlns="http://namespaces.plone.org/xdv"
xmlns:css="http://namespaces.plone.org/xdv+css">
<drop css:content="#byline"/>
<replace theme="/html/head/title" content="/html/head/title"/>
<copy css:theme="#pageheading" content="/html/head/title/text()"/>
<copy theme="/html/body/h1" content="/html/head/title/text()"/>
<copy css:theme="#pagecontent" content="/html/body/div[@id='content']/*"/>
<!-- assume this is an index view -->
<append css:theme="#nav" css:content="pre" if-content="not(/html/body/div[@id='content'])"/>
</rules>
19 changes: 19 additions & 0 deletions examples/theme.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<html>
<head>
<title>Theme Page Title</title>
</head>
<body>
<h1 class="somethemeclass">Theme Page Heading</h1>
<table border="0" height="300" cellpadding="20">
<tr>
<td width="200" bgcolor="gray" valign="top" id="nav">
<h2 align="center">Navigation</h2>
</td>
<td valign="top">
<h1 id="pageheading">Theme Page Heading</h1>
<div id="pagecontent">Theme content to replace.</div>
</td>
</tr>
</table>
</body>
</html>
79 changes: 79 additions & 0 deletions examples/theme.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dv="http://namespaces.plone.org/xdv" xmlns:exsl="http://exslt.org/common" xmlns:xhtml="http://www.w3.org/1999/xhtml" version="1.0" exclude-result-prefixes="exsl dv xhtml">
<xsl:output method="xml" indent="no" omit-xml-declaration="yes" media-type="text/html" encoding="utf-8" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>

<xsl:template match="/">

<!-- Pass incoming content through initial-stage filter. -->
<xsl:variable name="initial-stage-rtf">
<xsl:apply-templates select="/" mode="initial-stage"/>
</xsl:variable>
<xsl:variable name="initial-stage" select="exsl:node-set($initial-stage-rtf)"/>

<!-- Now apply the theme to the initial-stage content -->
<xsl:variable name="themedcontent-rtf">
<xsl:apply-templates select="$initial-stage" mode="apply-theme"/>
</xsl:variable>
<xsl:variable name="content" select="exsl:node-set($themedcontent-rtf)"/>

<!-- We're done, so generate some output by passing
through a final stage. -->
<xsl:apply-templates select="$content" mode="final-stage"/>

</xsl:template>

<!--
Utility templates
-->
<xsl:template match="//*[@id = 'byline']" mode="initial-stage"><!--Do nothing, skip these nodes--></xsl:template>
<xsl:template match="node()|@*" mode="initial-stage">
<xsl:copy>
<xsl:apply-templates select="node()|@*" mode="initial-stage"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/" mode="apply-theme">
<html><head><xsl:choose><xsl:when test="/html/head/title"><xsl:copy-of select="/html/head/title"/></xsl:when><xsl:otherwise><title>Theme Page Title</title></xsl:otherwise></xsl:choose></head><body>
<h1 class="somethemeclass"><xsl:choose><xsl:when test="/html/head/title/text()"><xsl:copy-of select="/html/head/title/text()"/></xsl:when><xsl:otherwise>Theme Page Heading</xsl:otherwise></xsl:choose></h1>
<table border="0" height="300" cellpadding="20"><tr><td width="200" bgcolor="gray" valign="top" id="nav">
<h2 align="center">Navigation</h2>
<xsl:if test="not(/html/body/div[@id='content'])"><xsl:copy-of select="//pre"/></xsl:if></td>
<td valign="top">
<h1 id="pageheading"><xsl:choose><xsl:when test="/html/head/title/text()"><xsl:copy-of select="/html/head/title/text()"/></xsl:when><xsl:otherwise>Theme Page Heading</xsl:otherwise></xsl:choose></h1>
<div id="pagecontent"><xsl:choose><xsl:when test="/html/body/div[@id='content']/*"><xsl:copy-of select="/html/body/div[@id='content']/*"/></xsl:when><xsl:otherwise>Theme content to replace.</xsl:otherwise></xsl:choose></div>
</td>
</tr></table></body></html>
</xsl:template>
<xsl:template match="style|script|xhtml:style|xhtml:script" priority="5" mode="final-stage">
<xsl:element name="{local-name()}" namespace="http://www.w3.org/1999/xhtml">
<xsl:apply-templates select="@*" mode="final-stage"/>
<xsl:value-of select="text()" disable-output-escaping="yes"/>
</xsl:element>
</xsl:template>
<xsl:template match="*" priority="3" mode="final-stage">
<!-- Move elements without a namespace into
the xhtml namespace. -->
<xsl:choose>
<xsl:when test="namespace-uri(.)">
<xsl:copy>
<xsl:apply-templates select="@*|node()" mode="final-stage"/>
</xsl:copy>
</xsl:when>
<xsl:otherwise>
<xsl:element name="{local-name()}" namespace="http://www.w3.org/1999/xhtml">
<xsl:apply-templates select="@*|node()" mode="final-stage"/>
</xsl:element>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="node()|@*" priority="1" mode="final-stage">
<xsl:copy>
<xsl:apply-templates select="node()|@*" mode="final-stage"/>
</xsl:copy>
</xsl:template>

<!--
Extra templates
-->

</xsl:stylesheet>
29 changes: 29 additions & 0 deletions nginx.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[buildout]
extends = lxml.cfg
parts +=
nginx
nginx-conf

[nginx]
recipe = zc.recipe.cmmi
url = http://html-xslt.googlecode.com/files/nginx-0.7.64-html-xslt.tar.gz
md5sum = f7eb0fef7cd0317294431153ce8e1817
extra_options =
--conf-path=${buildout:directory}/etc/nginx.conf
--sbin-path=${buildout:directory}/bin
--error-log-path=${buildout:directory}/var/log/nginx-error.log
--http-log-path=${buildout:directory}/var/log/nginx-access.log
--pid-path=${buildout:directory}/var/nginx.pid
--lock-path=${buildout:directory}/var/nginx.lock
--with-http_stub_status_module
--with-http_xslt_module
--with-libxml2=${buildout:directory}/parts/lxml/libxml2
--with-libxslt=${buildout:directory}/parts/lxml/libxslt
# --with-debug --with-cc-opt="-O0" # helps debugging with gdb

[nginx-conf]
recipe = collective.recipe.template
port = 8000
root = ${buildout:directory}/examples
input = ${buildout:directory}/examples/nginx/nginx.conf.in
output = ${buildout:directory}/etc/nginx.conf

0 comments on commit 92752e1

Please sign in to comment.