Commits

Simone Marzola committed ce04a5f

monkeypatch the ArtichokeTemplateLoader

Comments (0)

Files changed (5)

controllers/root.py

-import gartichoke
+import artichoke
 import os
 from artichoke import expose
 from google.appengine.api.app_identity import get_application_id
 
-class SubController(gartichoke.Controller):
+class SubController(artichoke.Controller):
     @expose()
     def about(self, args, params):
         return 'HELLO %s' % str(args)
     def not_found(self, args, params):
         return 'Sub Not Found'
 
-class RootController(gartichoke.Controller):
+class RootController(artichoke.Controller):
     def __init__(self, application, templates_path, helpers):
         super(RootController, self).__init__(application, templates_path, helpers)
         self.sub = SubController(application, os.path.join(templates_path, 'sub'), helpers)

gartichoke/__init__.py

-from controller import Controller
+import artichoke.controller
+import monkey
+artichoke.controller.ArtichokeTemplateLoader = monkey.JinjaTemplateLoader

gartichoke/controller.py

-import artichoke
-import jinja2
-
-response = artichoke.controller.response
-url = artichoke.controller.url
-
-class JinjaTemplateLoader(object):
-    def __init__(self, path, *args, **kw):
-        self.jinja_environ = jinja2.Environment(loader=jinja2.FileSystemLoader(path))
-
-    def load(self, tmpl):
-        if not tmpl.endswith('jinja'):
-            tmpl += '.jinja'
-
-        template = self.jinja_environ.get_template(tmpl)
-        return template
-
-class Controller(artichoke.controller.Controller):
-    def __init__(self, application, template_path, helpers):
-        super(Controller, self).__init__(application, template_path, helpers)
-        self.loader = JinjaTemplateLoader(template_path)
-
-    def render(self, template, params):
-        if not self.application.autoreload_templates:
-            try:
-                tmpl = self.templates[template]
-            except:
-                tmpl = self.loader.load(template)
-                self.templates[template] = tmpl
-        else:
-            self.loader = JinjaTemplateLoader(self.template_path)
-            tmpl = self.loader.load(template)
-
-        return tmpl.render(params)
-
-    def do_call(self, call, request, path):
-        response.content_type = call.artichoke['content-type']
-        self.inject_tools(request, response)
-
-        if call.artichoke['template']:
-            tmpl_context = {}
-            tmpl_context['a'] = type('Bunch', (object,), {'url':staticmethod(url)})
-            tmpl_context['h'] = self.helpers
-            tmpl_context['request'] = request
-            tmpl_context['response'] = response
-            tmpl_context.update(call(path, request.params))
-
-            template = call.artichoke['template']
-            response.text = self.render(template, tmpl_context)
-        else:
-            response.body = call(path, request.params)
-
-        return response
-
-
+import gartichoke
 import artichoke
 from controllers.root import RootController
 

views/index.jinja

     </p>
     <a class="close-reveal-modal">×</a>
   </div>
-  
-  
-  <!-- Included JS Files (Uncompressed) -->
-  <!--
-  
-  <script src="javascripts/jquery.js"></script>
-  
-  <script src="javascripts/jquery.foundation.mediaQueryToggle.js"></script>
-  
-  <script src="javascripts/jquery.foundation.forms.js"></script>
-  
-  <script src="javascripts/jquery.foundation.reveal.js"></script>
-  
-  <script src="javascripts/jquery.foundation.orbit.js"></script>
-  
-  <script src="javascripts/jquery.foundation.navigation.js"></script>
-  
-  <script src="javascripts/jquery.foundation.buttons.js"></script>
-  
-  <script src="javascripts/jquery.foundation.tabs.js"></script>
-  
-  <script src="javascripts/jquery.foundation.tooltips.js"></script>
-  
-  <script src="javascripts/jquery.foundation.accordion.js"></script>
-  
-  <script src="javascripts/jquery.placeholder.js"></script>
-  
-  <script src="javascripts/jquery.foundation.alerts.js"></script>
-  
-  <script src="javascripts/jquery.foundation.topbar.js"></script>
-  
-  -->
-  
-  <!-- Included JS Files (Compressed) -->
+
   <script src="javascripts/jquery.js"></script>
   <script src="javascripts/foundation.min.js"></script>
-  
-  <!-- Initialize JS Plugins -->
+
   <script src="javascripts/app.js"></script>
 </body>
 </html>