Skip to content
Permalink
Browse files

improve docserver, checks the IE layout

  • Loading branch information...
sdpython committed Oct 29, 2014
1 parent c22d7af commit e326a9e94871bc3c062115c0e22c6559294de921
@@ -13,6 +13,7 @@
from .utils_sphinx_doc import prepare_file_for_sphinx_help_generation
from .utils_sphinx_doc_helpers import HelpGenException
from ..sync.synchelper import explore_folder, has_been_updated
from .utils_sphinx_config import ie_layout_html

template_examples = """
@@ -101,7 +102,17 @@ def generate_help_sphinx ( project_var_name,
The function requires:
- pandoc
- latex
@warning Some themes such as `Bootstrap Sphinx Theme <http://ryan-roemer.github.io/sphinx-bootstrap-theme/>`_ do not work on Internet Explorer. In that case, the
file ``<python_path>/Lib/site-packages/sphinx/themes/basic/layout.html``
must be modified to add the following line (just below ``Content-Type``).
@code
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
@endcode
"""
ie_layout_html()

root = os.path.abspath(root)
froot = root
sys.path.append (os.path.join(root, "_doc", "sphinxdoc","source"))
@@ -0,0 +1,34 @@
"""
@file
@brief Check various settings.
"""

import sys, os

def ie_layout_html():
"""
The layout produced by sphinx does not always work with Internet Explorer.
See `Issue with some Sphinx themes and Internet Explorer <http://www.xavierdupre.fr/blog/2014-10-27_nojs.html>`_.
@return boolean
If False, raises an exception.
"""
tofind = '<meta http-equiv="X-UA-Compatible" content="IE=edge" />'

path = os.path.dirname(sys.executable)
layout = os.path.join( path, "Lib","site-packages","sphinx","themes","basic","layout.html")
if os.path.exists(layout):
with open(layout, "r", encoding="utf-8") as f :
content = f.read()
if tofind not in content:
all = [ "unable to find: " + tofind + " in "]
all.append (' File "{0}", line 1'.format(layout))
raise Exception("\n".join(all))
return True
else:
raise FileNotFoundError("Sphinx is not properly installed, unable to find: " + layout)

if __name__ == "__main__":
ie_layout_html()
@@ -109,43 +109,35 @@ def do_redirect(self, path="/index.html"):
self.send_header('Location', path)
self.end_headers()

media_types = {
".js" : ( 'application/javascript', 'r' ),
".css" : ("text/css", 'r'),
".html" : ('text/html', 'r'),
".py" : ('text/html','execute'),
".png" : ('image/png','rb'),
".jpg" : ('image/jpeg','rb'),
".ico" : ('image/x-icon','rb'),
".gif" : ('image/gif','rb'),
".eot" : ('application/vnd.ms-fontobject','rb'),
".ttf" : ('application/font-sfnt','rb'),
".otf" : ('font/opentype','rb'),
".svg" : ('image/svg+xml','r'),
".woff" : ('application/font-wof','rb'),
}

def get_ftype(self, path):
"""
defines the header to send (type of files) based on path
@param path location (a string)
@return htype, ftype (html, css, ...)
If a type is missing, you should look for the ``MIME TYPE``
on a search engine.
See also `media-types <http://www.iana.org/assignments/media-types/media-types.xhtml>`_
"""
htype = ''
ftype = ''

if path.endswith('.js'):
htype = 'application/javascript'
ftype = 'r'
elif path.endswith('.css'):
htype = 'text/css'
ftype = 'r'
elif path.endswith('.html'):
htype = 'text/html'
ftype = 'r'
elif path.endswith('.py'):
htype = 'text/html'
ftype = 'execute'
elif path.endswith('.png'):
htype = 'image/png'
ftype = 'rb'
elif path.endswith('.jpg'):
htype = 'image/jpeg'
ftype = 'rb'
elif path.endswith('.jepg'):
htype = 'image/jpeg'
ftype = 'rb'
elif path.endswith('.ico'):
htype = 'image/x-icon'
ftype = 'rb'
elif path.endswith('.gif'):
htype = 'image/gif'
ftype = 'rb'

ext = "." + path.split(".")[-1]
htype, ftype = DocumentationHandler.media_types.get(ext, ('',''))
return htype, ftype

def send_headers(self, path):

0 comments on commit e326a9e

Please sign in to comment.
You can’t perform that action at this time.