Skip to content

Commit

Permalink
renames event:prevent/stopProp changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Morris-Pearce committed May 28, 2012
1 parent 95a41d0 commit 8c71ee7
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 43 deletions.
97 changes: 65 additions & 32 deletions doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,8 @@

# Copyright (c) 2011 Michael Morris-Pearce <[email protected]>
#
# A quick & dirty script for parsing annotated Javascript comments and building
# a representation of Objects and Mixins for output as documentation in any
# target format.
#
# How to use this script:
#
# (1) Install the python interpreter for your system.
# (2) Write a visitor (see HTMLVisitor below) for your output format.
# The script comes with an HTML generator. Change __main__ to output your
# new visitor's output instead of HTML.
# (3) Input your source through standard input.
# (4) Redirect standard output to a file.
#
# Example (UNIXish systems):
# cat source.js | ./doc.py > doc.html
# A quick & dirty script for parsing annotated Javascript comments on stdin and
# generating HTML documentation.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -37,24 +24,30 @@
############ Begin HTML generator ############

DOC_HTML_TARGETS = {
'docs/api/index.html': """
'docs/index.html': """
%(header)
%(index)
%(footer)
"""
, 'docs/api/all.html': """
, 'docs/all.html': """
%(header)
%(index-all)
%(overview)
%(everything)
%(footer)
"""
, 'docs/Overview.html': """
%(header)
%(overview)
%(footer)
"""
}

DOC_HTML_FRAGMENT = {
'header': open('docs/template/header.html', 'r').read()
, 'footer': open('docs/template/footer.html', 'r').read()
, 'index' : open('docs/template/index.html', 'r').read()
, 'index-all': open('docs/template/index-all.html', 'r').read()
, 'index-all': open('docs/template/index-all.html', 'r').read(), 'overview' : open('docs/template/overview.html', 'r').read()
}

