# =========================================================================== # eXe # Copyright 2004-2005, University of Auckland # Copyright 2004-2008 eXe Project, http://eXeLearning.org/ # # 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # =========================================================================== """ This class transforms an eXe node into a page on a single page website """ import logging import re from cgi import escape from urllib import quote from exe.webui.blockfactory import g_blockFactory from exe.engine.error import Error from exe.engine.path import Path from exe.export.pages import Page, uniquifyNames from exe.webui import common log = logging.getLogger(__name__) # =========================================================================== class SinglePage(Page): """ This class transforms an eXe node into a page on a single page website """ def save(self, filename, for_print=0): """ Save page to a file. 'outputDir' is the directory where the filenames will be saved (a 'path' instance) """ outfile = open(filename, "w") outfile.write(self.render(self.node.package,for_print).encode('utf8')) outfile.close() def render(self, package, for_print=0): """ Returns an XHTML string rendering this page. """ html = self.renderHeader(package.name, for_print) if for_print: # include extra onload bit: html += u'\n' else: html += u"\n" html += u"
\n" html += u"
\n" html += escape(package.title) html += u"
\n" html += u"
\n" html += self.renderNode(package.root) html += u"
\n" html += self.renderLicense() html += self.renderFooter() html += u"
\n" html += u"\n" return html def renderHeader(self, name, for_print=0): """ Returns an XHTML string for the header of this page. """ html = u"\n" html += u'\n' html += u"\n" html += u"\n" html += u"" html += u"" html += name html += "\n" html += u"\n"; html += u'\n' if for_print: # include extra print-script for onload bit html += u'\n' html += u"\n" return html def renderNode(self, node): """ Returns an XHTML string for this node and recurse for the children """ html = "" html += '
\n' html += '
' html += '

' html += escape(node.titleLong) html += '

\n' style = self.node.package.style for idevice in node.idevices: html += u'
\n' % (idevice.klass, idevice.id) block = g_blockFactory.createBlock(None, idevice) if not block: log.critical("Unable to render iDevice.") raise Error("Unable to render iDevice.") if hasattr(idevice, "isQuiz"): html += block.renderJavascriptForWeb() html += self.processInternalLinks(block.renderView(style)) html += u'
\n' # iDevice div html += '
\n' # node div for child in node.children: html += self.renderNode(child) return html def processInternalLinks(self, html): """ take care of any internal links which are in the form of: href="exe-node:Home:Topic:etc#Anchor" For this SinglePage Export, go ahead and keep the #Anchor portion, but remove the 'exe-node:Home:Topic:etc', since it is all exported into the same file. """ return common.removeInternalLinkNodes(html)