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

Integrate new metal/soyparser #11

Merged
merged 5 commits into from
May 25, 2017
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
52 changes: 33 additions & 19 deletions lib/pipelines/compileSoy.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var ignore = require('gulp-ignore');
var merge = require('merge');
var path = require('path');
var replace = require('gulp-replace');
var soyparser = require('soyparser');
var soyparser = require('soyparser').default;
var through = require('through2');
var wrapper = require('gulp-wrapper');

Expand Down Expand Up @@ -42,10 +42,6 @@ module.exports = function(options) {
);
};

function addTemplateParam(soyJsPath, templateName, param) {
templateData[soyJsPath][templateName].params.push(param);
}

function buildSoyCompilerArgs(files, outputDir, soyDeps) {
var args = [
'-jar',
Expand Down Expand Up @@ -101,25 +97,43 @@ function createCompiledGulpFile(file, outputDir) {
});
}

function extractParamData(paramData, param) {
paramData.params.push(param.name);
paramData.types[param.name] = param.paramType;

return paramData;
};

function extractTemplateData(soyData, template) {
if (template.type !== 'DelTemplate') {
var templateData = template.params.reduce(
extractParamData,
{
params: [],
types: {}
}
);

if (template.doc && template.doc.params) {
templateData = template.doc.params.reduce(extractParamData, templateData);
}

var templateName = template.id.namespace ? template.id.namespace + '.' : '';
templateName += template.id.name;

soyData[templateName] = templateData;
}

return soyData;
};

function extractParams() {
return through.obj(function(file, encoding, callback) {
try {
var soyJsPath = file.relative + '.js';
var parsed = getParsedSoy(soyJsPath, file.contents);

templateData[soyJsPath] = {};
parsed.templates.forEach(function(cmd) {
if (cmd.deltemplate) {
return;
}

var templateName = cmd.name;
templateData[soyJsPath][templateName] = {params: [], types: {}};
cmd.params.forEach(function(tag) {
addTemplateParam(soyJsPath, templateName, tag.name);
templateData[soyJsPath][templateName].types[tag.name] = tag.type;
});
});
templateData[soyJsPath] = parsed.body.reduce(extractTemplateData, {});

this.push(file);
} catch (e) {
Expand Down Expand Up @@ -171,7 +185,7 @@ function getNameFromNamespace(namespace) {

function getParsedSoy(soyJsPath, contents) {
if (!parsedSoys[soyJsPath]) {
parsedSoys[soyJsPath] = soyparser(contents);
parsedSoys[soyJsPath] = soyparser(contents.toString());
}
return parsedSoys[soyJsPath];
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"gulp-util": "^3.0.7",
"gulp-wrapper": "^1.0.0",
"merge": "^1.2.0",
"soyparser": "^0.2.2",
"soyparser": "^1.0.0",
"stream-combiner": "^0.2.2",
"stream-consume": "^0.1.0",
"through2": "^2.0.0",
Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/soy/delTemplate.soy
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{namespace DelTemplate}

/**
* @param content
*/
{deltemplate DelTemplate.Foo}
{$content}
{/deltemplate}
10 changes: 10 additions & 0 deletions test/lib/pipelines/compileSoy.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ describe('Compile Soy Pipeline', function() {
});
});

it('should not export delegated templates', function(done) {
var stream = vfs.src('test/fixtures/soy/delTemplate.soy')
.pipe(compileSoy());
stream.on('data', function(file) {
var contents = file.contents.toString();
assert.strictEqual(-1, contents.indexOf('exports.DelTemplate.Foo'));
done();
});
});

it('should automatically generate and export component class using SoyRenderer', function(done) {
var stream = vfs.src('test/fixtures/soy/simple.soy')
.pipe(compileSoy());
Expand Down