xoslib wip
diff --git a/planetstack/core/xoslib/templatetags/mustache.py b/planetstack/core/xoslib/templatetags/mustache.py
new file mode 100644
index 0000000..a3b3b2a
--- /dev/null
+++ b/planetstack/core/xoslib/templatetags/mustache.py
@@ -0,0 +1,51 @@
+from django import template
+from django.conf import settings
+import pystache
+import os
+
+register = template.Library()
+
+class View(pystache.View):
+ template_path = settings.TEMPLATE_DIRS[0]
+
+ def __init__(self, template_dir, template_name, context):
+ self.template_path = template_dir
+ self.template_name = template_name
+ return super(View, self).__init__(context=context)
+
+class MustacheNode(template.Node):
+ def __init__(self, template_name, attr=None):
+ for template_dir in settings.TEMPLATE_DIRS:
+ if os.path.exists(os.path.join(template_dir, template_name) + ".mustache"):
+ break
+ else:
+ raise IOError("failed to find %s in %s" % (template_name, str(settings.TEMPLATE_DIRS)))
+
+ self.template_path = template_dir
+ self.template = template_name
+ self.attr = attr
+
+ def render(self, context):
+ mcontext = context[self.attr] if self.attr else {}
+ view = View(self.template_path, self.template, context=mcontext)
+ return view.render()
+
+def do_mustache(parser, token):
+ """
+ Loads a mustache template and render it inline
+
+ Example::
+
+ {% mustache "foo/bar" data %}
+
+ """
+ bits = token.split_contents()
+ if len(bits) not in [2,3]:
+ raise template.TemplateSyntaxError("%r tag takes two arguments: the location of the template file, and the template context" % bits[0])
+ path = bits[1]
+ path = path[1:-1]
+ attrs = bits[2:]
+ return MustacheNode(path, *attrs)
+
+
+register.tag("mustache", do_mustache)
diff --git a/planetstack/core/xoslib/templatetags/straight_include.py b/planetstack/core/xoslib/templatetags/straight_include.py
new file mode 100644
index 0000000..54710f3
--- /dev/null
+++ b/planetstack/core/xoslib/templatetags/straight_include.py
@@ -0,0 +1,62 @@
+"""
+Straight Include template tag by @HenrikJoreteg
+
+Django templates don't give us any way to escape template tags.
+
+So if you ever need to include client side templates for ICanHaz.js (or anything else that
+may confuse django's templating engine) You can is this little snippet.
+
+Just use it as you would a normal {% include %} tag. It just won't process the included text.
+
+It assumes your included templates are in you django templates directory.
+
+Usage:
+
+{% load straight_include %}
+
+{% straight_include "my_icanhaz_templates.html" %}
+
+"""
+
+import os
+from django import template
+from django.conf import settings
+
+
+register = template.Library()
+
+
+class StraightIncludeNode(template.Node):
+ def __init__(self, template_path):
+ for template_dir in settings.TEMPLATE_DIRS:
+ self.filepath = '%s/%s' % (template_dir, template_path)
+ if os.path.exists(self.filepath):
+ break
+ else:
+ raise IOError("cannot find %s in %s" % (template_path, str(TEMPLATE_DIRS)))
+
+ def render(self, context):
+ fp = open(self.filepath, 'r')
+ output = fp.read()
+ fp.close()
+ return output
+
+
+def do_straight_include(parser, token):
+ """
+ Loads a template and includes it without processing it
+
+ Example::
+
+ {% straight_include "foo/some_include" %}
+
+ """
+ bits = token.split_contents()
+ if len(bits) != 2:
+ raise template.TemplateSyntaxError("%r tag takes one argument: the location of the file within the template folder" % bits[0])
+ path = bits[1][1:-1]
+
+ return StraightIncludeNode(path)
+
+
+register.tag("straight_include", do_straight_include)