Skip to content
This repository has been archived by the owner on Jun 7, 2024. It is now read-only.

Commit

Permalink
Merge pull request speced#217 from marcoscaceres/previousVersions
Browse files Browse the repository at this point in the history
Previous versions (closes speced#215)
  • Loading branch information
darobin committed May 7, 2013
2 parents e0cbf40 + b6729c4 commit 347c25a
Show file tree
Hide file tree
Showing 7 changed files with 368 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
scratch
.DS_Store
*~

.htaccess
42 changes: 41 additions & 1 deletion bibref/biblio.js
Original file line number Diff line number Diff line change
Expand Up @@ -1307,7 +1307,47 @@ berjon.biblio = {
"publisher": "W3C"
},
"DAHU": { "aliasOf": "DAHUT" },
"DAHUT": "Robin Berjon; et al. <cite>The Dahut Specification Example From the Higher Circle.</cite> 15 March 1977. Lazy Daft. (Work for progress.) URL: <a href='http://berjon.com/'>http://berjon.com/</a>",
"DAHUT": {
"authors": [
"Robin Berjon"
],
"etAl": true,
"title": "The Dahut Specification Example From the Higher Circle",
"date": "15 March 1977",
"status": "Lazy Daft (Work for progress)",
"href": "http://berjon.com/",
"previousVersions": [
{
"key": "TEST1"
},
{
"key": "TEST2",
"href": "http://test.com"
},
{
"key": "TEST3",
"etAl": true,
"title": "test title",
"date": "test date",
"status": "test status"
},
{
"key": "TEST4",
"etAl": false,
"authors": [
"Test Author 1", "Test Author 2"
]
},
{
"key": "TEST5",
"aliasOf": "DC11"
},
{
"key": "TEST6",
"aliasOf": "DAHU"
}
]
},
"DAP-ACCESS-REQS": "L. Arribas, P. Byers, M. Hanclik, F Hirsch, D. Rogers. <a href=\"http://dev.w3.org/2009/dap/policy-reqs/\"><cite>Device API Access Control Requirements</cite></a> 17 June 2010. (Work in progress.) URL: <a href=\"http://dev.w3.org/2009/dap/policy-reqs/\">http://dev.w3.org/2009/dap/policy-reqs/</a> ",
"DAP-POLICY-FRAMEWORK": "L. Arribas, P. Byers, M. Hanclik, F Hirsch, D. Rogers. <a href=\"http://dev.w3.org/2009/dap/policy/Framework.html\"><cite>Device API Policy Framework.</cite></a> 17 June 2010. (Work in progress.) URL: <a href=\"http://dev.w3.org/2009/dap/policy/Framework.html\">http://dev.w3.org/2009/dap/policy/Framework.html</a> ",
"DAP-PRIVACY-POSITION": "Frederick Hirsch, Robin Berjon. <a href=\"http://www.w3.org/2010/policy-ws/papers/14-Hirsch-Berjon-DAP.html\"><cite>Position Paper: Privacy and Policy in the DAP WG - A DAP Perspective</cite></a>. 2 September 2010. URL: <a href=\"http://www.w3.org/2010/policy-ws/papers/14-Hirsch-Berjon-DAP.html\">http://www.w3.org/2010/policy-ws/papers/14-Hirsch-Berjon-DAP.html</a> (<a href=\"http://www.w3.org/2010/policy-ws/\">W3C Workshop on Privacy and Data Usage Control</a>.)",
Expand Down
92 changes: 92 additions & 0 deletions examples/previousVersions.html
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&lt;long>) bar()</dt>
<dd>without default</dd>
<dt>void foo((unsigned long or sequence&lt;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>
111 changes: 111 additions & 0 deletions js/core/biblio/previous-versions.js
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;
});
1 change: 1 addition & 0 deletions js/profile-w3c-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ define([
, "core/base-runner"
, "core/override-configuration"
, "core/default-root-attr"
, "core/biblio/previous-versions"
// , "core/local-biblio"
, "core/markdown"
, "core/style"
Expand Down
1 change: 1 addition & 0 deletions tests/SpecRunner.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

<!-- SPECS -->
<script src="spec/SpecHelper.js"></script>
<script src="spec/core/biblio/previous-versions-spec.js"></script>
<script src="spec/core/default-root-attr-spec.js"></script>
<script src="spec/core/style-spec.js"></script>
<script src="spec/core/override-configuration-spec.js"></script>
Expand Down
120 changes: 120 additions & 0 deletions tests/spec/core/biblio/previous-versions-spec.js
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();
});
});
});

0 comments on commit 347c25a

Please sign in to comment.