Coder Social home page Coder Social logo

gulp-dust's Introduction

Deprecated

The Dust project is no longer maintained.


gulp-dust Build Status

Precompile Dust templates

Issues with the output should be reported on the Dust issue tracker.

Install

$ npm install --save-dev gulp-dust

Usage

const gulp = require('gulp');
const dust = require('gulp-dust');

gulp.task('default', () =>
	gulp.src('templates/list.html')
		.pipe(dust())
		.pipe(gulp.dest('dist'))
);

API

dust([options])

options

Type: Object

name

Type: Function
Default: Filename (templates/list.html => list)

You can override the default behavior by supplying a function which gets the current File object and is expected to return the name.

Example:

dust({
	name: file => 'custom'
});
config

Type: Object
Default: {whitespace: false, amd: false, cjs: false}

Corresponds to dust.config. Use it to override any dust configuration value.

whitespace

Type: boolean
Default: false

Preserve whitespace.

amd

Type: boolean
Default: false

Compile as AMD modules.

cjs

Type: boolean
Default: false

Compile as CommonJS modules.

License

MIT © Sindre Sorhus

gulp-dust's People

Contributors

gilly3 avatar kevva avatar popham avatar sindresorhus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

gulp-dust's Issues

Whitespace Flag Unsupported

I need to inject a false value into the third parameter of Dust's compile method (whitespace handling), but the functionality is currently unexposed by your API. Would you add this flag to your plugin's signature (or accept a pull request)?

Details:
I'm using Dust to generate some Javascript with gulp-dust-render. I want to pretty print the generated code, including some comment blocks to get extracted by js-doc (or read inline). I mention the comment particularly, because all of the prettifiers that I can find have trouble restoring the newlines within a comment block.

Files not compiled when watch triggers due to change in subfolder

Hey, so I have a pretty weird problem and hope you can help me.

I have a gulp task:

gulp.task('html', function () {
  // load portfolio data
  let data = {
    'portfolioItems': JSON.parse(fs.readFileSync('resources/templates/data/portfolio.json'))
  }

  return gulp.src(['resources/templates/*.dust', 'resources/templates/**/*.dust', '!resources/templates/partials/*.dust'])
      .pipe(dust({
        basePath: 'resources/templates',
        whitespace: true,
        data: data
      }))
      .on('error', swallowError)
      .pipe(gulp.dest('public'))
      .pipe(refresh())
})

This works fine. I also have a watch task for this:

// watch css
gulp.task('watch-html', function () {
  gulp.watch([
    'resources/templates/*',
    'resources/templates/partials/*',
    'resources/templates/portfolio/*'
  ], () => {
    runSequence(
      'html',
      'service-worker'
    )
  })
})

The watch task works fine for files in the resources/templates/ directory. However, if I change something within the partials or portfolio folder, it breaks. Even though the html task is run (output is shown in the terminal e.g. [17:33:31] Reloaded index.html) the files are actually not updated.

I am at my wits end, as to what I am doing wrong. Is there some kind of caching/dirty checking that breaks my tasks? Any other idea what this could be?

Thanks for your help.

Compile to HTML

Hey,

I would love to see an option to compile to html instead of js. What do you thing @sindresorhus would you be in for this? I could try to send a PR.

Loading partials for use in templates

Is there any way to load partials for use in these templates? Perhaps I'm missing something.

If the answer is no I'd be happy to take a shot at implementing it.

Avoid name collisions

Here's the issue I'm running into when using your plugin:

I've spread my Dust templates over different directories, and many of them share the same name (like list.dust, show.dust etc.). It would be great if you could allow some kind of directory "namespacing" during compilation. For example: If I have a Dust template inside templates/articles/show.dust, it should be registered under the name artices/show rather than just show.

It would be sufficient to make this opt-in via an option parameter in order to retain backwards compatibility.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.