Skip to content

Commit

Permalink
Paso el parametro fromPretty a pretty para que coincida con jsToHtml
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoefe committed May 2, 2016
1 parent f181264 commit 57ff50c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
17 changes: 13 additions & 4 deletions lib/js-from-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,27 @@ jsFromHtml.parseTextNode = function parseTextNode(text, pad) {
}
};



function hasDisplayBlock(tagName) {
return jsToHtml.htmlTags[tagName]['display']==='block';
}

/*
1. El content va siempre abajo, nunca al lado salvo que sea un solo elemento de texto que va sin corchetes y en la misma línea
2. Los atributos si son 4 o menos van en un solo renglón. Si son más van identados uno abajo del otro
a. Primero va id (si está), luego en orden alfabético
b. Sin comillas salvo los reserved y los guionados
*/
jsFromHtml.cdoToSource = function cdoToSource(tag, pad) {
jsFromHtml.cdoToSource = function cdoToSource(tag, pad, opts) {
var out = [];
var margen = ' ';
var pretty = opts && opts.pretty;
if(tag instanceof jsToHtml.Html) {
if(pad.length!==0) {
out.push('\n');
}
var prettyPrint = pretty && hasDisplayBlock(tag.tagName);
out.push(pad+'html.'+tag.tagName+'(');
var attrs = [];
var idPos = -1;
Expand Down Expand Up @@ -174,7 +182,8 @@ jsFromHtml.cdoToSource = function cdoToSource(tag, pad) {
var obj = tag.content[elem];
var cont=[];
if(obj instanceof jsToHtml.Html || obj instanceof jsToHtml.HtmlComment) {
++haveObjs;
var prettyPrint = pretty && hasDisplayBlock(obj.tagName);
++haveObjs;
cont.push(jsFromHtml.cdoToSource(obj, pad+margen)+',');
} else {
if(tag.content.length !== 1) { cont.push('\n'+pad+margen); }
Expand Down Expand Up @@ -204,11 +213,11 @@ jsFromHtml.cdoToSource = function cdoToSource(tag, pad) {
return out.join('');
};

jsFromHtml.toJsSourceCode = function toJsSourceCode(canonicDirectObject){
jsFromHtml.toJsSourceCode = function toJsSourceCode(canonicDirectObject, opts){
var jsSrc = [];
for(var o=0; o<canonicDirectObject.length; ++o) {
var cdo = canonicDirectObject[o];
jsSrc.push(jsFromHtml.cdoToSource(cdo, ''));
jsSrc.push(jsFromHtml.cdoToSource(cdo, '',opts));
}
return jsSrc.join('');
};
Expand Down
4 changes: 2 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe("jsFromHtml from fixtures", function(){
{fileName: 'ejemplo.html' , },
{fileName: 'pseudo-pp.html'},
{fileName: 'pseudo-pp.html', skip: '#7', jsName: 'pseudo-pp-es6.js', versionES:6},
{fileName: 'from-pp.html' , skip: '#8', fromPretty:true},
{fileName: 'from-pp.html' , skip: '#8', pretty:true},
].forEach(function(fixtureInfo){
var fileName = fixtureInfo.fileName;
var mustName="must parse and create the same JS thats create the HTML text for: "+fileName+(fixtureInfo.skip ? " for issue "+fixtureInfo.skip : '');
Expand Down Expand Up @@ -105,7 +105,7 @@ describe("jsFromHtml from fixtures", function(){
// var htmlText = eval(js);
// console.log("htmlText", htmlText);
var cdo=jsFromHtml.parse(htmlText);
var sc=jsFromHtml.toJsSourceCode(cdo, {versionES: fixtureInfo.versionES, fromPretty: fixtureInfo.fromPretty});
var sc=jsFromHtml.toJsSourceCode(cdo, {versionES: fixtureInfo.versionES, pretty: fixtureInfo.pretty});
//console.log("sc", JSON.stringify(sc));
//console.log("js", JSON.stringify(js));
expect(sc).to.eql(js);
Expand Down

0 comments on commit 57ff50c

Please sign in to comment.