[Checkins] SVN: Sandbox/J1m/dojoapibrowser/ initial version

Jim Fulton jim at zope.com
Tue Jun 29 07:10:08 EDT 2010


Log message for revision 113969:
  initial version

Changed:
  A   Sandbox/J1m/dojoapibrowser/api.js
  A   Sandbox/J1m/dojoapibrowser/buildout.cfg
  A   Sandbox/J1m/dojoapibrowser/fetch.py
  A   Sandbox/J1m/dojoapibrowser/index.html

-=-
Added: Sandbox/J1m/dojoapibrowser/api.js
===================================================================
--- Sandbox/J1m/dojoapibrowser/api.js	                        (rev 0)
+++ Sandbox/J1m/dojoapibrowser/api.js	2010-06-29 11:10:08 UTC (rev 113969)
@@ -0,0 +1,46 @@
+dojo.require('dijit.Tree');
+dojo.require("dojo.data.ItemFileReadStore");
+dojo.require("dijit.layout.ContentPane");
+dojo.require("dijit.layout.BorderContainer");
+     
+
+dojo.addOnLoad((function () {
+
+    var store = new dojo.data.ItemFileReadStore({ url: "api.json"});
+
+    var treeModel = new dijit.tree.TreeStoreModel({
+        store: store,
+        query: { id: 'root' },
+        rootId: "root"
+    });
+    var div = dojo.create('div',{}, dojo.body());
+    var border = new dijit.layout.BorderContainer({
+        style: 'width: 100%; height: 100%',
+        liveSplitters: true
+    });
+    div.appendChild(border.domNode);
+    border.addChild(
+        new dijit.layout.ContentPane({
+            content: new dijit.Tree({
+                model: treeModel,
+                onClick: function (node) {
+                    if (node.url[0])
+                        iframe.src = 'http://dojotoolkit.org'+node.url[0];
+                }
+            }, "treeOne"),
+            style: 'width: 20em',
+            splitter: true,
+            region:  'left'
+        })
+    );
+    border.addChild(
+        new dijit.layout.ContentPane({
+            region: 'center'
+        })
+    );
+    var iframe = dojo.create('iframe', {
+        style: 'width: 100%; height: 99%'
+    }, border.getChildren()[1].containerNode);
+    border.startup();
+    border.layout();
+}));


Property changes on: Sandbox/J1m/dojoapibrowser/api.js
___________________________________________________________________
Added: svn:eol-style
   + native

Added: Sandbox/J1m/dojoapibrowser/buildout.cfg
===================================================================
--- Sandbox/J1m/dojoapibrowser/buildout.cfg	                        (rev 0)
+++ Sandbox/J1m/dojoapibrowser/buildout.cfg	2010-06-29 11:10:08 UTC (rev 113969)
@@ -0,0 +1,7 @@
+[buildout]
+parts = py
+
+[py]
+recipe = zc.recipe.egg
+eggs = BeautifulSoup
+interpreter = py


Property changes on: Sandbox/J1m/dojoapibrowser/buildout.cfg
___________________________________________________________________
Added: svn:eol-style
   + native

Added: Sandbox/J1m/dojoapibrowser/fetch.py
===================================================================
--- Sandbox/J1m/dojoapibrowser/fetch.py	                        (rev 0)
+++ Sandbox/J1m/dojoapibrowser/fetch.py	2010-06-29 11:10:08 UTC (rev 113969)
@@ -0,0 +1,82 @@
+import BeautifulSoup
+import json
+import os
+import sys
+import urllib2
+
+class Node(dict):
+
+    def __init__(self, label, url, id):
+        assert isinstance(label, unicode)
+        self.label = label
+        self.url = url
+        self.id = id
+
+def links():
+    nnodes = 0
+    root = Node(u'Dojo toolkit API', '/api', 'root')
+    for top in 'dojo', 'dijit', 'dojox', 'djConfig':
+        f = urllib2.urlopen('http://dojotoolkit.org/api/%s.html' % top)
+        soup = BeautifulSoup.BeautifulSoup(f.read())
+        f.close()
+        prefix = '/api/%s/' % top
+        for a in soup.findAll('a', **{'class': 'jsdoc-link'}):
+            href = a['href']
+            if not href.startswith(prefix):
+                continue
+            if not href.endswith('.html'):
+                continue
+            names = href[5:-5].split('/')
+            node = root
+            url = root.url
+            for n in names:
+                url += '/'+n
+                if n not in node:
+                    nnodes += 1
+                    node[n] = Node(n, url+'.html', 'n%s' % nnodes)
+                node = node[n]
+            node.label = u''.join(a.contents)
+            node.url = href
+
+    result = dict(identifier='id', label='label',
+                  items = [d for d in flatten(root)])
+    result = json.dumps(result)
+    return result
+
+def flatten(node):
+    data = dict(
+        id=node.id, url=node.url,
+        label=node.label,
+        )
+    if node:
+        children = sorted(node.values(), key=lambda n: n.label.lower())
+        goofy_prefix = node.label + '._'
+        goofy = [n for n in children if n.label.startswith(goofy_prefix)]
+        if goofy:
+            children = [dict(_reference=n.id)
+                        for n in children
+                        if not n.label.startswith(goofy_prefix)]
+            goofy = dict(
+                label = 'underware',
+                id=node.id+'goofy',
+                url='',
+                children=[dict(_reference=n.id) for n in goofy]
+                )
+            children.append(dict(_reference=goofy['id']))
+            yield goofy
+            data['children'] = children
+        else:
+            data['children'] = [dict(_reference=n.id) for n in children]
+    yield data
+    for n in sorted(node):
+        for data in flatten(node[n]):
+            yield data
+
+def main(args=None):
+    if args is None:
+        args = sys.argv[1:]
+    out, = args
+    open(out, 'w').write(links())
+
+if __name__ == '__main__':
+    main(['api.json'])


Property changes on: Sandbox/J1m/dojoapibrowser/fetch.py
___________________________________________________________________
Added: svn:keywords
   + Id
Added: svn:eol-style
   + native

Added: Sandbox/J1m/dojoapibrowser/index.html
===================================================================
--- Sandbox/J1m/dojoapibrowser/index.html	                        (rev 0)
+++ Sandbox/J1m/dojoapibrowser/index.html	2010-06-29 11:10:08 UTC (rev 113969)
@@ -0,0 +1,23 @@
+<html>
+  <head>
+    <title>Dojo API</title>
+
+    <style type="text/css">
+      @import "http://o.aolcdn.com/dojo/1.4/dojo/resources/dojo.css";
+      @import "http://o.aolcdn.com/dojo/1.4/dijit/themes/tundra/tundra.css";
+    </style>
+
+    <script
+       type="text/javascript"
+       src="http://o.aolcdn.com/dojo/1.4/dojo/dojo.xd.js.uncompressed.js"
+       ></script>
+
+    <script
+       type="text/javascript"
+       src="api.js"
+       ></script>
+
+  </head>
+  <body class="tundra">
+  </body>
+</html>


Property changes on: Sandbox/J1m/dojoapibrowser/index.html
___________________________________________________________________
Added: svn:eol-style
   + native



More information about the checkins mailing list