Permalink
Browse files

Replace Figure 1 with a canned image.

  • Loading branch information...
jorendorff committed Mar 4, 2012
1 parent 59d4a09 commit c29c4f25d496916153154f807d9f211a441fa334
Showing with 129 additions and 29 deletions.
  1. +4 −26 es6-draft.html
  2. BIN figure-1.png
  3. +77 −0 figure-1.svg
  4. +41 −0 fixups.py
  5. +4 −3 htmodel.py
  6. +3 −0 transform.py
View
@@ -552,32 +552,10 @@ <h1><span class="secnum"><a href="#sec-4.2" title="link to this section">4.2</a>
<h1><span class="secnum"><a href="#sec-4.2.1" title="link to this section">4.2.1</a></span> Objects</h1>
<p>ECMAScript does not use classes such as those in C++, Smalltalk, or Java. Instead objects may be created in various ways including via a literal notation or via <span style="font-style: italic; font-weight: bold">constructors</span> which create objects and then execute code that initialises all or part of them by assigning initial values to their properties. Each constructor is a function that has a property named &ldquo;<code>prototype</code>&rdquo; that is used to implement <span style="font-style: italic; font-weight: bold">prototype-based inheritance</span> and <span style="font-style: italic; font-weight: bold">shared properties</span>. Objects are created by using constructors in <b>new</b> expressions; for example, <code>new Date(2009,11)</code> creates a new Date object. Invoking a constructor without using <b>new</b> has consequences that depend on the constructor. For example, <code>Date()</code> produces a string representation of the current date and time rather than an object.</p>
<p>Every object created by a constructor has an implicit reference (called the object&rsquo;s <i>prototype</i>) to the value of its constructor&rsquo;s &ldquo;<code>prototype</code>&rdquo; property. Furthermore, a prototype may have a non-null implicit reference to its prototype, and so on; this is called the <i>prototype chain</i>. When a reference is made to a property in an object, that reference is to the property of that name in the first object in the prototype chain that contains a property of that name. In other words, first the object mentioned directly is examined for such a property; if that object contains the named property, that is the property to which the reference refers; if that object does not contain the named property, the prototype for that object is examined next; and so on.</p>
-<p>
- <p><b>cf<sub>5</sub></b></p>
- <p><span style="font-family: monospace">q1</span></p>
- <p><span style="font-family: monospace">q2</span></p>
- <p><b>cf<sub>4</sub></b></p>
- <p><span style="font-family: monospace">q1</span></p>
- <p><span style="font-family: monospace">q2</span></p>
- <p><b>cf<sub>3</sub></b></p>
- <p><span style="font-family: monospace">q1</span></p>
- <p><span style="font-family: monospace">q2</span></p>
- <p><b>CF<sub>p</sub></b></p>
- <p><span style="font-family: monospace">CFP1</span></p>
- <p><b>CF</b></p>
- <p><span style="font-family: monospace">prototype</span></p>
- <p><span style="font-family: monospace">P1</span></p>
- <p><span style="font-family: monospace">P2</span></p>
- <p><b>cf<sub>1</sub></b></p>
- <p><span style="font-family: monospace">q1</span></p>
- <p><span style="font-family: monospace">q2</span></p>
- <p><b>cf<sub>2</sub></b></p>
- <p><span style="font-family: monospace">q1</span></p>
- <p><span style="font-family: monospace">q2</span></p>
- <p>implicit prototype link</p>
- <p>explicit prototype property</p>
-</p>
-<figcaption>Figure 1 &mdash; Object/Prototype Relationships</figcaption>
+<figure>
+ <object width="719" type="image/svg+xml" data="figure-1.svg" height="354"><img src="figure-1.png" alt="An image of lots of boxes and arrows." height="354" width="719"></img></object>
+ <figcaption>Figure 1 &mdash; Object/Prototype Relationships</figcaption>
+</figure>
<p>In a class-based object-oriented language, in general, state is carried by instances, methods are carried by classes, and inheritance is only of structure and behaviour. In ECMAScript, the state and methods are carried by objects, and structure, behaviour, and state are all inherited.</p>
<p>All objects that do not directly contain a particular property that their prototype contains share that property and its value. Figure 1 illustrates this:</p>
<p><b>CF</b> is a constructor (and also an object). Five objects have been created by using <code>new</code> expressions: <b>cf<sub>1</sub></b>, <b>cf<sub>2</sub></b>, <b>cf<sub>3</sub></b>, <b>cf<sub>4</sub></b>, and <b>cf<sub>5</sub></b>. Each of these objects contains properties named <span style="font-family: monospace">q1</span> and <span style="font-family: monospace">q2</span>. The dashed lines represent the implicit prototype relationship; so, for example, <b>cf<sub>3</sub></b>&rsquo;s prototype is <b>CF<sub>p</sub></b>. The constructor, <b>CF</b>, has two properties itself, named <span style="font-family: monospace">P1</span> and <span style="font-family: monospace">P2</span>, which are not visible to <b>CF<sub>p</sub></b>, <b>cf<sub>1</sub></b>, <b>cf<sub>2</sub></b>, <b>cf<sub>3</sub></b>, <b>cf<sub>4</sub></b>, or <b>cf<sub>5</sub></b>. The property named <span style="font-family: monospace">CFP1</span> in <b>CF<sub>p</sub></b> is shared by <b>cf<sub>1</sub></b>, <b>cf<sub>2</sub></b>, <b>cf<sub>3</sub></b>, <b>cf<sub>4</sub></b>, and <b>cf<sub>5</sub></b> (but not by <b>CF</b>), as are any properties found in <b>CF<sub>p</sub></b>&rsquo;s implicit prototype chain that are not named <span style="font-family: monospace">q1</span>, <span style="font-family: monospace">q2</span>, or <span style="font-family: monospace">CFP1</span>. Notice that there is no implicit prototype link between <b>CF</b> and <b>CF<sub>p</sub></b>.</p>
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -0,0 +1,77 @@
+<?xml version="1.0"?>
+<svg xmlns="http://www.w3.org/2000/svg"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ width="719" height="354">
+ <style type="text/css">
+ rect.box {
+ fill: white;
+ stroke: black;
+ stroke-width: 1px;
+ }
+ path.a {
+ fill: none;
+ stroke: black;
+ stroke-width: 2px;
+ marker-end: url(#arrowhead);
+ }
+ path.d { stroke-dasharray: 2,2; }
+ text { font-family: Helvetica, Arial, Liberation Sans, sans-serif; }
+ text.pn { font-family: "Courier New", monospace; }
+ text.on { font-weight: bold; }
+ text.ons { font-weight: bold; font-size: 60%; }
+ </style>
+ <defs>
+ <marker id="arrowhead" viewBox="0 0 15 10" refX="0" refY="5"
+ markerUnits="userSpaceOnUse" markerWidth="9" markerHeight="6"
+ orient="auto">
+ <path d="M 0 0 L 15 5 L 0 10 z" />
+ </marker>
+ <g id="instance" width="50" height="101">
+ <rect class="box" x=".5" y=".5" width="49" height="100" />
+ <text class="pn" x="14" y="56">q1</text>
+ <text class="pn" x="14" y="79">q2</text>
+ <text class="on" x="10" y="22">cf</text>
+ </g>
+ </defs>
+ <g font-size="14.5">
+ <rect class="box" x="0.5" y="0.5" width="718" height="353" />
+ <!-- legend -->
+ <path class="a d" d="M 457,25 616,25" />
+ <text x="470" y="51" font-size="13.5">implicit prototype link</text>
+ <path class="a s" d="M 456,80 616,80" />
+ <text x="469" y="106" font-size="12.5">explicit prototype property</text>
+
+ <!-- CF -->
+ <rect class="box" x="80.5" y="25.5" width="144" height="117" />
+ <text x="89" y="57" font-weight="bold">CF</text>
+ <path class="a d" d="M 80,37 42,37 42,23" />
+ <text class="pn" x="95" y="75">prototype</text>
+ <text class="pn" x="95" y="96">P1</text>
+ <text class="pn" x="95" y="117">P2</text>
+ <path class="a s" d="M 175,70 260,70" />
+
+ <!-- CFp -->
+ <rect class="box" x="268.5" y="59.5" width="79" height="88" />
+ <path class="a d" d="M 348,81 380,81 380,23" />
+ <text class="on" x="283" y="79">CF</text>
+ <text class="ons" x="304" y="81">p</text>
+ <text class="pn" x="287" y="113">CFP1</text>
+
+ <!-- instances -->
+ <use xlink:href="#instance" x="79" y="240" />
+ <text class="ons" x="103" y="264">1</text>
+ <path class="a d" d="M 79,249 45,249 45,194 270,194 270,155" />
+ <use xlink:href="#instance" x="184" y="240" />
+ <text class="ons" x="208" y="264">2</text>
+ <path class="a d" d="M 184,246 160,246 160,208 281,208 281,155" />
+ <use xlink:href="#instance" x="290" y="240" />
+ <text class="ons" x="314" y="264">3</text>
+ <path class="a d" d="M 305,240 305,155" />
+ <use xlink:href="#instance" x="396" y="240" />
+ <text class="ons" x="420" y="264">4</text>
+ <path class="a d" d="M 447,250 469,250 469,207 333,207 333,155" />
+ <use xlink:href="#instance" x="502" y="240" />
+ <text class="ons" x="526" y="264">5</text>
+ <path class="a d" d="M 553,251 579,251 579,197 346,197 346,155" />
+ </g>
+</svg>
View
@@ -686,6 +686,46 @@ def fixup_tables(doc):
td.name = 'th'
del span.style['background-color']
+def fixup_picts(doc):
+ """ Replace Figure 1 with canned HTML. Remove div.w-pict elements. """
+ def walk(e):
+ i = 0
+ while i < len(e.content):
+ child = e.content[i]
+ if isinstance(child, str):
+ i += 1
+ elif child.name == 'div' and child.attrs.get('class') == 'w-pict':
+ # Remove the div element, but retain its contents.
+ e.content[i:i + 1] = child.content
+ elif (child.name == 'p'
+ and len(child.content) == 1
+ and ht_name_is(child.content[0], "div")
+ and child.content[0].attrs.get('class') == 'w-pict'):
+ pict = child.content[0]
+ print("GOT HERE")
+ print(e.to_html())
+ is_figure_1 = False
+ if i + 1 < len(e.content):
+ caption = e.content[i + 1]
+ print("CAPTION IS:", caption if isinstance(caption, str) else caption.to_html())
+ if ht_name_is(caption, 'figcaption') and caption.content and caption.content[0].startswith('Figure 1'):
+ is_figure_1 = True
+
+ if is_figure_1:
+ image = html.object(
+ html.img(src="figure-1.png", width="719", height="354", alt="An image of lots of boxes and arrows."),
+ type="image/svg+xml", width="719", height="354", data="figure-1.svg")
+ del e.content[i + 1]
+ e.content[i] = html.figure(image, caption)
+ else:
+ # Remove the div element, but retain its contents.
+ e.content[i:i + 1] = pict.content
+ else:
+ walk(child)
+ i += 1
+
+ walk(doc)
+
def fixup_figures(doc):
for parent, i, child in all_parent_index_child_triples(doc):
if child.name == 'figcaption' and i + 1 < len(parent.content) and ht_name_is(parent.content[i + 1], 'figure'):
@@ -776,6 +816,7 @@ def fixup(doc, styles):
fixup_lists(doc)
fixup_grammar(doc)
fixup_tables(doc)
+ fixup_picts(doc)
fixup_figures(doc)
fixup_links(doc)
return doc
View
@@ -33,7 +33,7 @@ def kids(self, name=None):
_spaceable_tags = set('html head title base link meta style '
'table caption colgroup col tbody thead tfoot tr td th '
'body section nav article aside h1 h2 h3 h4 h5 h6 header footer '
- 'p hr pre blockquote ol ul li dl dt dd figure figcaption div '.split())
+ 'p hr pre blockquote ol ul li dl dt dd figure figcaption object div '.split())
def is_spaceable(ht):
return not isinstance(ht, str) and ht.name in _spaceable_tags
@@ -134,11 +134,12 @@ def construct(*content, **attrs):
return construct
names = ('html head title base link meta style script noscript '
- 'table caption colgroup col tbody thead tfoot tr td th '
'body section nav article aside h1 h2 h3 h4 h5 h6 hgroup header footer address '
'p hr pre blockquote ol ul li dl dt dd figure figcaption div '
'a em strong small s cite q dfn abbr data time code var '
- 'samp kbd sub sup i b u mark ruby rt rp bdi bdo span br wbr').split()
+ 'samp kbd sub sup i b u mark ruby rt rp bdi bdo span br wbr '
+ 'img iframe embed object param video audio source track canvas map area '
+ 'table caption colgroup col tbody thead tfoot tr td th').split()
for name in names:
v[name] = element_constructor(name)
View
@@ -88,6 +88,9 @@ def add(ht):
result.style = css
return result
+ elif name == 'pict':
+ return div(*c, class_='w-pict')
+
elif name == 'sym':
assert not c
attrs = {shorten(k): v for k, v in e.items()}

0 comments on commit c29c4f2

Please sign in to comment.