Skip to content

Commit

Permalink
Updated URL module
Browse files Browse the repository at this point in the history
  • Loading branch information
glennjones committed Dec 28, 2015
1 parent 65a5228 commit 5a88395
Show file tree
Hide file tree
Showing 16 changed files with 256 additions and 282 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ lib-cov
pids
logs
node_modules
url

npm-debug.log
_site
Expand Down
32 changes: 16 additions & 16 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = function( grunt ) {
process: function(src, filename) {
console.log(filename);
if(filename.indexOf('maps') > -1){
src = src.replace('modules.maps = (modules.maps)? modules.maps : {};','');
src = src.replace('modules.maps = (modules.maps)? modules.maps : {};','');
}
if(filename.indexOf('umd') === -1){
src = src.replace(/(^|\n)[ \t]*('use strict'|"use strict");?\s*/g, '');
Expand All @@ -45,14 +45,14 @@ module.exports = function( grunt ) {
},
files:{
'<%= pkg.name %>.js': [
'umd/umd-start.js',
'umd/umd-start.js',
'lib/version.js',
'lib/living-standard.js',
'lib/parser.js',
'lib/parser-implied.js',
'lib/parser-includes.js',
'lib/parser-rels.js',
'lib/utilities.js',
'lib/parser-implied.js',
'lib/parser-includes.js',
'lib/parser-rels.js',
'lib/utilities.js',
'lib/domutils.js',
'lib/url.js',
'lib/isodate.js',
Expand All @@ -71,7 +71,7 @@ module.exports = function( grunt ) {
process: function(src, filename) {
console.log(filename);
if(filename.indexOf('maps') > -1){
src = src.replace('modules.maps = (modules.maps)? modules.maps : {};','');
src = src.replace('modules.maps = (modules.maps)? modules.maps : {};','');
}
if(filename.indexOf('umd') === -1){
src = src.replace(/(^|\n)[ \t]*('use strict'|"use strict");?\s*/g, '');
Expand All @@ -90,16 +90,16 @@ module.exports = function( grunt ) {
},
files:{
'modern/<%= pkg.name %>-modern.js': [
'umd/umd-start.js',
'umd/umd-start.js',
'lib/version.js',
'lib/living-standard.js',
'lib/parser.js',
'lib/parser-implied.js',
'lib/parser-includes.js',
'lib/parser-rels.js',
'lib/utilities.js',
'lib/parser-implied.js',
'lib/parser-includes.js',
'lib/parser-rels.js',
'lib/utilities.js',
'lib/domutils.js',
'lib/modern/url.js',
'lib/url.js',
'lib/isodate.js',
'lib/dates.js',
'lib/text.js',
Expand Down Expand Up @@ -189,9 +189,9 @@ module.exports = function( grunt ) {
grunt.registerTask( 'default', ['buildfile', 'concat:standard', 'concat:modern', 'copy', 'uglify']);
grunt.registerTask( 'test', ['mocha_phantomjs:all']);
grunt.registerTask( 'umd', ['umd:default']);





};
78 changes: 39 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Methods
-----
* Parsing
* [`get`](#get)
* [`getParent`](#getParent)
* [`getParent`](#getParent)
* Discovery
* [`count`](#count)
* [`isMicroformat`](#isMicroformat)
Expand All @@ -31,7 +31,7 @@ Methods
get
-----

Simple parse of a HTML document or a selected part of a HTML document.
Simple parse of a HTML document or a selected part of a HTML document.
```javascript
<script src="microformat-shiv.min.js" type="text/javascript"></script>
<script type="text/javascript">
Expand All @@ -40,52 +40,52 @@ Simple parse of a HTML document or a selected part of a HTML document.
items = Microformats.get()
// do something with data `items`
</script>
```
```

Using options
```javascript
<script src="microformat-shiv.min.js" type="text/javascript"></script>
<script type="text/javascript">
var items,
options;

options = {'filters': ['h-card']};
var items = Microformats.get( options )
// do something with data `items`
</script>
```
```

Targeting just part of a HTML document
```javascript
<script src="microformat-shiv.min.js" type="text/javascript"></script>
<script type="text/javascript">
var items,
options;

options = {
'filters': ['h-card'],
'node': document.getElementById('target')
};
var items = Microformats.get( options )
// do something with data `items`
</script>
```
</script>
```

Parsing a HTML string
```javascript
<script src="microformat-shiv.min.js" type="text/javascript"></script>
<script type="text/javascript">
var items,
options;

options = {
'baseUrl': 'http://glennjones.net',
'html': '<a class="h-card" href="/about.html">Glenn</a>'
};
var items = Microformats.get( options )
// do something with data `items`
</script>
```
</script>
```
Note: The `baseUrl` is optional and is used to resolve relative URLs


Expand All @@ -104,7 +104,7 @@ __I would recommend always setting the `textFormat` option to `normalised`. This
Experimental options
-------
These options are part of ongoing specification development. They maybe removed or renamed in the future.
* `parseLatLonGeo` (Boolean) Parse geo date written as latlon i.e. 30.267991;-97.739568
* `parseLatLonGeo` (Boolean) Parse geo date written as latlon i.e. 30.267991;-97.739568
default is `false`


Expand All @@ -126,16 +126,16 @@ JSON output. This is an example of a parsed `h-card` microformat.
"rels": {},
"rel-urls": {}
}
```
JSON output with error.
```
JSON output with error.
```javascript
{
"items":[],
"rels": {},
"rel-urls": {}
"errors":["No options.node was provided and no global document object could be found."]
}
```
```

getParent
-----
Expand All @@ -150,7 +150,7 @@ Given an HTML DOM node it will return its first parent microformat.
items = Microformats.getParent( node )
// do something with data `items`
</script>
```
```
The `getParent` method takes the same `options` as the `get` method. The one difference is how the `options.filters` property affects the output. Adding a filter list to `getParent` will allow the search for a parent to pass through microformats you do not want to target.

```javascript
Expand All @@ -163,57 +163,57 @@ The `getParent` method takes the same `options` as the `get` method. The one dif
items = Microformats.getParent( node, options )
// do something with data `items`
</script>
```
```


Count
-----
The `count` method returns the number of each microformat type found. It does not do a full parse so it is much quicker
The `count` method returns the number of each microformat type found. It does not do a full parse so it is much quicker
than `get` and can be used for tasks such as adding notifications to the UI. The method can take an `options` object as a parameter.
```javascript
<script src="microformat-shiv.min.js" type="text/javascript"></script>
<script type="text/javascript">
var counts = Microformats.count()
// do something with counts data
</script>
```
Output
// do something with counts data
</script>
```
Output
```javascript
{
'h-event': 1,
'h-card': 2,
'rels': 6
}
```
```

isMicroformat
-------------
The `isMicroformat` method returns whether a node has a valid microformats class. It currently does not consider
The `isMicroformat` method returns whether a node has a valid microformats class. It currently does not consider
`rel=*` a microformat. The method can take an `options` object as a second parameter.
```javascript
<script src="microformat-shiv.min.js" type="text/javascript"></script>
<script type="text/javascript">
var node = document.getElementById('target');
var isVaild = Microformats.isMicroformat( node );
// do something with isVaild boolean
</script>
```
// do something with isVaild boolean
</script>
```


hasMicroformats
-------------
The `hasMicroformats` method returns whether a document or node has any valid microformats class. It currently does
The `hasMicroformats` method returns whether a document or node has any valid microformats class. It currently does
not take `rel=*` microformats into account. The method can take an `options` object as a second parameter.
```javascript
<script src="microformat-shiv.min.js" type="text/javascript"></script>
<script type="text/javascript">
var isVaild,
node = document.getElementById('target');

isVaild = Microformats.isMicroformat( node );
// do something with isVaild boolean
</script>
```
// do something with isVaild boolean
</script>
```



Expand All @@ -223,7 +223,7 @@ The library has two properties to help identify how up-to-date it is:

* `version` (String) internal version number
* `livingStandard` (String ISO Date) the current https://github.com/microformats/tests used.


Browser support
---------------
Expand All @@ -233,12 +233,12 @@ Desktop
* Chrome 14-43
* Opera 19-30 (Version 18 > passes 84% of tests)
* Safari 6-8 (Version 5 passes 97% of tests)
* IE 8-11
* Edge
* IE 9-11
* Edge

Mobile
----------------------
* iOS 5.1-8.3 (Version 4 passes 97% of tests)
* iOS 5.1-8.3 (Version 4 passes 97% of tests)
* Andriod 4.2-5 (The only versions I could test)
* Android Firefox 39 (The only versions I could test)
* Android Chrome 43 (The only versions I could test)
Expand All @@ -258,12 +258,12 @@ The library has all the version 1 definitions built-in, but you can add new defi
'currency': {}
}
}
```
```

Standard vs Modern
-------------------------------
The library code comes in two versions `microformats-shiv.js` and `microformat-shiv-modern.js`. The modern version used by Mozilla in Firefox does not include the polyfills for
[DOMParser](https://developer.mozilla.org/en-US/docs/Web/API/DOMParser) and [URL](https://developer.mozilla.org/en-US/docs/Web/API/URL/URL).
The library code comes in two versions `microformats-shiv.js` and `microformat-shiv-modern.js`. The modern version used by Mozilla in Firefox does not include the polyfills for
[DOMParser](https://developer.mozilla.org/en-US/docs/Web/API/DOMParser).
This version of the library can only be used with modern browser which support these features.


Expand Down
17 changes: 13 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ var Hapi = require('hapi');
// Create a server with a host and port
var server = new Hapi.Server();

server.connection({
host: (process.env.PORT)? '0.0.0.0' : 'localhost',
server.connection({
host: (process.env.PORT)? '0.0.0.0' : 'localhost',
port: parseInt(process.env.PORT, 10) || 3000
});

Expand Down Expand Up @@ -77,6 +77,15 @@ server.route([{
listing: true,
}
}
},{
method: 'GET',
path: '/url/{path*}',
handler: {
directory: {
path: './url',
listing: true,
}
}
},{
method: 'GET',
path: '/thirdparty/{path*}',
Expand Down Expand Up @@ -110,10 +119,10 @@ var goodOptions = {

// Register plug-in and start
server.register([{
register: require('good'),
register: require('good'),
options: goodOptions
},{
register: require('blipp'),
register: require('blipp'),
}], function (err) {
if (err) {
console.error(err);
Expand Down
4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "microformat-shiv",
"version": "1.0.0",
"main": "microformat-shiv.js",
"version": "1.3.2",
"main": "microformat-shiv.js",
"authors": ["Glenn Jones <glennjonesnet@gmail.com>"],
"license": "MIT",
"moduleType": [
Expand Down
Loading

0 comments on commit 5a88395

Please sign in to comment.