Skip to content

Commit

Permalink
fix render function
Browse files Browse the repository at this point in the history
  • Loading branch information
adamstallard committed May 22, 2013
1 parent 1d0f4e9 commit d22dc16
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions lib/modest-preview.js
Expand Up @@ -37,14 +37,14 @@ modest = this.modest || {

// Remove trailing slashes and whitespace from the "path" attribute; Add one slash

path = pathAttr.replace(/[\/\\\s]+$/,'') + '/';
path = pathAttr.replace(/[\/\\\s]+$/, '') + '/';
}

path += moduleName;

// Append ".xml" if the path doesn't already end with it

path = path.replace(/\.xml$/,'') + '.xml';
path = path.replace(/\.xml$/, '') + '.xml';
moduleContent = modest.localFile(path);
modest.$uncompiled[moduleName] = $(moduleContent);
}
Expand Down Expand Up @@ -135,24 +135,24 @@ modest = this.modest || {

// find and compile module views within the node

$.each(modules, function(i,module){
$.each(modules, function(i, module){
$node.find(module).each(function(){
modest.compileView($(this),module);
modest.compileView($(this), module);
});
});

},
//#!REMOVE-POST-COMPILE
getAttributes : function(el){
var attrs = {};
$.each(el.attributes, function(i,attr){
$.each(el.attributes, function(i, attr){
attrs[attr.name] = attr.value;
});
return attrs;
},
localFile : function (path){
if(modest.nodejs)
return fs.readFileSync(path,'utf8');
return fs.readFileSync(path, 'utf8');
else
return modest.remoteFile(path);
},
Expand All @@ -171,7 +171,7 @@ modest = this.modest || {
// Supported data formats: JSON
return $.parseJSON(modest.remoteFile(path));
},
compileView : function($view,module,parameters){
compileView : function($view, module, parameters){
var params = {};
var paramAttrs = {};
var viewAttrs, $targets;
Expand All @@ -185,19 +185,19 @@ modest = this.modest || {

if($view.attr('remotedata')){
$.each($view.attr('remotedata').toLowerCase().split(' '),function(){
$.extend(params,modest.remoteData(this + ''));
$.extend(params, modest.remoteData(this + ''));
});
$view.removeAttr('remotedata');
}

if($view.attr('data')){
$.each($view.attr('data').toLowerCase().split(' '),function(){
$.extend(params,modest.data(this + ''));
$.each($view.attr('data').toLowerCase().split(' '), function(){
$.extend(params, modest.data(this + ''));
});
$view.removeAttr('data');
}

$.extend(params,parameters);
$.extend(params, parameters);

// html parameters

Expand Down Expand Up @@ -255,10 +255,10 @@ modest = this.modest || {
default:
eq = uses[u].indexOf('=');
if(eq !== -1){
attr = uses[u].slice(0,eq);
param = uses[u].slice(eq+1);
attr = uses[u].slice(0, eq);
param = uses[u].slice(eq + 1);
if(params[param])
$target.attr(attr,params[param]);
$target.attr(attr, params[param]);
}
else {
if(params[uses[u]]===undefined){
Expand All @@ -274,13 +274,14 @@ modest = this.modest || {
}
}
});


return $view;
},
render : function(module,parameters){
render : function(module, parameters){
var $view = $('<div>');
modest.compileView($view, module, parameters);
$view = modest.compileView($view, module, parameters);
$view.find('[uses]').not('[uses=""]').removeAttr('uses');
return $view.children(':first')[0].outerHTML;
return $view[0].outerHTML;
}
};
//#REMOVE-POST-COMPILE
Expand Down

0 comments on commit d22dc16

Please sign in to comment.