Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Div rendering #31

Merged
merged 4 commits into from
Feb 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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