Skip to content

Commit

Permalink
Using custom livereload wrapper. Fixes #3
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeylukin committed Jul 5, 2013
1 parent 6f69610 commit 73d04c4
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 1 deletion.
3 changes: 3 additions & 0 deletions docpad.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ docpadConfig = {
environments:
development:
outPath: ".tmp"
plugins:
livereload:
populateCollections: false
# Because we utilize Grunt for optimization processed
# docpad's static build is a staging one before Grunt
static:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"docpad-plugin-sitemap": "~0.2.0",
"docpad-plugin-cleanurls": "~2.5.0",
"docpad-plugin-highlightjs": "~2.1.4",
"docpad-plugin-livereload": "~2.4.0",
"docpad-plugin-livereload": "https://github.com/sergeylukin/docpad-plugin-livereload/archive/master.tar.gz",
"grunt": "~0.4.0",
"grunt-contrib-jshint": "~0.1.0",
"grunt-contrib-watch": "~0.1.4",
Expand Down
1 change: 1 addition & 0 deletions src/files/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require.config({
baseUrl: '/scripts',
paths: {
'live-reload-socket-io': '../socket.io/socket.io'
},
shim: {
},
Expand Down
25 changes: 25 additions & 0 deletions src/files/scripts/modules/live-reload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
define('live-reload', [ 'live-reload-socket-io' ], function ( io ) {
(function() {
/* Did we just livereload? */
var log = true && localStorage && console && console.log && true;
if ( log && localStorage.getItem('/docpad-livereload/reloaded') === 'yes' ) {
localStorage.removeItem('/docpad-livereload/reloaded');
console.log('LiveReloaded at', new Date())
}
/* Listen for the regenerated event and perform a reload of the page when the event occurs */
var listen = function(){
var socket = io.connect('/docpad-livereload');
socket.on('regenerated',function(){
if ( log ) {
localStorage.setItem('/docpad-livereload/reloaded', 'yes');
}
document.location.reload();
});
};
if ( typeof io !== 'undefined' ) {
listen();
} else {
console.log( 'io is undefined' );
}
})();
});
8 changes: 8 additions & 0 deletions src/layouts/default.html.jade
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,12 @@ html
script(src="/scripts/charts.js")
// endbuild
script require(['charts'])

if getEnvironment() == 'development'
// Ok, because there are known issues with socket.io client when using in
// tandem with RequireJS, see for details:
// https://github.com/docpad/docpad-plugin-livereload/issues/5
// we inject this custom live-reload module that fixes that
script require(['modules/live-reload'])

!= getBlock('scripts').toHTML()

0 comments on commit 73d04c4

Please sign in to comment.