Skip to content

Commit

Permalink
Clean content-for method
Browse files Browse the repository at this point in the history
  • Loading branch information
zzarcon committed Nov 23, 2015
1 parent fa188dc commit 5cc083f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
14 changes: 2 additions & 12 deletions lib/ember-addon.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var path = require('path');
var fs = require('fs');
var mergeTrees = require('broccoli-merge-trees');
var funnel = require('broccoli-funnel');
var stringifile = require('stringifile');

var serviceWorker = require('./service-worker.js');

Expand Down Expand Up @@ -48,18 +49,7 @@ module.exports = {

contentFor: function(type, config) {
if (config.environment !== 'test' && type === 'body-footer') {
var lines = [];
lines.push('<script>');
lines.push('if (\'serviceWorker\' in navigator) {');
lines.push(' navigator.serviceWorker.register(\'./service-worker.js\', {scope: \'./\'})');
lines.push(' .catch(function(error) {');
lines.push(' alert(\'Error registering service worker:\'+error);');
lines.push(' });');
lines.push('} else {');
lines.push(' alert(\'service worker not supported\');');
lines.push('}');
lines.push('</script>');
return lines.join('\n');
return stringifile('registration.js', 'script', __dirname);
}
}
};
8 changes: 8 additions & 0 deletions lib/registration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('./service-worker.js', {scope: './'})
.catch(function(error) {
alert('Error registering service worker:'+error);
});
} else {
alert('service worker not supported');
}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,8 @@
"broccoli-merge-trees": "~0.1.4",
"broccoli-writer": "~0.1.1",
"serviceworker-cache-polyfill": "^3.0.0"
},
"devDependencies": {
"stringifile": "^0.1.1"
}
}

0 comments on commit 5cc083f

Please sign in to comment.