This repository has been archived by the owner on Jun 7, 2024. It is now read-only.
forked from speced/respec
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request speced#217 from marcoscaceres/previousVersions
Previous versions (closes speced#215)
- Loading branch information
Showing
7 changed files
with
368 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
scratch | ||
.DS_Store | ||
*~ | ||
|
||
.htaccess |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<!DOCTYPE html> | ||
<html xmlns='http://www.w3.org/1999/xhtml'> | ||
<head> | ||
<meta charset='utf-8'/> | ||
<title>Basic ReSpec Evolution Example</title> | ||
<!-- // <script src='http://w3.dev/2009/dap/ReSpec.js/js/respec.js' class='remove'></script> --> | ||
<script src='../js/require.js' data-main='../js/profile-w3c-common' async class='remove'></script> | ||
<!-- // <script src='../builds/respec-w3c-common.js' async class='remove'></script> --> | ||
<!-- // <script src='//www.w3.org/Tools/respec/respec-w3c-common' async class='remove'></script> --> | ||
<!-- // <script src='http://darobin.github.com/respec/builds/respec-w3c-common.js' async class='remove'></script> --> | ||
<script class='remove'> | ||
var respecConfig = { | ||
specStatus: "ED" | ||
, shortName: "basics" | ||
, editors: [{ name: "Robin Berjon", url: "http://berjon.com/" }] | ||
, wg: "ReSpec Hackin' Gang" | ||
, wgURI: "http://darobin.github.com/respec" | ||
, wgPublicList: "none" | ||
, wgPatentURI: "XXX" | ||
, edDraftURI: "http://darobin.github.com/respec" | ||
, localBiblio: { | ||
"MEMES": "<a href='http://w3cmemes.tumblr.com/'>W3C Memes</a>", | ||
"REX": "<strong>Overridden!</strong>", | ||
"WEE": { | ||
title: "weee!", | ||
previousVersions: [{key: "TESTING", href: "http://test"}] | ||
} | ||
} | ||
}; | ||
</script> | ||
</head> | ||
<body> | ||
<section id='abstract'> | ||
<p> | ||
This is just a very basic document. [[!REX]] Yeah for memes [[MEMES]]. | ||
[[DOM4]], [[XML10]], [[\WHATEVER]], [[!DAHUT-TEST1]], | ||
[[!WEE]], | ||
[[!WEE-TESTING]], | ||
[[!DAHUT-TEST2]], | ||
[[!DAHUT-TEST3]], | ||
[[!DAHUT-TEST4]], | ||
[[!DAHUT-TEST5]], | ||
[[!DAHUT-TEST6]] | ||
|
||
</p> | ||
</section> | ||
<section id='sotd'> | ||
<p> | ||
CUSTOM PARAGRAPH | ||
</p> | ||
</section> | ||
<section> | ||
<h2>Name <a href='http://berjon.com/'>clashes</a> after <span>and <a href='http://w3.org/'>deep</a> stuff</span></h2> | ||
<p> | ||
Something MUST happen. | ||
</p> | ||
<p class='issue' title='A real problem'> | ||
This is a problem | ||
</p> | ||
<p class='note' title='About this'> | ||
Just a note | ||
</p> | ||
</section> | ||
<section> | ||
<h2>Clash here</h2> | ||
<dl class='idl' title='interface Dahut'> | ||
<dt>void other ()</dt> | ||
<dd> | ||
Partial would be better. | ||
</dd> | ||
</dl> | ||
</section> | ||
<section> | ||
<h2>Type Unions</h2> | ||
<section> | ||
<h2>Two</h2> | ||
<dl class="idl" title="interface MutableCapabilities : Capabilities"> | ||
<dt>(DOMString or sequence<long>) bar()</dt> | ||
<dd>without default</dd> | ||
<dt>void foo((unsigned long or sequence<unsigned long>) value1)</dt> | ||
<dd>without default</dd> | ||
<!-- <dt>void foo(boolean value1, DOMString other1)</dt> | ||
<dd>without default</dd> | ||
<dt>void bar(boolean value2 = true, DOMString other2)</dt> | ||
<dd>with default</dd> | ||
<dt>void bar(unsigned long value3 = 8.2, DOMString other3 = "something else")</dt> | ||
<dd>with default</dd> --> | ||
</dl> | ||
</section> | ||
</section> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/*jshint | ||
expr: true | ||
*/ | ||
// Module core/biblio/previous-versions | ||
// This module provides an object that finds "previousVersions" | ||
// properties in bibliographies and expands them so they can | ||
// be used in specifications. | ||
|
||
define([], function() { | ||
'use strict'; | ||
var prevVersionExpander = {}; | ||
|
||
function expandPrevVersions(bib, msg) { | ||
var props = Object.getOwnPropertyNames(bib); | ||
|
||
function hasPrevVersion(key) { | ||
var entry = bib[key], | ||
prop = 'previousVersions', | ||
isValid = !! entry[prop] && entry[prop] instanceof Array; | ||
if (isValid) { | ||
processPrevVersions(key, entry); | ||
} | ||
} | ||
|
||
function processPrevVersions(key, parentEntry) { | ||
parentEntry.previousVersions.forEach(function(prevObj, index) { | ||
var warning = '', | ||
newKey = key + '-' + prevObj['key']; | ||
|
||
if ((typeof prevObj) !== 'object') { | ||
warning = 'Expected Object, but got ' + (typeof prevObj) + '?'; | ||
warning += ' Please fix: ' + key + ' at index ' + index + '.'; | ||
msg('error', warning); | ||
return; | ||
} | ||
|
||
if (!prevObj.hasOwnProperty('key')) { | ||
warning = 'Previous versions require a key property. '; | ||
warning += 'Please fix: ' + key; | ||
msg('error', warning); | ||
return; | ||
} | ||
|
||
if (bib[newKey]) { | ||
warning = 'Previous version (' + newKey + ') already in biblio. '; | ||
warning += 'Please fix previousVersion key: ' + prevObj.key; | ||
msg('error', warning); | ||
return; | ||
} | ||
addPrevVersion(newKey, parentEntry, prevObj); | ||
}); | ||
} | ||
|
||
function addPrevVersion(newKey, parentEntry, prevObj) { | ||
var parentProps = Object.getOwnPropertyNames(parentEntry), | ||
newProps = Object.getOwnPropertyNames(prevObj), | ||
allProps = parentProps.concat(newProps).sort().filter(clean), | ||
newEntry = bib[newKey] = {}; | ||
|
||
//Don't add props to aliased entries, they are handeled by another plugin | ||
if (prevObj.hasOwnProperty('aliasOf')) { | ||
newEntry.aliasOf = prevObj.aliasOf; | ||
return; | ||
} | ||
allProps.forEach(function(prop) { | ||
var value = prevObj[prop] || parentEntry[prop]; | ||
this[prop] = value; | ||
}, newEntry); | ||
|
||
//remove duplicates, "previousVersions", and "key" prop | ||
|
||
function clean(elem, pos, self) { | ||
if (elem === 'previousVersions' || elem === 'key') { | ||
return false; | ||
} | ||
return self.lastIndexOf(elem) === pos; | ||
} | ||
} | ||
props.forEach(hasPrevVersion); | ||
} | ||
|
||
prevVersionExpander.run = function(conf, doc, cb, msg) { | ||
var biblio, | ||
props = { | ||
get: function() { | ||
return biblio; | ||
}, | ||
set: function(obj) { | ||
if ((typeof obj) === 'object') { | ||
biblio = obj; | ||
expandPrevVersions(obj, msg); | ||
} | ||
} | ||
}; | ||
msg.pub('start', 'core/biblio/previous-versions'); | ||
if (conf.localBiblio) { | ||
expandPrevVersions(conf.localBiblio, msg); | ||
} | ||
if (berjon.biblio) { | ||
expandPrevVersions(berjon.biblio, msg); | ||
} else { | ||
//we take over getting and setting of | ||
//berjon.biblio, so to dynamically | ||
//expand the biblio when loaded. | ||
Object.defineProperty(berjon, 'biblio', props); | ||
} | ||
msg.pub('end', 'core/fix-headers'); | ||
cb(); | ||
}; | ||
return prevVersionExpander; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
describe('Core — Definitions', function() { | ||
var MAXOUT = 5000, | ||
basicConfig = { | ||
editors: [{ | ||
name: 'Marcos Caceres' | ||
}], | ||
specStatus: 'WD', | ||
localBiblio: { | ||
'FOO': { | ||
title: 'TEST 7!', | ||
previousVersions: [{ | ||
key: 'TEST-7', | ||
href: 'http://test' | ||
}] | ||
} | ||
} | ||
}; | ||
|
||
it("expands 'previousVersions' props of DAHUT", function() { | ||
var doc; | ||
runs(function() { | ||
var body = '<section></section>'; | ||
makeRSDoc({ | ||
config: basicConfig, | ||
body: $(body) | ||
}, function(rsdoc) { | ||
doc = rsdoc; | ||
}); | ||
}); | ||
waitsFor(function() { | ||
return doc; | ||
}, MAXOUT); | ||
runs(function() { | ||
var iframe = document.querySelector('iframe'), | ||
biblio = iframe.contentWindow.berjon.biblio, | ||
dahut = biblio.DAHUT; | ||
|
||
var test1 = biblio['DAHUT-TEST1']; | ||
expect(test1.authors[0]).toEqual(dahut.authors[0]); | ||
expect(test1.etAl).toEqual(dahut.etAl); | ||
expect(test1.title).toEqual(dahut.title); | ||
expect(test1.date).toEqual(dahut.date); | ||
expect(test1.status).toEqual(dahut.status); | ||
expect(test1.href).toEqual(dahut.href); | ||
|
||
var test2 = biblio['DAHUT-TEST2']; | ||
expect(test2.authors[0]).toEqual(dahut.authors[0]); | ||
expect(test2.etAl).toEqual(true); | ||
expect(test2.title).toEqual(dahut.title); | ||
expect(test2.date).toEqual(dahut.date); | ||
expect(test2.status).toEqual(dahut.status); | ||
expect(test2.href).toEqual('http://test.com'); | ||
|
||
var test3 = biblio['DAHUT-TEST3']; | ||
expect(test3.authors[0]).toEqual(dahut.authors[0]); | ||
expect(test3.etAl).toEqual(true); | ||
expect(test3.title).toEqual('test title'); | ||
expect(test3.date).toEqual('test date'); | ||
expect(test3.status).toEqual('test status'); | ||
expect(test3.href).toEqual(dahut.href); | ||
|
||
var test4 = biblio['DAHUT-TEST4']; | ||
expect(test4.authors[0]).toEqual('Test Author 1'); | ||
expect(test4.authors[1]).toEqual('Test Author 2'); | ||
expect(test4.etAl).toEqual(true); | ||
expect(test4.title).toEqual(dahut.title); | ||
expect(test4.date).toEqual(dahut.date); | ||
expect(test4.status).toEqual(dahut.status); | ||
expect(test4.href).toEqual(dahut.href); | ||
|
||
var test5 = biblio['DAHUT-TEST5'], | ||
props = Object.getOwnPropertyNames(test5); | ||
expect(props.length).toEqual(1); | ||
expect(props[0]).toEqual('aliasOf'); | ||
expect(test5['aliasOf']).toEqual('DC11'); | ||
flushIframes(); | ||
}); | ||
}); | ||
|
||
it('should display previousVersions', function() { | ||
var doc; | ||
runs(function() { | ||
var body = '<section>[[!DAHUT-TEST1]],[[!DAHUT-TEST2]],'; | ||
body += '[[!DAHUT-TEST3]],[[!DAHUT-TEST4]],[[!DAHUT-TEST5]],'; | ||
body += '[[!DAHUT-TEST6]],[[!FOO]],[[!FOO-TEST7]]</section>'; | ||
makeRSDoc({ | ||
config: basicConfig, | ||
body: $(body) | ||
}, function(rsdoc) { | ||
doc = rsdoc; | ||
}); | ||
}); | ||
waitsFor(function() { | ||
return doc; | ||
}, MAXOUT); | ||
runs(function() { | ||
var test, query, content, i; | ||
//id checks | ||
for (i = 1; i <= 6; i++) { | ||
test = 'bib-DAHUT-TEST' + i, | ||
query = '#' + test; | ||
expect(doc.querySelector(query).id).toEqual(test); | ||
} | ||
expect(doc.querySelector('#bib-FOO', doc).id).toEqual('bib-FOO'); | ||
expect(doc.querySelector('#bib-FOO-TEST7').id).toEqual('bib-FOO-TEST7'); | ||
//text content check | ||
for (i = 1; i <= 6; i++) { | ||
test = 'DAHUT-TEST' + i, | ||
query = '#bib-' + test, | ||
content = '[' + test + ']'; | ||
expect(doc.querySelector(query).textContent).toEqual(content); | ||
} | ||
content = doc.querySelector('#bib-FOO').textContent; | ||
expect(content).toEqual('[FOO]'); | ||
content = doc.querySelector('#bib-FOO-TEST7').textContent; | ||
expect(content).toEqual('[FOO-TEST7]'); | ||
flushIframes(); | ||
}); | ||
}); | ||
}); |