Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

better template abstraction

  • Loading branch information...
commit 5473e93025e1208599c667ccce4e0c33210f637e 1 parent 73c6e43
mvr authored
4 lib/cortex/services/web/__init__.py
View
@@ -37,8 +37,8 @@ def start(self):
"""
d = os.path.dirname(__file__)
code_dir = os.path.dirname(cortex.__file__)
- static_dir = os.path.join(d,'static')
- favicon = os.path.join(static_dir,'favicon.ico')
+ static_dir = os.path.join(d, 'static')
+ favicon = os.path.join(static_dir, 'favicon.ico')
root = Root()
root.putChild('static', static.File(static_dir))
21 lib/cortex/services/web/resource.py
View
@@ -79,7 +79,6 @@ class ObjectResource(Resource):
def __init__(self, obj):
self._obj = obj
-<<<<<<< HEAD
@property
def is_atom(self):
return isinstance(self.target, ( int, str ))
@@ -91,13 +90,16 @@ def is_complex(self):
@property
def template(self):
if isinstance(self.target, Agent):
- return template('objects/agent'),{}
+ return [template('objects/agent'),
+ dict(source=inspect.getsource(self.target.__class__))]
elif isinstance(self.target, types.MethodType):
- return template('objects/method'),dict(source=inspect.getsource(self.target))
+ return [template('objects/method'),
+ dict(source=inspect.getsource(self.target))]
elif self.is_atom:
- return template('objects/primitive'),{}
+ return [template('objects/primitive'),{}]
else:
- return template('objects/abstract'),{}
+ return [template('objects/abstract'),
+ dict(source=inspect.getsource(self.target))]
def render_GET(self, request):
""" """
@@ -116,7 +118,7 @@ def render_GET(self, request):
t,extra_ctx=self.template
ctx.update(**extra_ctx)
return str(t.render(**ctx))
-=======
+
def resolve_object(self, obj_path, target=None):
target = target or self._obj
while obj_path:
@@ -128,11 +130,8 @@ def obj_name(self, target):
obj_name = obj_name.replace('<','(').replace('>',')')
return obj_name
- def is_atom(self, target):
- return isinstance(target, (int,str))
+ """ def render_GET(self, request):
- def render_GET(self, request):
- """ """
obj_path = filter(None, request.postpath)
target = self.resolve_object(obj_path)
ctx = dict(path=request.postpath, request=request)
@@ -146,5 +145,5 @@ def render_GET(self, request):
methods=ns.methods.keys(),
private=ns.private.keys())
ctx.update(obj_name=self.obj_name(target))
- return str(_template.render(**ctx))
+ return str(_template.render(**ctx))"""
ObjResource = ObjectResource
2  lib/cortex/services/web/static/css/base.css
View
@@ -90,7 +90,7 @@
blockquote cite:before { content: "\2014 \0020"; }
blockquote cite a, blockquote cite a:visited, blockquote cite a:visited { color: #555; }
- hr { border: solid #ddd; border-width: 1px 0 0; clear: both; margin: 10px 0 30px; height: 0; }
+ hr { border: solid #ddd; border-width: 1px 0 0; clear: both; height: 0; }
/* #Links
30 lib/cortex/services/web/static/js/tabs.js
View
@@ -1,29 +1 @@
-
-/**
- * Skeleton V1.1
- * Copyright 2011, Dave Gamache
- * www.getskeleton.com
- * Free to use under the MIT license.
- * http://www.opensource.org/licenses/mit-license.php
- * 8/17/2011
- */
-
-(function ($) {
- // hash change handler
- function hashchange () {
- var hash = window.location.hash
- , el = $('ul.tabs [href*="' + hash + '"]')
- , content = $(hash)
-
- if (el.length && !el.hasClass('active') && content.length) {
- el.closest('.tabs').find('.active').removeClass('active');
- el.addClass('active');
- content.show().addClass('active').siblings().hide().removeClass('active');
- }
- }
-
- // listen on event and fire right away
- $(window).on('hashchange.skeleton', hashchange);
- hashchange();
- $(hashchange);
-})(jQuery);
+$(document).ready(function(){$('.hidden').hide();})
3  lib/cortex/services/web/template.py
View
@@ -4,7 +4,8 @@
from jinja2 import Environment, PackageLoader
from cortex.contrib.pygments_extension import PygmentsExtension
env = Environment(loader=PackageLoader('cortex.services.web', 'templates'),
- extensions=[PygmentsExtension,with_])
+ extensions=[with_,
+ PygmentsExtension, ])
def template(name):
return env.get_template(name + '.html')
2  lib/cortex/services/web/templates/objects/_namespace.html
View
@@ -1,4 +1,6 @@
+{%if namespace%}
<ul>{% for x in namespace%}
<li><a href={{request.path}}/{{x}}>{{x}}</a>
{%endfor%}
</ul>
+{%else%}<b>Nada</b>{%endif%}
24 lib/cortex/services/web/templates/objects/abstract.html
View
@@ -2,22 +2,10 @@
{%block page_title%}{{obj_name}}{%endblock%}
{%block obj_type%}unknown object type{%endblock%}
-
-{%block one%}
-<strong>Everything:</strong><br/>
-{%with namespace=all_namespace%}{%include "objects/_namespace.html"%}{%endwith%}
-{%endblock%}
-
-
-{%block two%}
-<strong>Methods:</strong><br/>
-{%with namespace=methods%}{%include "objects/_namespace.html"%}{%endwith%}
-{%endblock%}
-
-
-{%block three%}
-<strong>Private:</strong><br/>
-{%with namespace=private%}{%include "objects/_namespace.html"%}{%endwith%}
-<hr/>
-</html>
+{%block obj_namespace%}
+{{super()}}
+<td>
+ <strong>Methods:</strong><br/>
+ {% with namespace=methods%}{%include "objects/_namespace.html"%}{%endwith%}
+</td>
{%endblock%}
25 lib/cortex/services/web/templates/objects/agent.html
View
@@ -4,23 +4,10 @@
{%block page_title%}{{obj_name}}{%endblock%}
{%block obj_type%}AGENT{%endblock%}
-{%block main%}
-
-
-<table>
- <tr>
- <td>
- <strong>Everything:</strong><hr/>
- {% with namespace=all_namespace%}{%include "objects/_namespace.html"%}{%endwith%}
- </td>
- <td>
- <strong>Methods:</strong><hr/>
- {% with namespace=methods%}{%include "objects/_namespace.html"%}{%endwith%}
- </td>
- <td>
- <strong>Private:</strong><hr/>
- {%with namespace=private%}{%include "objects/_namespace.html"%}{%endwith%}
- </td>
- </tr>
-</table>
+{%block obj_namespace%}
+ {{super()}}
+ <td>
+ <strong>Behaviours:</strong><hr/>
+ {% with namespace=methods%}{%include "objects/_namespace.html"%}{%endwith%}
+ </td>
{%endblock%}
39 lib/cortex/services/web/templates/objects/base.html
View
@@ -1,6 +1,45 @@
{%extends "index.html"%}
{%block page_title%}{{obj_name}}{%endblock%}
+
+{%block main%}
+
+<div class=nav2>
+ {%block obj_nav%}
+ <a href="javascript:$('#source_code').toggle();">Source</a>
+ <a href="javascript:$('#namespace').toggle();">Namespace</a>
+ {%endblock%}
+</div><hr/>
+
+{%block obj_main%}
+<table id=namespace class=hidden>
+ <tr>
+ {%block obj_namespace%}
+ <td>
+ <strong>Everything:</strong><hr/>
+ {% with namespace=all_namespace%}{%include "objects/_namespace.html"%}{%endwith%}
+ </td>
+ <td>
+ <strong>Private:</strong><hr/>
+ {%with namespace=private%}{%include "objects/_namespace.html"%}{%endwith%}
+ </td>
+ {%endblock%}
+ </tr>
+</table>
+{%block obj_source%}
+<div id=source_code class=hidden>
+ <strong>Source:</strong><hr/>
+ {% code 'python' %}
+ {{source}}
+ {% endcode %}
+ <hr/>
+</div>
+{%endblock%}
+
+{%endblock%}
+{%endblock%}
+
+
{%block page_subtitle%}
&nbsp;&nbsp;&nbsp;
{{request.path}}
Please sign in to comment.
Something went wrong with that request. Please try again.