diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..12034792 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "lib/tornado"] + path = lib/tornado + url = git://github.com/facebook/tornado.git diff --git a/clyde.py b/clyde.py new file mode 100644 index 00000000..ad0202f9 --- /dev/null +++ b/clyde.py @@ -0,0 +1,78 @@ +import os +import sys +import tornado.auth +import tornado.httpserver +import tornado.ioloop +import tornado.options +import tornado.web +import simplejson as json +import unicodedata + +from tornado.options import define, options +from django.conf import settings +from hydeengine import setup_env +from hydeengine.siteinfo import SiteInfo + +define("port", default=8888, help="run on the given port", type=int) + +class Application(tornado.web.Application): + def __init__(self): + handlers = [ + (r"/site/([^/]+)", SiteHandler), + (r"/site/([^/]+/files)", FilesJSONHandler), + + ] + opts = dict( + static_path = os.path.join(os.path.dirname(__file__), "clydeweb/media"), + sites = dict( + mysite = "/Users/lakshmivyas/mysite" + ) + ) + tornado.web.Application.__init__(self, handlers, **opts) + +class FilesJSONHandler(tornado.web.RequestHandler): + def get(self, site): + if not hasattr(settings, 'siteinfo'): + setup_env('/Users/lakshmivyas/mysite') + siteinfo = SiteInfo(settings, '/Users/lakshmivyas/mysite') + siteinfo.refresh() + setattr(settings, 'siteinfo', siteinfo) + else: + siteinfo = settings.siteinfo + d = siteinfo.content_node.simple_dict + def jsresource(resource): + return dict( + attributes = dict(tooltip=resource['path'], rel='file'), + data = resource['name'] + ) + def jsnode(node): + children = [jsresource(resource) for resource in + node['resources']] + children.append([jsnode(child_node) + for child_node in node['nodes']]) + return dict( + attributes = dict(tooltip=node['path']), + data = node['name'], + children=children, + state='open' + ) + jsdict = jsnode(d) + jsonobj = json.dumps(jsdict) + self.set_header("Content-Type", "application/json") + self.write(jsonobj) + +class SiteHandler(tornado.web.RequestHandler): + def get(self, site): + self.render("clydeweb/templates/site.html") + + +def main(): + tornado.options.parse_command_line() + http_server = tornado.httpserver.HTTPServer(Application()) + http_server.listen(options.port) + tornado.ioloop.IOLoop.instance().start() + + +if __name__ == "__main__": + main() + \ No newline at end of file diff --git a/clydeweb/media/clyde.css b/clydeweb/media/clyde.css new file mode 100644 index 00000000..f5cb5020 --- /dev/null +++ b/clydeweb/media/clyde.css @@ -0,0 +1,39 @@ +body{ + margin: 32px; + font-family: Helvetica, sans-serif; + font-size: 12px; +} + +header{ + clear:both; + height: 96px; +} + +header h1{ + font-weight: bold; + font-size: 12px; + float: left; +} + +nav{ + float: right; + margin-right: 32px; +} + +nav ul{ + list-style-type:none; +} + +nav li{ + float:left; + margin:0 16px; +} + +aside{ + float:left; + margin-right: 16px; +} + +section{ + float:left; +} \ No newline at end of file diff --git a/clydeweb/media/jstree/jquery.tree.min.js b/clydeweb/media/jstree/jquery.tree.min.js new file mode 100644 index 00000000..27699ca8 --- /dev/null +++ b/clydeweb/media/jstree/jquery.tree.min.js @@ -0,0 +1 @@ +(function($){$.tree={datastores:{},plugins:{},defaults:{data:{async:false,type:"html",opts:{method:"GET",url:false}},selected:false,opened:[],languages:[],ui:{dots:true,animation:0,scroll_spd:4,theme_path:false,theme_name:"default",selected_parent_close:"select_parent",selected_delete:"select_previous"},types:{"default":{clickable:true,renameable:true,deletable:true,creatable:true,draggable:true,max_children:-1,max_depth:-1,valid_children:"all",icon:{image:false,position:false}}},rules:{multiple:false,multitree:"none",type_attr:"rel",createat:"bottom",drag_copy:"ctrl",drag_button:"left",use_max_children:true,use_max_depth:true,max_children:-1,max_depth:-1,valid_children:"all"},lang:{new_node:"New folder",loading:"Loading ..."},callback:{beforechange:function(NODE,TREE_OBJ){return true},beforeopen:function(NODE,TREE_OBJ){return true},beforeclose:function(NODE,TREE_OBJ){return true},beforemove:function(NODE,REF_NODE,TYPE,TREE_OBJ){return true},beforecreate:function(NODE,REF_NODE,TYPE,TREE_OBJ){return true},beforerename:function(NODE,LANG,TREE_OBJ){return true},beforedelete:function(NODE,TREE_OBJ){return true},beforedata:function(NODE,TREE_OBJ){return{id:$(NODE).attr("id")||0}},ondata:function(DATA,TREE_OBJ){return DATA},onparse:function(STR,TREE_OBJ){return STR},onhover:function(NODE,TREE_OBJ){},onselect:function(NODE,TREE_OBJ){},ondeselect:function(NODE,TREE_OBJ){},onchange:function(NODE,TREE_OBJ){},onrename:function(NODE,TREE_OBJ,RB){},onmove:function(NODE,REF_NODE,TYPE,TREE_OBJ,RB){},oncopy:function(NODE,REF_NODE,TYPE,TREE_OBJ,RB){},oncreate:function(NODE,REF_NODE,TYPE,TREE_OBJ,RB){},ondelete:function(NODE,TREE_OBJ,RB){},onopen:function(NODE,TREE_OBJ){},onopen_all:function(TREE_OBJ){},onclose_all:function(TREE_OBJ){},onclose:function(NODE,TREE_OBJ){},error:function(TEXT,TREE_OBJ){},ondblclk:function(NODE,TREE_OBJ){TREE_OBJ.toggle_branch.call(TREE_OBJ,NODE);TREE_OBJ.select_branch.call(TREE_OBJ,NODE)},onrgtclk:function(NODE,TREE_OBJ,EV){},onload:function(TREE_OBJ){},oninit:function(TREE_OBJ){},onfocus:function(TREE_OBJ){},ondestroy:function(TREE_OBJ){},onsearch:function(NODES,TREE_OBJ){NODES.addClass("search")},ondrop:function(NODE,REF_NODE,TYPE,TREE_OBJ){},check:function(RULE,NODE,VALUE,TREE_OBJ){return VALUE},check_move:function(NODE,REF_NODE,TYPE,TREE_OBJ){return true}},plugins:{}},create:function(){return new tree_component()},focused:function(){return tree_component.inst[tree_component.focused]},reference:function(obj){var o=$(obj);if(!o.size())o=$("#"+obj);if(!o.size())return null;o=(o.is(".tree"))?o.attr("id"):o.parents(".tree:eq(0)").attr("id");return tree_component.inst[o]||null},rollback:function(data){for(var i in data){if(!data.hasOwnProperty(i))continue;var tmp=tree_component.inst[i];var lock=!tmp.locked;if(lock)tmp.lock(true);tmp.inp=false;tmp.container.html(data[i].html).find(".dragged").removeClass("dragged").end().find(".hover").removeClass("hover");if(data[i].selected){tmp.selected=$("#"+data[i].selected);tmp.selected_arr=[];tmp.container.find("a.clicked").each(function(){tmp.selected_arr.push(tmp.get_node(this))})}if(lock)tmp.lock(false);delete lock;delete tmp}},drop_mode:function(opts){opts=$.extend(opts,{show:false,type:"default",str:"Foreign node"});tree_component.drag_drop.foreign=true;tree_component.drag_drop.isdown=true;tree_component.drag_drop.moving=true;tree_component.drag_drop.appended=false;tree_component.drag_drop.f_type=opts.type;tree_component.drag_drop.f_data=opts;if(!opts.show){tree_component.drag_drop.drag_help=false;tree_component.drag_drop.drag_node=false}else{tree_component.drag_drop.drag_help=$("
");tree_component.drag_drop.drag_node=tree_component.drag_drop.drag_help.find("li:eq(0)")}if($.tree.drag_start!==false)$.tree.drag_start.call(null,false)},drag_start:false,drag:false,drag_end:false};$.fn.tree=function(opts){return this.each(function(){var conf=$.extend({},opts);if(tree_component.inst&&tree_component.inst[$(this).attr('id')])tree_component.inst[$(this).attr('id')].destroy();if(conf!==false)new tree_component().init(this,conf)})};function tree_component(){return{cntr:++tree_component.cntr,settings:$.extend({},$.tree.defaults),init:function(elem,conf){var _this=this;this.container=$(elem);if(this.container.size==0)return false;tree_component.inst[this.cntr]=this;if(!this.container.attr("id"))this.container.attr("id","jstree_"+this.cntr);tree_component.inst[this.container.attr("id")]=tree_component.inst[this.cntr];tree_component.focused=this.cntr;this.settings=$.extend(true,{},this.settings,conf);if(this.settings.languages&&this.settings.languages.length){this.current_lang=this.settings.languages[0];var st=false;var id="#"+this.container.attr("id");for(var ln=0;ln a ins { ";else type_icons+="#"+this.container.attr("id")+" li[rel="+t+"] > a ins { ";if(this.settings.types[t].icon.image)type_icons+=" background-image:url("+this.settings.types[t].icon.image+"); ";if(this.settings.types[t].icon.position)type_icons+=" background-position:"+this.settings.types[t].icon.position+"; ";type_icons+="} "}}if(type_icons!="")tree_component.add_sheet({str:type_icons});if(this.settings.rules.multiple)this.selected_arr=[];this.offset=false;this.hovered=false;this.locked=false;if(tree_component.drag_drop.marker===false)tree_component.drag_drop.marker=$("
").attr({id:"jstree-marker"}).hide().appendTo("body");this.callback("oninit",[this]);this.refresh();this.attach_events();this.focus()},refresh:function(obj){if(this.locked)return this.error("LOCKED");var _this=this;if(obj&&!this.settings.data.async)obj=false;this.is_partial_refresh=obj?true:false;this.opened=Array();if(this.settings.opened!=false){$.each(this.settings.opened,function(i,item){if(this.replace(/^#/,"").length>0){_this.opened.push("#"+this.replace(/^#/,""))}});this.settings.opened=false}else{this.container.find("li.open").each(function(i){if(this.id){_this.opened.push("#"+this.id)}})}if(this.selected){this.settings.selected=Array();if(obj){$(obj).find("li:has(a.clicked)").each(function(){if(this.id)_this.settings.selected.push("#"+this.id)})}else{if(this.selected_arr){$.each(this.selected_arr,function(){if(this.attr("id"))_this.settings.selected.push("#"+this.attr("id"))})}else{if(this.selected.attr("id"))this.settings.selected.push("#"+this.selected.attr("id"))}}}else if(this.settings.selected!==false){var tmp=Array();if((typeof this.settings.selected).toLowerCase()=="object"){$.each(this.settings.selected,function(){if(this.replace(/^#/,"").length>0)tmp.push("#"+this.replace(/^#/,""))})}else{if(this.settings.selected.replace(/^#/,"").length>0)tmp.push("#"+this.settings.selected.replace(/^#/,""))}this.settings.selected=tmp}if(obj&&this.settings.data.async){this.opened=Array();obj=this.get_node(obj);obj.find("li.open").each(function(i){_this.opened.push("#"+this.id)});if(obj.hasClass("open"))obj.removeClass("open").addClass("closed");if(obj.hasClass("leaf"))obj.removeClass("leaf");obj.children("ul:eq(0)").html("");return this.open_branch(obj,true,function(){_this.reselect.apply(_this)})}var _this=this;var _datastore=new $.tree.datastores[this.settings.data.type]();if(this.container.children("ul").size()==0){this.container.html("")}_datastore.load(this.callback("beforedata",[false,this]),this,this.settings.data.opts,function(data){data=_this.callback("ondata",[data,_this]);_datastore.parse(data,_this,_this.settings.data.opts,function(str){str=_this.callback("onparse",[str,_this]);_this.container.empty().append($("