Skip to content

Commit

Permalink
Update to v1.2.0 of shiv code
Browse files Browse the repository at this point in the history
  • Loading branch information
glennjones committed Sep 14, 2015
1 parent d11fc3f commit a4a3ec4
Show file tree
Hide file tree
Showing 130 changed files with 411 additions and 429 deletions.
288 changes: 140 additions & 148 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
microformat-node - v1.0.0
Built: 2015-09-08 09:09 -
microformat-node - v1.1.0
Built: 2015-09-14 03:09 -
Copyright (c) 2015 Glenn Jones
Licensed MIT
*/
Expand All @@ -11,8 +11,8 @@ var cheerio = require('cheerio'),
Promise = require('bluebird');

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

/**
* constructor
Expand All @@ -39,9 +39,9 @@ var Modules = (function (modules) {
'baseUrl': '',
'filters': [],
'textFormat': 'whitespacetrimmed',
'dateFormat': 'auto',
'overlappingVersions': true,
'impliedPropertiesByVersion': false,
'dateFormat': 'auto', // html5 for testing
'overlappingVersions': false,
'impliedPropertiesByVersion': true,
'parseLatLonGeo': false
};
this.rootID = 0;
Expand Down Expand Up @@ -131,6 +131,139 @@ var Modules = (function (modules) {
},


/**
* get the count of microformats
*
* @param {DOM Node} rootNode
* @return {Int}
*/
count: function( options ) {
var out = {},
items,
classItems,
x,
i;

this.init();
options = (options)? options : {};
this.getDOMContext( options );

// if we do not have any context create error
if(!this.rootNode || !this.document){
return {'errors': [this.noContentErr]};
}else{

items = this.findRootNodes( this.rootNode, true );
i = items.length;
while(i--) {
classItems = modules.domUtils.getAttributeList(items[i], 'class');
x = classItems.length;
while(x--) {
// find v2 names
if(modules.utils.startWith( classItems[x], 'h-' )){
this.appendCount(classItems[x], 1, out);
}
// find v1 names
for(var key in modules.maps) {
// has v1 root but not also a v2 root so we dont double count
if(modules.maps[key].root === classItems[x] && classItems.indexOf(key) === -1) {
this.appendCount(key, 1, out);
}
}
}
}
var relCount = this.countRels( this.rootNode );
if(relCount > 0){
out.rels = relCount;
}

return out;
}
},


/**
* does a node have a class that marks it as a microformats root
*
* @param {DOM Node} node
* @param {Objecte} options
* @return {Boolean}
*/
isMicroformat: function( node, options ) {
var classes,
i;

if(!node){
return false;
}

// if documemt get topmost node
node = modules.domUtils.getTopMostNode( node );

// look for h-* microformats
classes = this.getUfClassNames(node);
if(options && options.filters && modules.utils.isArray(options.filters)){
i = options.filters.length;
while(i--) {
if(classes.root.indexOf(options.filters[i]) > -1){
return true;
}
}
return false;
}else{
return (classes.root.length > 0);
}
},


/**
* does a node or its children have microformats
*
* @param {DOM Node} node
* @param {Objecte} options
* @return {Boolean}
*/
hasMicroformats: function( node, options ) {
var items,
i;

if(!node){
return false;
}

// if browser based documemt get topmost node
node = modules.domUtils.getTopMostNode( node );

// returns all microformats roots
items = this.findRootNodes( node, true );
if(options && options.filters && modules.utils.isArray(options.filters)){
i = items.length;
while(i--) {
if( this.isMicroformat( items[i], options ) ){
return true;
}
}
return false;
}else{
return (items.length > 0);
}
},


/**
* add a new V1 mapping object to parser
*
* @param {Array} maps
*/
add: function( maps ){
maps.forEach(function(map){
if(map && map.root && map.name && map.properties){
modules.maps[map.name] = JSON.parse(JSON.stringify(map));
}
});
},


/**
* internal parse to get parent microformat by walking up the tree
*
Expand Down Expand Up @@ -253,20 +386,6 @@ var Modules = (function (modules) {
},


/**
* add a new V1 mapping object to parser
*
* @param {Array} maps
*/
add: function( maps ){
maps.forEach(function(map){
if(map && map.root && map.name && map.properties){
modules.maps[map.name] = JSON.parse(JSON.stringify(map));
}
});
},


