Commits

Kamil Kisiel committed 59f5c26

Report an error if the MathJax install cannot be found on plugin initialization.

  • Participants
  • Parent commits 4770122

Comments (0)

Files changed (1)

File tracmathjax/tracmathjax.py

 from trac.web.api import IRequestFilter
 from trac.web.chrome import ITemplateProvider, add_script
 from trac.wiki.api import IWikiSyntaxProvider, IWikiMacroProvider
+import os.path
         
 MACRO_DESCRIPTION = \
 """Renders a LaTeX using MathJax.
 }}}
 """
 
+MATHJAX_DIR = "MathJax"
+MATHJAX_JS = "MathJax.js"
+
 class TracMathJax(Component):
     implements(ITemplateProvider, 
                IRequestFilter, 
                IWikiSyntaxProvider,
                IWikiMacroProvider)
 
+    def __init__(self):
+        self.mathjax_path = os.path.abspath(self.config.get('tracmathjax', 'mathjax_path'))
+        self.log.debug("MathJax path: %s" % self.mathjax_path)
+        if not os.path.exists(os.path.join(self.mathjax_path, MATHJAX_JS)):
+            self.log.error("Could not find a MathJax install at %s" % self.mathjax_path)
+
     # ITemplateProvider methods
     def get_htdocs_dirs(self):
-        mathjax_path = self.config.get('tracmathjax', 'mathjax_path')
-        self.log.debug("MathJax path: %s" % mathjax_path)
-        return [("MathJax", mathjax_path)]
+        return [(MATHJAX_DIR, self.mathjax_path)]
 
     def get_templates_dirs(self):
         # we have no templates
         return handler
 
     def post_process_request(self, req, template, data, content_type):
-        add_script(req, "/chrome/MathJax/MathJax.js")
+        add_script(req, "/chrome/%s/%s" % (MATHJAX_DIR, MATHJAX_JS))
         return template, data, content_type
 
     # IWikiSyntaxProvider methods