Skip to content
This repository has been archived by the owner on Jan 9, 2021. It is now read-only.

Commit

Permalink
Replace Figure 1 with a canned image.
Browse files Browse the repository at this point in the history
  • Loading branch information
jorendorff committed Mar 4, 2012
1 parent 59d4a09 commit c29c4f2
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 29 deletions.
30 changes: 4 additions & 26 deletions es6-draft.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Binary file added figure-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
77 changes: 77 additions & 0 deletions figure-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions fixups.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'):
Expand Down Expand Up @@ -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
7 changes: 4 additions & 3 deletions htmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()}
Expand Down

0 comments on commit c29c4f2

Please sign in to comment.