// find uf's of a given type and return a dom and node structure of just that type of ufs
findFilterNodes: function(rootNode, filters) {
var newRootNode = modules.domUtils.createNode('div'),
Expand Down Expand Up @@ -303,57 +422,6 @@ var Modules = (function (modules) {
},


/**
* get the count of microformats
*
* @param {DOM Node} rootNode
* @return {Int}
*/
count: function( options ) {
var out = {},
items,
classItems,
x,
i;

this.init();
options = (options)? options : {};
this.getDOMContext( options );

// if we do not have any context create error
if(!this.rootNode || !this.document){
return {'errors': [this.noContentErr]};
}else{

items = this.findRootNodes( this.rootNode, true );
i = items.length;
while(i--) {
classItems = modules.domUtils.getAttributeList(items[i], 'class');
x = classItems.length;
while(x--) {
// find v2 names
if(modules.utils.startWith( classItems[x], 'h-' )){
this.appendCount(classItems[x], 1, out);
}
// find v1 names
for(var key in modules.maps) {
// has v1 root but not also a v2 root so we dont double count
if(modules.maps[key].root === classItems[x] && classItems.indexOf(key) === -1) {
this.appendCount(key, 1, out);
}
}
}
}
var relCount = this.countRels( this.rootNode );
if(relCount > 0){
out.rels = relCount;
}

return out;
}
},


/**
* appends data to output object for count
*
Expand All @@ -368,84 +436,8 @@ var Modules = (function (modules) {
out[name] = count;
}
},



/**
* does a node have a class that marks it as a microformats root
*
* @param {DOM Node} node
* @param {Objecte} options
* @return {Boolean}
*/
isMicroformat: function( node, options ) {
var classes,
i;

if(!node){
return false;
}

// if documemt get topmost node
node = modules.domUtils.getTopMostNode( node );
//if(node.nodeType && node.nodeType === 9){
// node = modules.domUtils.querySelector(node, 'html');
//}

// look for h-* microformats
classes = this.getUfClassNames(node);
if(options && options.filters && modules.utils.isArray(options.filters)){
i = options.filters.length;
while(i--) {
if(classes.root.indexOf(options.filters[i]) > -1){
return true;
}
}
return false;
}else{
return (classes.root.length > 0);
}
},


/**
* does a node or its children have microformats
*
* @param {DOM Node} node
* @param {Objecte} options
* @return {Boolean}
*/
hasMicroformats: function( node, options ) {
var items,
i;

if(!node){
return false;
}


// if browser based documemt get topmost node
node = modules.domUtils.getTopMostNode( node );
//if(node.nodeType && node.nodeType === 9){
// node = modules.domUtils.querySelector(node, 'html');
//}

// returns all microformats roots
items = this.findRootNodes( node, true );
if(options && options.filters && modules.utils.isArray(options.filters)){
i = items.length;
while(i--) {
if( this.isMicroformat( items[i], options ) ){
return true;
}
}
return false;
}else{
return (items.length > 0);
}
},


/**
* is the microformats type in the filter list
*
Expand Down
2 changes: 1 addition & 1 deletion lib/version.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
modules.version = '1.0.0';
modules.version = '1.1.0';
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "Glenn Jones",
"name": "microformat-node",
"description": "A microformat parser for node.js",
"version": "1.0.1",
"version": "1.1.0",
"license": "MIT",
"keywords": [
"parser",
Expand Down Expand Up @@ -31,7 +31,7 @@
"dependencies": {
"cheerio": "0.19.x",
"bluebird": "2.9.x",
"microformat-shiv": "1.0.x"
"microformat-shiv": "https://api.github.com/repos/glennjones/microformat-shiv/tarball/"
},
"devDependencies": {
"hapi": "8.4.x",
Expand Down
2 changes: 1 addition & 1 deletion static/javascript/data.js

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions static/javascript/testrunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

var options = {
'baseUrl': 'http://example.com',
'overlappingVersions': true,
'impliedPropertiesByVersion': false,
'dateFormat': 'html5',
'parseLatLonGeo': false
};

Expand Down
3 changes: 1 addition & 2 deletions test/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ function parseHTML(html, baseUrl){
options = {
'html': html,
'baseUrl': baseUrl,
'overlappingVersions': false,
'impliedPropertiesByVersion': true
'dateFormat': 'html5'
};

return Microformats.get(options);
Expand Down
4 changes: 1 addition & 3 deletions test/interface-count-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ var cheerio = require('cheerio');


var options = {
'baseUrl': 'http://example.com/',
'overlappingVersions': false,
'impliedPropertiesByVersion': true
'baseUrl': 'http://example.com/'
},
result;

Expand Down
Loading

0 comments on commit a4a3ec4

Please sign in to comment.