DOC_HTML = {
Expand All @@ -63,8 +56,8 @@
"""
, 'object': '<article id="%(label)"> <h2 class="object"> %(label) <a class="link" href="#%(label)">#</a> %(inheritance) </h2> <p> %(description) </p> <p> %(contained) </p> </article>'
, 'inheritance': '<div class="inheritance"> inherits %(label) </div>'
, 'constructor': '<section> <h3 class="method"> Constructor </h3> %(contained) <div class="method_desc"> %(description) </div> </section>'
, 'method': '<section> <h3 class="method"> %(label) </h3> %(contained) <div class="method_desc"> %(description) </div> </section>'
, 'constructor': '<section id="%(constructor-link)"> <h3 class="method"> Constructor <a class="link" href="#%(constructor-link)">#</a> </h3> %(contained) <div class="method_desc"> %(description) </div> </section>'
, 'method': '<section id="%(method-link)"> <h3 class="method"> %(label) <a class="link" href="#%(method-link)">#</a> </h3> %(contained) <div class="method_desc"> %(description) </div> </section>'
, 'param': '<div> <span> &larr; %(label) </span> <span> %(description) </span> </div>'
, 'return': '<div class="return"> div class="return_type"> &rarr; %(label) </div> <div class="return_desc"> %(description) </div> </div>'
}
Expand All @@ -85,7 +78,9 @@ def s_visit(self, s):

# Parse special items
s = s.replace('%(classes)', build_html_classes())
s = s.replace('%(classes-detailed)', build_html_classes(True))
s = s.replace('%(mixins)', build_html_mixins())
s = s.replace('%(mixins-detailed)', build_html_mixins(True))
s = s.replace('%(everything)', self.o_visit(Everything()))

# Finally, filter/sanitize
Expand All @@ -110,30 +105,60 @@ def o_visit(self, o):
s = s.replace('%(description)', d)
s = s.replace('%(contained)', c)
s = s.replace('%(inheritance)', i)

if o.getType() == 'method':
s = s.replace('%(method-link)', o.parent.getLabel() + '-' + o.getName())
if o.getType() == 'constructor':
s = s.replace('%(constructor-link)', o.parent.getLabel() + '-Constructor')

return s

def build_html_targets():
template = open('docs/template/article.html', 'r').read()
for c in namespace['class'].values() + namespace['mixin'].values():
article = HTMLVisitor().o_visit(c)
target = 'docs/' + c.getLabel().split(':')[0] + '.html'
html = template.replace('%(article)', article)
DOC_HTML_TARGETS[target] = html

def output_html_targets():
for target in DOC_HTML_TARGETS.keys():
f = open(target, 'w')
template = DOC_HTML_TARGETS[target]
f.write(HTMLVisitor().s_visit(template))
f.close()

def build_html_classes():
def build_html_classes(detailed = False):
html = ''
for c in sorted(namespace['class'].values(),
lambda a,b: cmp(a.getLabel().lower(), b.getLabel().lower())):
l = c.getLabel().split(':')[0]
html += '<li><a href="#' + l + '">' + l + '</a></li>'
link = '#' + l if detailed else l + '.html'
html += '<li><a href="' + link + '">' + l + '</a>'
if detailed:
html += '<ul>'
for method in c.getMethods():
name = method.getName()
html += '<li><a href="#' + l + '-' + name + '" class="">' + name + '</a></li>'
html += '</ul>'

html += '</li>'

return html

def build_html_mixins():
def build_html_mixins(detailed = False):
html = ''
for m in sorted(namespace['mixin'].values(),
lambda a,b: cmp(a.getLabel().lower(), b.getLabel().lower())):
l = m.getLabel().split(':')[0]
html += '<li><a href="#' + l + '" class="content">' + l + '</a></li>'
link = '#' + l if detailed else l + '.html'
html += '<li><a href="' + link + '" class="content">' + l + '</a>'
if detailed:
html += '<ul>'
for method in m.getMethods():
name = method.getName()
html += '<li><a href="#' + l + '-' + name + '" class="">' + name + '</a></li>'
html += '</ul>'
html += '</li>'
return html

############ End HTML generator ############
Expand Down Expand Up @@ -222,14 +247,13 @@ def getType(self):
def getLabel(self):
output = self.label + '(' + ', '.join( \
[p.getLabel() for p in self.params]) + ')'
#if self.ret:
# output += ' --> ' + \
# self.ret.getLabel() if self.ret.getLabel() else 'void'
return output

def getContained(self):
return []
#return self.params

def getName(self):
return self.label

class Constructor(Method):
def getType(self):
Expand All @@ -240,6 +264,7 @@ def incorporate_annotation(self, a):
self.description = a[1] + a[2]
elif a[0] == 'param':
p = Param()
p.parent = self
p.incorporate_annotation(a)
self.params.append(p)

Expand All @@ -256,6 +281,7 @@ def __init__(self):
Visited.__init__(self)
self.constructor = None
self.inheritance = []
self.methods = {}

def incorporate_annotation(self, a):
global method_focus
Expand All @@ -270,16 +296,19 @@ def incorporate_annotation(self, a):
elif a[0] == 'method':
m = Method()
m.incorporate_annotation(a)
self.contained[a[1]] = m
m.parent = self
self.methods[a[1]] = m
method_focus = m
elif a[0] == 'constructor':
c = Constructor()
c.incorporate_annotation(a)
c.parent = self
self.constructor = c
method_focus = c
elif a[0] == 'extends':
i = Implements()
i.incorporate_annotation(a)
i.parent = self
self.inheritance.append(i)

def getInheritance(self):
Expand All @@ -289,10 +318,13 @@ def getType(self):
return 'object'

def getContained(self):
methods = sorted(self.contained.values(), \
lambda a,b: cmp(a.getLabel().lower(), b.getLabel().lower()))
methods = self.getMethods()
return [self.constructor] + methods if self.constructor else methods

def getMethods(self):
return sorted(self.methods.values(), \
lambda a,b: cmp(a.getLabel().lower(), b.getLabel().lower()))

def read_annotations(comment):
annots = [['preamble', '', '']]
for line in comment.splitlines():
Expand Down Expand Up @@ -349,4 +381,5 @@ def annotation_to_representation(a):
annotation_to_representation(a)

# Generate HTML on standard output
build_html_targets()
output_html_targets()
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 2 additions & 3 deletions docs/api/style.css → docs/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,10 @@ a:visited {
}
a.link {
float: right;
font-size: smaller;
text-decoration: none;
color: #ccc;
color: #888;
}
a.link:hover {
color: #f44;
color: #c22;
text-decoration: underline;
}
3 changes: 3 additions & 0 deletions docs/template/footer.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<br>
<br>
<br>
<script src="include/prettify.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
Expand Down
6 changes: 3 additions & 3 deletions docs/template/header.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<title>Meta2D API Documentation</title>
<title>Meta2D Documentation</title>
<link rel="stylesheet" href="style.css" type="text/css" />
<link rel="stylesheet" href="include/prettify.css" type="text/css" />
</head>
<body>

<h1>Meta2D API Documentation</h1>
<a href="index.html">Index</a>&nbsp;|&nbsp;<a href="all.html">Single page</a>
<h1>Meta2D Documentation</h1>
<a href="index.html">Index</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="all.html">Single page</a>
<hr>

7 changes: 5 additions & 2 deletions docs/template/index-all.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<h4>Table of Contents</h4>
<ul>
<li><a href="#Overview">Overview</a></li>
</ul>
<ul>
<li>Classes</li>
<ul>
%(classes)
%(classes-detailed)
</ul>
<li>Mixins</li>
<ul>
%(mixins)
%(mixins-detailed)
</ul>
</ul>
<hr>
3 changes: 3 additions & 0 deletions docs/template/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<h4>Table of Contents</h4>
<ul>
<li><a href="Overview.html">Overview</a></li>
</ul>
<ul>
<li>Classes</li>
<ul>
Expand Down
2 changes: 1 addition & 1 deletion rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ desc "Remove all generated files."
task :clean do
sh """
rm meta2d.js ;
rm docs/api/index.html ;
rm docs/*.html ;
"""
end

Expand Down
11 changes: 9 additions & 2 deletions src/metacontext.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@
w_ = w
h_ = h

if (!parent_) parent_ = document.createElement('ins')
if (!parent_) parent_ = document.createElement('div')

var style = canvas_ ?
'' :
Expand Down Expand Up @@ -504,6 +504,8 @@
}

var handle_click = function(event) {
event.stopPropagation()

var mouse = mouse_pos(event),
hits = this.pick.call(this, mouse[0], mouse[1], true, true)

Expand All @@ -513,9 +515,12 @@
if (!top.onclick) return

top.onclick.apply(top, mouse)

}

var handle_dblclick = function(event) {
event.stopPropagation()

var mouse = mouse_pos(event),
hits = this.pick.call(this, mouse[0], mouse[1], true, true)

Expand Down Expand Up @@ -589,11 +594,13 @@
if (focus_ && focus_.onfocus) {
handle_textinput_focus()
}

event.preventDefault()
}

var handle_mouseup = function(event) {
event.stopPropagation()

var mouse = mouse_pos(event),
hits = this.pick.call(this, mouse[0], mouse[1], true, true),
top
Expand Down

0 comments on commit 8c71ee7

Please sign in to comment.