gulp-soynode
v2.0.0
Published
Gulp plugin using soynode for working with Closure Templates, aka Soy.
Downloads
40
Readme
gulp-soynode
Gulp plugin using soynode for working with Closure Templates, aka Soy.
Issues with the output should be reported on the soynode issue tracker.
Install
$ npm install --save-dev gulp-soynode
Usage
var gulp = require('gulp');
var soynode = require('gulp-soynode');
gulp.task('build', function() {
return gulp.src('views/*.soy')
.pipe(soynode())
.pipe(gulp.dest('build'));
});
You can also watch for changes to rebuild all templates:
gulp.task('watch', function(done) {
gulp.watch('views/*.soy', ['build']);
});
Or, if you prefer, rebuild only one the modified file:
gulp.task('watch', function(done) {
gulp.watch('test/*.soy', function(file) {
gulp.src(file.path)
.pipe(soynode())
.pipe(gulp.dest('build'));
});
});
Message extraction
You can also use gulp-soynode
to extract all messages from your soy templates into a tlf file, which can be used for translating them later. To use it, just call soynode.lang
with the name of the file you want the messages to be extracted to:
var gulp = require('gulp');
var soynode = require('gulp-soynode');
gulp.task('build-lang', function() {
return gulp.src('views/*.soy')
.pipe(soynode.lang({
outputFile: 'translations/translations_en.xlf'
}));
});
Build with locales
var gulp = require('gulp');
var soynode = require('gulp-soynode');
gulp.task('build', function() {
return gulp.src('views/*.soy')
.pipe(soynode({
locales: ['en', 'pt-BR'],
messageFilePathFormat: 'translations/translations_{LOCALE}.xlf'
}))
.pipe(gulp.dest('build'));
});
API
soynode(options)
Options can be set via soynode(options)
, the keys can contain the following:
renderSoyWeb
{boolean} Whether SoyWeb templates will be rendered automatically. It deliberately allows to includes dummy data so the designer can get a feel for how the task list will appear with real data rather with minimal copy and paste. For more information visit http://plovr.com/soyweb.html. [Default: false]renderSoyWebContext
{Object|function()} Default render context of rendered SoyWeb file, or a function that is called with each handled file, returning the context object for it. [Default: null]renderSoyWebFileExtension
{string} File extension of the rendered SoyWeb file. Relevant when your Soy template outputs other formats, like.md
. [Default: .html]renderSoyWebInjectedData
{Object|function()} Object with injected data to be used when rendering SoyWeb files, or a function that is called with each handled file, returning the injected data for it. [Default: null]inputDir
{string} Optional path to a directory where files will be read. When compiled from a directory, this option will be overwritten with the caller inputDir. [Default: process.cwd()]outputDir
{string} Path to a directory where files will be written. [Default: null]eraseTemporaryFiles
{boolean} Whether to erase temporary files after a compilation. [Default: false]concatOutput
{boolean} Whether the compiled soy.js files should be joined into a single file. This is helpful for loading templates in a browser and simplest to use whenoutputDir
is explicitly set anduniqueDir
is false. [Default: false]concatFileName
{string} File name used for concatenated files, only relevant when concatOutput is true, ".soy.concat.js" is appended, so don't include ".js" yourself. [Default: compiled]- locales {Array} List of locales to translate the templates to.
- messageFilePathFormat {string} Path to the translation file to use, which can contain any of the placeholders allowed on the --messageFilePathFormat option of SoyToJsSrcCompiler.jar.
See the soynode options for more information.
soynode.lang(options)
Options can be set via soynode.lang(options)
, the keys can contain the following:
outputFile
{String} The path of the file with the resulting extracted messages. [Default: '/tmp/soynode/translations.xlf']
Contributing
Questions, comments, bug reports, and pull requests are all welcome. Submit them at the project on GitHub.
Bug reports that include steps-to-reproduce (including code) are the best. Even better, make them in the form of pull requests.