Commits

Shlomi Fish committed df9e632

Start adding the all-in-one-fortunes optimisation.

I get a perl error though when running ./gen-helpers.pl :

Use of my $_ is experimental at lib/Shlomif/Homepage/FortuneCollections.pm line 190.

  • Participants
  • Parent commits 4368d58
  • Branches use-of-my-dollar-underscore-is-experimental

Comments (0)

Files changed (3)

 $(FORTUNES_TARGET): $(T2_FORTUNES_DIR)/index.html.wml $(DOCS_COMMON_DEPS) $(HUMOUR_DEPS) $(T2_FORTUNES_DIR)/Makefile $(T2_FORTUNES_DIR)/ver.txt
 	WML_LATEMP_PATH="$$(perl -MFile::Spec -e 'print File::Spec->rel2abs(shift)' '$@')" ; ( cd $(T2_SRC_DIR) && wml -o "$${WML_LATEMP_PATH}" $(T2_WML_FLAGS) -DLATEMP_FILENAME=$(patsubst $(T2_DEST)/%,%,$(patsubst %.wml,%,$@)) -DPACKAGE_BASE="$$( unset MAKELEVEL ; cd $(FORTUNES_DIR) && make print_package_base )" $(patsubst $(T2_SRC_DIR)/%,%,$<) )
 
-$(T2_FORTUNES_ALL__TEMP__HTML): $(T2_FORTUNES_ALL_WML) $(DOCS_COMMON_DEPS) $(FORTUNES_XHTMLS__FOR_INPUT_PORTIONS)
+$(T2_FORTUNES_ALL__TEMP__HTML): $(T2_FORTUNES_ALL_WML) $(DOCS_COMMON_DEPS) $(FORTUNES_XHTMLS__FOR_INPUT_PORTIONS) $(FORTUNES_XHTMLS_TOCS)
 	WML_LATEMP_PATH="$$(perl -MFile::Spec -e 'print File::Spec->rel2abs(shift)' '$@')" ; WML_LATEMP_SRC_PATH="$$(perl -MFile::Spec -e 'print File::Spec->rel2abs(shift)' '$<')" ; ( cd $(T2_SRC_DIR) && wml -o "$${WML_LATEMP_PATH}" $(T2_WML_FLAGS) -DLATEMP_FILENAME=$(patsubst $(T2_DEST)/%,%,$(patsubst %.wml,%,$@)) -DPACKAGE_BASE="$$( unset MAKELEVEL ; cd $(FORTUNES_DIR) && make print_package_base )" "$${WML_LATEMP_SRC_PATH}" )
 
 T2_DOCS_SRC = $(patsubst $(T2_DEST)/%,$(T2_SRC_DIR)/%.wml,$(T2_DOCS_DEST))
 FORTUNES_XMLS_BASE = $(addsuffix .xml,$(FORTUNES_FILES_BASE))
 FORTUNES_XMLS_SRC = $(patsubst %,$(T2_FORTUNES_DIR)/%,$(FORTUNES_XMLS_BASE))
 FORTUNES_XHTMLS = $(patsubst $(T2_FORTUNES_DIR)/%.xml,$(FORTUNES_XHTMLS_DIR)/%.xhtml,$(FORTUNES_XMLS_SRC))
+FORTUNES_XHTMLS_TOCS = $(patsubst $(T2_FORTUNES_DIR)/%.xml,$(FORTUNES_XHTMLS_DIR)/%.toc-xhtml,$(FORTUNES_XMLS_SRC))
 FORTUNES_SOURCE_WMLS = $(patsubst %.xml,%.html.wml,$(FORTUNES_XMLS_SRC))
 FORTUNES_XHTMLS__COMPRESSED = $(patsubst %.xhtml,%.compressed.xhtml,$(FORTUNES_XHTMLS))
 FORTUNES_XHTMLS__FOR_INPUT_PORTIONS = $(patsubst %.xhtml,%.xhtml-for-input,$(FORTUNES_XHTMLS))
 	bash $(T2_FORTUNES_DIR)/run-validator.bash $< && \
 	perl $(FORTUNES_CONVERT_TO_XHTML_SCRIPT) $< $@
 
