Skip to content

Commit

Permalink
Merge pull request #31 from opentable/div-rendering
Browse files Browse the repository at this point in the history
Div rendering
  • Loading branch information
matteofigus committed Feb 16, 2015
2 parents 39c7391 + 6d99cfb commit 3e0a9c8
Show file tree
Hide file tree
Showing 13 changed files with 1,810 additions and 317 deletions.
8 changes: 3 additions & 5 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,21 @@ module.exports = function(grunt) {
// default task
grunt.registerTask('default', ['test', 'build']);

// build task
grunt.registerTask('build', ['build-web-client']);

// Setup the precommit hook
grunt.registerTask('hooks', ['githooks:all']);

// test
grunt.registerTask('test', ['jshint:all', 'mochaTest:unit', 'mochaTest:acceptance']);

// custom tasks
grunt.registerTask('build-web-client', 'Builds and minifies the web-client.js', function(){
grunt.registerTask('build', 'Builds and minifies the oc-client component', function(){

var done = this.async(),
handlebarsRuntime = fs.readFileSync(path.join(__dirname, 'node_modules/handlebars/dist/handlebars.runtime.min.js')).toString(),
jadeRuntime = fs.readFileSync(path.join(__dirname, 'node_modules/jade/runtime.js')).toString(),
headLoad = fs.readFileSync(path.join(__dirname, 'components/oc-client/src/head.load.js')).toString(),
ocClient = fs.readFileSync(path.join(__dirname, 'components/oc-client/src/oc-client.js')).toString(),
bundle = format('{0}\n;\n{1}\n;\n{2}\n;\noc.clientVersion=\'{3}\';', jadeRuntime, handlebarsRuntime, ocClient, taskObject.pkg.version),
bundle = format('{0}\n;\n{1}\n;\n{2}\n;\n{3}\n;\noc.clientVersion=\'{4}\';', jadeRuntime, handlebarsRuntime, headLoad, ocClient, taskObject.pkg.version),
ocClientPackageInfo = require('./components/oc-client/package.json');

ocClientPackageInfo.version = taskObject.pkg.version;
Expand Down
16 changes: 12 additions & 4 deletions client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ var Client = function(conf){
}

fs.readFile(path.resolve(__dirname, '../components/oc-client/src/oc-client.min.js'), 'utf-8', function(err, clientJs){
var clientSideHtml = format('<script class="ocClientScript">{0}</script>{1}', clientJs, self.getUnrenderedComponent(href));
var clientSideHtml = format('<script class="ocClientScript">{0}</script>{1}', clientJs, self.getUnrenderedComponent(href, options));
return callback(errorDescription, clientSideHtml);
});

Expand All @@ -126,7 +126,7 @@ var Client = function(conf){
local = isLocal(apiResponse);

if(options.render === 'client'){
return callback(null, self.getUnrenderedComponent(href));
return callback(null, self.getUnrenderedComponent(href, options));
}

self.getStaticTemplate(apiResponse.template.src, !local, function(templateText){
Expand All @@ -150,8 +150,16 @@ var Client = function(conf){
});
};

this.getUnrenderedComponent = function(href){
return format('<oc-component href="{0}" data-rendered="false"></oc-component>', href);
this.getUnrenderedComponent = function(href, options){

if(!options || !options.ie8){
return format('<oc-component href="{0}" data-rendered="false"></oc-component>', href);
}

return format('<script class="ocComponent">(function($d,$w,oc){var href=\'href="{0}"\';' +
'$d.write((!!$w.navigator.userAgent.match(/MSIE 8/))?(\'<div data-oc-component="true" \'+href+\'>' +
'</div>\'):(\'<oc-component \'+href+\'></oc-component>\'));if(oc) oc.renderUnloadedComponents();}' +
'(document,window,((typeof(oc)===\'undefined\')?undefined:oc)));</script>', href);
};

this.getRenderedComponent = function(data){
Expand Down
4 changes: 2 additions & 2 deletions components/oc-client/_package/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "oc-client",
"description": "",
"version": "0.8.3",
"version": "0.8.4",
"dependencies": {},
"repository": "",
"oc": {
Expand All @@ -21,6 +21,6 @@
"src": "server.js"
}
},
"version": "0.8.3"
"version": "0.8.4"
}
}
Loading

0 comments on commit 3e0a9c8

Please sign in to comment.