[library-web] Minimalistic support for Mallard documents
- From: Frederic Peters <fpeters src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [library-web] Minimalistic support for Mallard documents
- Date: Fri, 7 Aug 2009 12:19:25 +0000 (UTC)
commit 099b0c88e0b00ef227f6edf0066c8510e4144b62
Author: Frédéric Péters <fpeters 0d be>
Date: Fri Aug 7 11:02:55 2009 +0200
Minimalistic support for Mallard documents
data/xslt/mal2html.xsl | 143 ++++++++++++++++++++++++++++++++++++++++
src/lgo.py | 6 ++-
src/modtypes/base.py | 5 +-
src/modtypes/mallard.py | 167 +++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 319 insertions(+), 2 deletions(-)
---
diff --git a/data/xslt/mal2html.xsl b/data/xslt/mal2html.xsl
new file mode 100644
index 0000000..4e3da94
--- /dev/null
+++ b/data/xslt/mal2html.xsl
@@ -0,0 +1,143 @@
+<?xml version='1.0' encoding='UTF-8'?><!-- -*- indent-tabs-mode: nil -*- -->
+<!--
+Copyright (c) 2009 Frederic Peters <fpeters gnome org>
+
+This file is part of libgo.
+
+libgo is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+libgo is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with libgo; if not, write to the Free Software Foundation, Inc.,
+59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+-->
+
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:exsl="http://exslt.org/common"
+ xmlns:set="http://exslt.org/sets"
+ xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:str="http://exslt.org/strings"
+ xmlns:mal="http://projectmallard.org/1.0/"
+ extension-element-prefixes="exsl"
+ xsl:exclude-result-prefixes="set str"
+ version="1.0">
+
+<!-- FIXME: Shaun's styles are under LGPL, is it OK to use GPL for this? -->
+<xsl:import href="/usr/share/xml/gnome/xslt/mallard/html/mal2html.xsl"/>
+<xsl:import href="heading.xsl"/>
+<xsl:import href="gettext.xsl"/>
+
+<!-- Setting parameters for included stylesheets -->
+<xsl:param name="mal.chunk.extension" select="concat('.html.',$libgo.lang)"/>
+
+<!-- output -->
+<xsl:output method="html" encoding="UTF-8" indent="yes"
+ omit-xml-declaration="yes"
+ doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"
+ doctype-system="http://www.w3.org/TR/html4/loose.dtd"/>
+
+<!-- This gets set on the command line ... -->
+<xsl:param name="libgo.lang" select="''"/>
+<xsl:param name="libgo.tarball" select="false()"/>
+<xsl:param name="libgo.languages_in_sidebar" select="false()"/>
+<xsl:param name="libgo.nightly" select="false()"/>
+
+<!-- Setting parameters for included stylesheets -->
+<xsl:param name="theme.icon.admon.path" select="'/skin/'"/>
+<xsl:param name="theme.icon.nav.previous" select="'/skin/nav-previous.png'"/>
+<xsl:param name="theme.icon.nav.next" select="'/skin/nav-next.png'"/>
+
+<!-- Process -->
+
+<!-- = mal:page % mal.chunk.content.mode = -->
+<xsl:template mode="mal.chunk.content.mode" match="mal:page">
+ <!-- FIXME: find a way to just select the version element -->
+ <xsl:variable name="date">
+ <xsl:for-each select="mal:info/mal:revision">
+ <xsl:sort select="@date" data-type="text" order="descending"/>
+ <xsl:if test="position() = 1">
+ <xsl:value-of select="@date"/>
+ </xsl:if>
+ </xsl:for-each>
+ </xsl:variable>
+ <xsl:variable name="revision"
+ select="mal:info/mal:revision[ date = $date][last()]"/>
+ <html>
+ <head>
+ <title>
+ <xsl:value-of select="mal:title"/>
+ </title>
+ <xsl:call-template name="mal2html.css"/>
+ <xsl:call-template name="libgo.head"/>
+ </head>
+ <body>
+ <xsl:call-template name="libgo.header">
+ <xsl:with-param name="lang"><xsl:value-of select="$libgo.lang"/></xsl:with-param>
+ </xsl:call-template>
+ <div class="head">
+ <xsl:call-template name="mal2html.page.linktrails">
+ <xsl:with-param name="node" select="."/>
+ </xsl:call-template>
+ </div>
+ <div class="body">
+ <xsl:if test="$mal2html.editor_mode and $revision/@status != ''">
+ <div class="version">
+ <!-- FIXME: i18n -->
+ <div class="title">
+ <xsl:choose>
+ <xsl:when test="$revision/@status = 'stub'">
+ <xsl:call-template name="l10n.gettext">
+ <xsl:with-param name="msgid" select="'Stub'"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:when test="$revision/@status = 'incomplete'">
+ <xsl:call-template name="l10n.gettext">
+ <xsl:with-param name="msgid" select="'Incomplete'"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:when test="$revision/@status = 'draft'">
+ <xsl:call-template name="l10n.gettext">
+ <xsl:with-param name="msgid" select="'Draft'"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:when test="$revision/@status = 'review'">
+ <xsl:call-template name="l10n.gettext">
+ <xsl:with-param name="msgid" select="'Ready for review'"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:when test="$revision/@status = 'final'">
+ <xsl:call-template name="l10n.gettext">
+ <xsl:with-param name="msgid" select="'Final'"/>
+ </xsl:call-template>
+ </xsl:when>
+ </xsl:choose>
+ </div>
+ <p class="version">
+ <!-- FIXME: i18n -->
+ <xsl:text>Version </xsl:text>
+ <xsl:value-of select="$revision/@version"/>
+ <xsl:text> on </xsl:text>
+ <xsl:value-of select="$revision/@date"/>
+ </p>
+ <xsl:apply-templates mode="mal2html.block.mode" select="$revision/*"/>
+ </div>
+ </xsl:if>
+ <xsl:apply-templates select="."/>
+ </div>
+ <xsl:call-template name="db2html.page.copyrights">
+ <xsl:with-param name="node" select="."/>
+ </xsl:call-template>
+ </body>
+ </html>
+</xsl:template>
+
+
+
+</xsl:stylesheet>
diff --git a/src/lgo.py b/src/lgo.py
index 23eff85..c0335b2 100755
--- a/src/lgo.py
+++ b/src/lgo.py
@@ -55,6 +55,7 @@ from overlay import Overlay
from modtypes.gnomedocbook import GnomeDocbookModule
from modtypes.gtkdoc import GtkDocModule
from modtypes.htmlfiles import HtmlFilesModule
+from modtypes.mallard import MallardModule
from app import App
@@ -411,7 +412,10 @@ class Lgo(App):
fd = tar.extractfile(tarinfo)
makefile_am = fd.read()
makefile_am = makefile_am.replace('\\\n', ' ')
- if 'DOC_MODULE' in makefile_am and regex_gdu.findall(makefile_am):
+ if 'DOC_ID' in makefile_am and regex_gdu.findall(makefile_am):
+ logging.debug('found usage of mallard in %s' % tarinfo.name)
+ doc = MallardModule(tar, tarinfo, makefile_am, nightly)
+ elif 'DOC_MODULE' in makefile_am and regex_gdu.findall(makefile_am):
logging.debug('found usage of gnome-doc-utils in %s' % tarinfo.name)
doc = GnomeDocbookModule(tar, tarinfo, makefile_am, nightly)
elif 'include $(top_srcdir)/gtk-doc.make' in makefile_am or \
diff --git a/src/modtypes/base.py b/src/modtypes/base.py
index c43f29b..f839e17 100644
--- a/src/modtypes/base.py
+++ b/src/modtypes/base.py
@@ -44,7 +44,10 @@ class DocModule:
self.dirname = os.path.dirname(tarinfo.name)
if makefile_am:
self.makefile_am = makefile_am
- self.modulename = re.findall(r'DOC_MODULE\s?=\s?(.*)', makefile_am)[0].strip()
+ try:
+ self.modulename = re.findall(r'DOC_ID\s?=\s?(.*)', makefile_am)[0].strip()
+ except IndexError:
+ self.modulename = re.findall(r'DOC_MODULE\s?=\s?(.*)', makefile_am)[0].strip()
if '@' in self.modulename:
logging.warning('variadic module name: %s' % self.modulename)
# don't go interpreting autotools variables, as in this path
diff --git a/src/modtypes/mallard.py b/src/modtypes/mallard.py
new file mode 100644
index 0000000..2ed0f38
--- /dev/null
+++ b/src/modtypes/mallard.py
@@ -0,0 +1,167 @@
+# libgo - script to build library.gnome.org
+# Copyright (C) 2007-2009 Frederic Peters
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301 USA
+
+import glob
+import logging
+import os
+import re
+import shutil
+import stat
+import subprocess
+import tarfile
+import tempfile
+
+try:
+ import elementtree.ElementTree as ET
+except ImportError:
+ import xml.etree.ElementTree as ET
+
+try:
+ import html5lib
+except ImportError:
+ html5lib = None
+
+import errors
+from base import DocModule
+
+class MallardModule(DocModule):
+ '''Class for documentation shipped in a tarball and using gnome-doc-utils'''
+ mal2html_xsl_file = os.path.join(data_dir, 'xslt', 'mal2html.xsl')
+ category = None
+
+ related_xsl_files = ['mal2html.xsl', 'heading.xsl']
+
+ def __init__(self, tar, tarinfo, makefile_am, nightly):
+ DocModule.__init__(self, tar, tarinfo, makefile_am, nightly)
+
+ def setup_channel(self):
+ # get category from omf file
+ ext_dirname = os.path.join(app.config.private_dir, 'extracts')
+ omf_file = glob.glob(os.path.join(ext_dirname, self.dirname) + '/*.omf.in')
+ if not omf_file:
+ omf_file = glob.glob(os.path.join(ext_dirname, self.dirname) + '/C/*.omf.in')
+ if omf_file:
+ try:
+ self.category = ET.parse(omf_file[0]).find('resource/subject').attrib['category']
+ except (IndexError, KeyError):
+ pass
+
+ channel = 'users'
+ if self.category and (self.category.startswith('GNOME|Development') or
+ self.category.startswith('GNOME|Applications|Programming')):
+ channel = 'devel'
+
+ self.channel = app.overlay.get_channel_overlay(self.modulename, channel)
+ if self.channel == 'misc' and not self.category:
+ self.category = 'GNOME|Other'
+
+ def __str__(self):
+ return 'mallard module at %s' % self.dirname
+
+ def process(self):
+ doc_module = self.modulename
+ ext_dirname = os.path.join(app.config.private_dir, 'extracts')
+
+ try:
+ doc_linguas = re.findall(r'DOC_LINGUAS\s+=[\t ](.*)',
+ self.makefile_am)[0].split()
+ if not 'en' in doc_linguas:
+ doc_linguas.append('en')
+ except IndexError:
+ doc_linguas = ['en']
+
+ try:
+ doc_pages = re.findall('DOC_PAGES\s+=\s+(.*)', self.makefile_am)[0].split()
+ except IndexError:
+ return
+
+ try:
+ doc_figures = re.findall('DOC_FIGURES\s+=\s+(.*)',
+ self.makefile_am)[0].split()
+ figures_dirname = os.path.join(ext_dirname, self.dirname, 'C')
+ for doc_figure in doc_figures:
+ if not os.path.exists(os.path.join(figures_dirname, doc_figure)):
+ logging.warning('figure (%s) listed but not present, going to autodiscover' % \
+ doc_figure)
+ raise IndexError()
+ except IndexError:
+ figures_dirname = os.path.join(ext_dirname, self.dirname, 'C', 'figures')
+ images_dirname = os.path.join(ext_dirname, self.dirname, 'C', 'images')
+ doc_figures = []
+ if os.path.exists(figures_dirname):
+ doc_figures += [os.path.join('figures', x) for x in \
+ os.listdir(figures_dirname) \
+ if os.path.splitext(x)[1] in ('.png', '.jpg', '.jpeg')]
+ if os.path.exists(images_dirname):
+ doc_figures += [os.path.join('images', x) for x in \
+ os.listdir(images_dirname) \
+ if os.path.splitext(x)[1] in ('.png', '.jpg', '.jpeg')]
+
+ doc_linguas.sort()
+ if app.config.languages:
+ for lang in doc_linguas[:]:
+ if lang not in app.config.languages + ['C']:
+ doc_linguas.remove(lang)
+
+ doc = self.get_libgo_document(doc_linguas)
+ if not doc:
+ return
+
+ if self.category:
+ doc.category = self.category
+ doc.toc_id = app.toc_mapping.get(doc.category)
+
+ web_output_dir = os.path.join(app.config.output_dir, self.channel,
+ doc_module, self.one_dot_version)
+
+ logging.info('generating doc in %s' % web_output_dir[len(app.config.output_dir):])
+ if not os.path.exists(web_output_dir):
+ os.makedirs(web_output_dir)
+
+ for lang in doc.languages:
+ if lang == 'en' and not os.path.exists(os.path.join(ext_dirname, self.dirname, 'en')):
+ lang_dirname = os.path.join(ext_dirname, self.dirname, 'C')
+ else:
+ lang_dirname = os.path.join(ext_dirname, self.dirname, lang)
+
+ for doc_page in doc_pages:
+ xml_file = os.path.join(lang_dirname, doc_page)
+ if not os.path.exists(xml_file):
+ # the document had a translation available in a previous
+ # version, and it got removed
+ continue
+ filename = os.path.splitext(doc_page)[0] + '.html.' + lang
+
+ # format docbook into html files
+ cmd = ['xsltproc', '--output', web_output_dir + '/' + filename,
+ '--nonet', '--xinclude',
+ '--stringparam', 'libgo.lang', lang,
+ '--stringparam', 'libgo.channel', self.channel,
+ self.mal2html_xsl_file, xml_file]
+
+ if self.nightly:
+ cmd[5:5] = ['--param', 'libgo.nightly', 'true()']
+ onepage_cmd = cmd[:]
+
+ logging.debug('executing %s' % ' '.join(cmd))
+ rc = subprocess.call(cmd)
+ if rc != 0:
+ logging.warn('%s failed with error %d' % (' '.join(cmd), rc))
+
+ self.install_version_symlinks(doc)
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]