Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactoring layouts module

added css links
added js links
  • Loading branch information...
commit e99b7537c4adf37774fe95156fe40bb4fb4fe1dc 1 parent 501b2a1
@sadig authored
View
4 cocoyam/layouts/templates/apps/layouts/css/link.tmpl
@@ -0,0 +1,4 @@
+{% if status != "notfound" %}
+<link rel="stylesheet" href="{{ cssfile.cssfile.url}}" rel='stylesheet' type='text/css' />
+{% endif %}
+
View
4 cocoyam/layouts/templates/apps/layouts/js/script.tmpl
@@ -0,0 +1,4 @@
+{% if not jsfile.status %}
+<script src="{{ jsfile.jsfile.url }}"></script>
+{% endif %}
+
View
0  cocoyam/layouts/templatetags/__init__.py
No changes.
View
38 cocoyam/layouts/templatetags/css.py
@@ -0,0 +1,38 @@
+from django import template
+from django.conf import settings
+from cocoyam.layouts.models import CSSFiles
+
+
+class CSSGenerator(template.Node):
+ template="apps/layouts/css/link.tmpl"
+
+ def __init__(self,content_id):
+ if content_id[0] in ('"',"'") and content_id[-1]==content_id[0]:
+ self._content_id=content_id[1:-1]
+ else:
+ self._content_id=template.Variable(self._content_id)
+
+ def render(self,context):
+ t=template.loader.get_template(self.template)
+ content_id=self._content_id
+ if isinstance(self._content_id,template.Variable):
+ content_id=self._content_id.resolve(context)
+ try:
+ cssfile=CSSFiles.objects.get(idname=content_id)
+ context["cssfile"]=cssfile
+ except CSSFiles.DoesNotExist,e:
+ context["cssfile"]={}
+ context["cssfile"]["status"]="notfound"
+ return t.render(template.Context(context))
+
+
+def do_generate_css_link(parser,token):
+ try:
+ tagname,content_id=token.split_contents()
+ except valueError:
+ raise template.TemplateSyntaxError("%r needs at least one argument" % token.contents.split()[0])
+ return CSSGenerator(content_id)
+
+
+register=template.Library()
+register.tag('css_link',do_generate_css_link)
View
38 cocoyam/layouts/templatetags/js.py
@@ -0,0 +1,38 @@
+from django import template
+from django.conf import settings
+from cocoyam.layouts.models import JSFiles
+
+
+class JSGenerator(template.Node):
+ template="apps/layouts/js/script.tmpl"
+
+ def __init__(self,content_id):
+ if content_id[0] in ('"',"'") and content_id[-1]==content_id[0]:
+ self._content_id=content_id[1:-1]
+ else:
+ self._content_id=template.Variable(self._content_id)
+
+ def render(self,context):
+ t=template.loader.get_template(self.template)
+ content_id=self._content_id
+ if isinstance(self._content_id,template.Variable):
+ content_id=self._content_id.resolve(context)
+ try:
+ cssfile=JSFiles.objects.get(idname=content_id)
+ context["jsfile"]=cssfile
+ except CSSFiles.DoesNotExist,e:
+ context["jsfile"]={}
+ context["jsfile"]["status"]="notfound"
+ return t.render(template.Context(context))
+
+
+def do_generate_js_link(parser,token):
+ try:
+ tagname,content_id=token.split_contents()
+ except valueError:
+ raise template.TemplateSyntaxError("%r needs at least one argument" % token.contents.split()[0])
+ return JSGenerator(content_id)
+
+
+register=template.Library()
+register.tag('js_link',do_generate_js_link)

0 comments on commit e99b753

Please sign in to comment.
Something went wrong with that request. Please try again.