+FORTUNES_XML_TO_XHTML_TOC_XSLT = lib/fortunes/fortune-xml-to-xhtml-toc.xslt
+$(FORTUNES_XHTMLS_TOCS): $(FORTUNES_XHTMLS_DIR)/%.toc-xhtml : $(T2_FORTUNES_DIR)/%.xml $(FORTUNES_CONVERT_TO_XHTML_SCRIPT)
+	xsltproc $(FORTUNES_XML_TO_XHTML_TOC_XSLT) $< | \
+	perl -0777 -lapE 's#\A.*?<ul[^>]*?>#<ul>#ms' - > \
+	$@
+
 $(FORTUNES_WMLS_HTMLS): $(T2_DEST_FORTUNES_DIR)/%.html: $(FORTUNES_XHTMLS_DIR)/%.xhtml-for-input
 
 $(T2_FORTUNES_ALL__TEMP__HTML): $(T2_FORTUNES_ALL_WML) $(FORTUNES_XHTMLS__FOR_INPUT_PORTIONS)

lib/Shlomif/Homepage/FortuneCollections.pm

 <latemp_subject "Shlomi Fish Fortunes Collections - All in One Page" />
 <latemp_meta_desc "Shlomi Fish Fortunes Collections - All in One Page" />
 
-<toc_div head_tag="h2" />
-
+<div class="page_toc">
+<h2 id="toc">Table of Contents</h2>
+<ul>
 EOF
 
     foreach my $r (@{$class->get_fortune_records()})
     {
+
+        my $id = $r->id();
+        my $title = $r->title();
+
+        $ret .= <<"FOO_EOF" ;
+<li><a href="#$id">$title</a><br />
+#include "fortunes/xhtmls/$id.toc-xhtml"
+</li>
+FOO_EOF
+
+    }
+
+    $ret .= "</ul>\n";
+    $ret .= "</div>\n";
+
+    foreach my $r (@{$class->get_fortune_records()}
+    {
         $ret .= $class->get_single_fortune_record_all_in_one_page_entry($r);
     }
 

lib/fortunes/fortune-xml-to-xhtml-toc.xslt

+<?xml version="1.0" encoding="utf-8" ?>
+<xsl:stylesheet version = '1.0'
+    xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
+    xmlns="http://www.w3.org/1999/xhtml"
+     >
+
+<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"
+ doctype-public="-//W3C//DTD XHTML 1.1//EN"
+ doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"
+ />
+
+<xsl:param name="fortune.id"></xsl:param>
+
+<!-- The purpose of this function is to recursively copy elements without a
+namespace-->
+<xsl:template mode="copy-html-ns" match="*">
+    <xsl:element xmlns="http://www.w3.org/1999/xhtml" name="{local-name()}">
+        <xsl:copy-of select="@*"/>
+        <xsl:apply-templates mode="copy-html-ns"/>
+    </xsl:element>
+</xsl:template>
+
+<xsl:template name="copy_html_ns_by_name">
+    <xsl:element xmlns="http://www.w3.org/1999/xhtml" name="{local-name()}">
+            <xsl:copy-of select="@*" />
+            <xsl:call-template name="copy_html_ns_by_name" />
+    </xsl:element>
+</xsl:template>
+
+<xsl:template match="/collection">
+    <ul xml:lang="en-US">
+        <xsl:apply-templates select="list/fortune" />
+    </ul>
+</xsl:template>
+
+<xsl:template match="fortune">
+    <li><a href="#{@id}"><xsl:call-template name="get_header" /></a></li>
+</xsl:template>
+
+<xsl:template name="get_irc_default_header">
+    <xsl:choose>
+        <xsl:when test="info">
+            <xsl:if test="info/tagline">
+                <xsl:value-of select="info/tagline" /> on
+            </xsl:if>
+            <xsl:if test="info/network">
+                <xsl:value-of select="info/network" />'s
+            </xsl:if>
+            <xsl:value-of select="info/channel" />
+        </xsl:when>
+        <xsl:otherwise>
+            <xsl:text>Unknown Subject</xsl:text>
+        </xsl:otherwise>
+    </xsl:choose>
+</xsl:template>
+
+<xsl:template name="get_header">
+    <xsl:choose>
+        <xsl:when test="meta/title">
+            <xsl:value-of select="meta/title" />
+        </xsl:when>
+        <xsl:otherwise>
+            <xsl:call-template name="get_irc_default_header" />
+        </xsl:otherwise>
+    </xsl:choose>
+</xsl:template>
+
+</xsl:stylesheet>