Skip to content

Commit a4a3ec4

Browse files
committed
Update to v1.2.0 of shiv code
1 parent d11fc3f commit a4a3ec4

File tree

130 files changed

+411
-429
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+411
-429
lines changed

lib/index.js

Lines changed: 140 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
microformat-node - v1.0.0
3-
Built: 2015-09-08 09:09 -
2+
microformat-node - v1.1.0
3+
Built: 2015-09-14 03:09 -
44
Copyright (c) 2015 Glenn Jones
55
Licensed MIT
66
*/
@@ -11,8 +11,8 @@ var cheerio = require('cheerio'),
1111
Promise = require('bluebird');
1212

1313
var Modules = (function (modules) {
14-
modules.version = '1.0.0';
15-
modules.livingStandard = '2015-08-20T13:50:36Z';
14+
modules.version = '1.1.0';
15+
modules.livingStandard = '2015-09-09T14:47:13Z';
1616

1717
/**
1818
* constructor
@@ -39,9 +39,9 @@ var Modules = (function (modules) {
3939
'baseUrl': '',
4040
'filters': [],
4141
'textFormat': 'whitespacetrimmed',
42-
'dateFormat': 'auto',
43-
'overlappingVersions': true,
44-
'impliedPropertiesByVersion': false,
42+
'dateFormat': 'auto', // html5 for testing
43+
'overlappingVersions': false,
44+
'impliedPropertiesByVersion': true,
4545
'parseLatLonGeo': false
4646
};
4747
this.rootID = 0;
@@ -131,6 +131,139 @@ var Modules = (function (modules) {
131131
},
132132

133133

134+
/**
135+
* get the count of microformats
136+
*
137+
* @param {DOM Node} rootNode
138+
* @return {Int}
139+
*/
140+
count: function( options ) {
141+
var out = {},
142+
items,
143+
classItems,
144+
x,
145+
i;
146+
147+
this.init();
148+
options = (options)? options : {};
149+
this.getDOMContext( options );
150+
151+
// if we do not have any context create error
152+
if(!this.rootNode || !this.document){
153+
return {'errors': [this.noContentErr]};
154+
}else{
155+
156+
items = this.findRootNodes( this.rootNode, true );
157+
i = items.length;
158+
while(i--) {
159+
classItems = modules.domUtils.getAttributeList(items[i], 'class');
160+
x = classItems.length;
161+
while(x--) {
162+
// find v2 names
163+
if(modules.utils.startWith( classItems[x], 'h-' )){
164+
this.appendCount(classItems[x], 1, out);
165+
}
166+
// find v1 names
167+
for(var key in modules.maps) {
168+
// has v1 root but not also a v2 root so we dont double count
169+
if(modules.maps[key].root === classItems[x] && classItems.indexOf(key) === -1) {
170+
this.appendCount(key, 1, out);
171+
}
172+
}
173+
}
174+
}
175+
var relCount = this.countRels( this.rootNode );
176+
if(relCount > 0){
177+
out.rels = relCount;
178+
}
179+
180+
return out;
181+
}
182+
},
183+
184+
185+
/**
186+
* does a node have a class that marks it as a microformats root
187+
*
188+
* @param {DOM Node} node
189+
* @param {Objecte} options
190+
* @return {Boolean}
191+
*/
192+
isMicroformat: function( node, options ) {
193+
var classes,
194+
i;
195+
196+
if(!node){
197+
return false;
198+
}
199+
200+
// if documemt get topmost node
201+
node = modules.domUtils.getTopMostNode( node );
202+
203+
// look for h-* microformats
204+
classes = this.getUfClassNames(node);
205+
if(options && options.filters && modules.utils.isArray(options.filters)){
206+
i = options.filters.length;
207+
while(i--) {
208+
if(classes.root.indexOf(options.filters[i]) > -1){
209+
return true;
210+
}
211+
}
212+
return false;
213+
}else{
214+
return (classes.root.length > 0);
215+
}
216+
},
217+
218+
219+
/**
220+
* does a node or its children have microformats
221+
*
222+
* @param {DOM Node} node
223+
* @param {Objecte} options
224+
* @return {Boolean}
225+
*/
226+
hasMicroformats: function( node, options ) {
227+
var items,
228+
i;
229+
230+
if(!node){
231+
return false;
232+
}
233+
234+
// if browser based documemt get topmost node
235+
node = modules.domUtils.getTopMostNode( node );
236+
237+
// returns all microformats roots
238+
items = this.findRootNodes( node, true );
239+
if(options && options.filters && modules.utils.isArray(options.filters)){
240+
i = items.length;
241+
while(i--) {
242+
if( this.isMicroformat( items[i], options ) ){
243+
return true;
244+
}
245+
}
246+
return false;
247+
}else{
248+
return (items.length > 0);
249+
}
250+
},
251+
252+
253+
/**
254+
* add a new V1 mapping object to parser
255+
*
256+
* @param {Array} maps
257+
*/
258+
add: function( maps ){
259+
maps.forEach(function(map){
260+
if(map && map.root && map.name && map.properties){
261+
modules.maps[map.name] = JSON.parse(JSON.stringify(map));
262+
}
263+
});
264+
},
265+
266+
134267
/**
135268
* internal parse to get parent microformat by walking up the tree
136269
*
@@ -253,20 +386,6 @@ var Modules = (function (modules) {
253386
},
254387

255388

256-
/**
257-
* add a new V1 mapping object to parser
258-
*
259-
* @param {Array} maps
260-
*/
261-
add: function( maps ){
262-
maps.forEach(function(map){
263-
if(map && map.root && map.name && map.properties){
264-
modules.maps[map.name] = JSON.parse(JSON.stringify(map));
265-
}
266-
});
267-
},
268-
269-
270389
// find uf's of a given type and return a dom and node structure of just that type of ufs
271390
findFilterNodes: function(rootNode, filters) {
272391
var newRootNode = modules.domUtils.createNode('div'),
@@ -303,57 +422,6 @@ var Modules = (function (modules) {
303422
},
304423

305424

306-
/**
307-
* get the count of microformats
308-
*
309-
* @param {DOM Node} rootNode
310-
* @return {Int}
311-
*/
312-
count: function( options ) {
313-
var out = {},
314-
items,
315-
classItems,
316-
x,
317-
i;
318-
319-
this.init();
320-
options = (options)? options : {};
321-
this.getDOMContext( options );
322-
323-
// if we do not have any context create error
324-
if(!this.rootNode || !this.document){
325-
return {'errors': [this.noContentErr]};
326-
}else{
327-
328-
items = this.findRootNodes( this.rootNode, true );
329-
i = items.length;
330-
while(i--) {
331-
classItems = modules.domUtils.getAttributeList(items[i], 'class');
332-
x = classItems.length;
333-
while(x--) {
334-
// find v2 names
335-
if(modules.utils.startWith( classItems[x], 'h-' )){
336-
this.appendCount(classItems[x], 1, out);
337-
}
338-
// find v1 names
339-
for(var key in modules.maps) {
340-
// has v1 root but not also a v2 root so we dont double count
341-
if(modules.maps[key].root === classItems[x] && classItems.indexOf(key) === -1) {
342-
this.appendCount(key, 1, out);
343-
}
344-
}
345-
}
346-
}
347-
var relCount = this.countRels( this.rootNode );
348-
if(relCount > 0){
349-
out.rels = relCount;
350-
}
351-
352-
return out;
353-
}
354-
},
355-
356-
357425
/**
358426
* appends data to output object for count
359427
*
@@ -368,84 +436,8 @@ var Modules = (function (modules) {
368436
out[name] = count;
369437
}
370438
},
371-
372-
373-
374-
/**
375-
* does a node have a class that marks it as a microformats root
376-
*
377-
* @param {DOM Node} node
378-
* @param {Objecte} options
379-
* @return {Boolean}
380-
*/
381-
isMicroformat: function( node, options ) {
382-
var classes,
383-
i;
384-
385-
if(!node){
386-
return false;
387-
}
388-
389-
// if documemt get topmost node
390-
node = modules.domUtils.getTopMostNode( node );
391-
//if(node.nodeType && node.nodeType === 9){
392-
// node = modules.domUtils.querySelector(node, 'html');
393-
//}
394-
395-
// look for h-* microformats
396-
classes = this.getUfClassNames(node);
397-
if(options && options.filters && modules.utils.isArray(options.filters)){
398-
i = options.filters.length;
399-
while(i--) {
400-
if(classes.root.indexOf(options.filters[i]) > -1){
401-
return true;
402-
}
403-
}
404-
return false;
405-
}else{
406-
return (classes.root.length > 0);
407-
}
408-
},
409-
410-
411-
/**
412-
* does a node or its children have microformats
413-
*
414-
* @param {DOM Node} node
415-
* @param {Objecte} options
416-
* @return {Boolean}
417-
*/
418-
hasMicroformats: function( node, options ) {
419-
var items,
420-
i;
421-
422-
if(!node){
423-
return false;
424-
}
425439

426440

427-
// if browser based documemt get topmost node
428-
node = modules.domUtils.getTopMostNode( node );
429-
//if(node.nodeType && node.nodeType === 9){
430-
// node = modules.domUtils.querySelector(node, 'html');
431-
//}
432-
433-
// returns all microformats roots
434-
items = this.findRootNodes( node, true );
435-
if(options && options.filters && modules.utils.isArray(options.filters)){
436-
i = items.length;
437-
while(i--) {
438-
if( this.isMicroformat( items[i], options ) ){
439-
return true;
440-
}
441-
}
442-
return false;
443-
}else{
444-
return (items.length > 0);
445-
}
446-
},
447-
448-
449441
/**
450442
* is the microformats type in the filter list
451443
*

lib/version.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
modules.version = '1.0.0';
1+
modules.version = '1.1.0';

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"author": "Glenn Jones",
33
"name": "microformat-node",
44
"description": "A microformat parser for node.js",
5-
"version": "1.0.1",
5+
"version": "1.1.0",
66
"license": "MIT",
77
"keywords": [
88
"parser",
@@ -31,7 +31,7 @@
3131
"dependencies": {
3232
"cheerio": "0.19.x",
3333
"bluebird": "2.9.x",
34-
"microformat-shiv": "1.0.x"
34+
"microformat-shiv": "https://api.github.com/repos/glennjones/microformat-shiv/tarball/"
3535
},
3636
"devDependencies": {
3737
"hapi": "8.4.x",

static/javascript/data.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

static/javascript/testrunner.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77

88
var options = {
99
'baseUrl': 'http://example.com',
10-
'overlappingVersions': true,
11-
'impliedPropertiesByVersion': false,
10+
'dateFormat': 'html5',
1211
'parseLatLonGeo': false
1312
};
1413

test/helper.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ function parseHTML(html, baseUrl){
99
options = {
1010
'html': html,
1111
'baseUrl': baseUrl,
12-
'overlappingVersions': false,
13-
'impliedPropertiesByVersion': true
12+
'dateFormat': 'html5'
1413
};
1514

1615
return Microformats.get(options);

test/interface-count-test.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ var cheerio = require('cheerio');
99

1010

1111
var options = {
12-
'baseUrl': 'http://example.com/',
13-
'overlappingVersions': false,
14-
'impliedPropertiesByVersion': true
12+
'baseUrl': 'http://example.com/'
1513
},
1614
result;
1715

0 commit comments

Comments
 (0)