0.1.7 • Published 8 years ago

gulp-pug-template-underscore v0.1.7

Weekly downloads
-
License
MIT
Repository
github
Last release
8 years ago

gulp-pug-template-underscore

logo

Build Status

Overview

指定のディレクトリ配下にあるpugファイルをcompileして、指定のjsファイル内の /.template\('.*?'\)/g に該当する要素の場合、replaceする。

このことにより、htmlファイル内に <script type="text/template"></script> のような記述がなくなり、htmlファイルの見通しがよくなること、かつpugファイルの再利用性や、共通性を高められるのでは、という狙い。

Sample Project

Sample gulpfile.js

var gulp = require('gulp');
var ptu = require('gulp-pug-template-underscore');

var srcPath = 'src/javascripts/**/*.js';
var destPath = 'dest/javascripts';

gulp.task('default',function(){
  gulp.src(srcPath)
  .pipe(ptu({
    templateDirPath: 'src/pug/templates',
    prefix: '',
    pathSplit: '.',
    extension: false,
  }))
  .pipe(gulp.dest(destPath));
});

options.prefix

gulpfile.js

var gulp = require('gulp');
var ptu = require('gulp-pug-template-underscore');

var templateDirPath = 'src/pug/templates';
var srcPath = 'src/javascripts/**/*.js';
var destPath = 'dest/javascripts';

gulp.task('default',function(){
  gulp.src(srcPath)
  .pipe(ptu({
    templateDirPath: templateDirPath,
    prefix: 'ptu-'
  }))
  .pipe(gulp.dest(destPath));
});

sample.js

// not replace target
_.template($('#foo').html())
_.template('<li><%= title %></li>')

// replace target
_.template('ptu-foo') // replace with compiled foo.pug 

options.pathSplit

var gulp = require('gulp');
var ptu = require('gulp-pug-template-underscore');

var templateDirPath = 'src/pug/templates';
var srcPath = 'src/javascripts/**/*.js';
var destPath = 'dest/javascripts';

gulp.task('default',function(){
  gulp.src(srcPath)
  .pipe(ptu({
    templateDirPath: templateDirPath,
    pathSplit: '/',
  }))
  .pipe(gulp.dest(destPath));
});

sample.js

// replace target
_.template('nest/foo') // replace with compiled nest/foo.pug 

options.extension

var gulp = require('gulp');
var ptu = require('gulp-pug-template-underscore');

var templateDirPath = 'src/pug/templates';
var srcPath = 'src/javascripts/**/*.js';
var destPath = 'dest/javascripts';

gulp.task('default',function(){
  gulp.src(srcPath)
  .pipe(ptu({
    templateDirPath: templateDirPath,
    extension: true,
  }))
  .pipe(gulp.dest(destPath));
});

sample.js

// replace target
_.template('foo.pug') // replace with compiled nest/foo.pug 

options example

var gulp = require('gulp');
var ptu = require('gulp-pug-template-underscore');

var templateDirPath = 'src/pug/templates';
var srcPath = 'src/javascripts/**/*.js';
var destPath = 'dest/javascripts';

gulp.task('default',function(){
  gulp.src(srcPath)
  .pipe(ptu({
    templateDirPath: 'src/pug/templates',
    prefix: '',
    pathSplit: '/',
    extension: true,
  }))
  .pipe(gulp.dest(destPath));
});

sample.js

// replace target
_.template('nest/foo.pug') // replace with compiled nest/foo.pug 
0.1.7

8 years ago

0.1.6

8 years ago

0.1.5

8 years ago

0.1.4

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago

0.0.16

8 years ago

0.0.15

8 years ago

0.0.14

8 years ago

0.0.13

8 years ago

0.0.12

8 years ago

0.0.11

8 years ago

0.0.10

8 years ago

0.0.9

8 years ago

0.0.8

8 years ago

0.0.7

8 years ago

0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago