Giter Site home page Giter Site logo

grunt-jade's Introduction

grunt-jade build status

Compile jade templates with grunt.

Notices

This plugin requires Grunt ~0.4.0

If you are looking for the version of this that works in Grunt ~0.3.0, use version 0.3.9

Getting Started

Install this grunt plugin next to your project's grunt.js gruntfile with: npm install grunt-jade

Then add this line to your project's grunt.js gruntfile:

grunt.loadNpmTasks('grunt-jade');

Documentation

To your grunt.js gruntfile, add:

jade: {
  no_options: {
    files: {
      'dest/path/': ['path/to/src/*.jade']
    }
  }
}

For AMD compilation, add: (dependencies is what you want the runtime to be named)

jade: {
  amd: {
    files: {
      'dest/path/': ['path/to/src/*.jade']
    },
    options: {
      wrap: 'amd'
    }
  }
}

For node-style (Modules/1.0) compilation, add: (dependencies is what you want the runtime to be named)

jade: {
  node: {
    files: {
      'dest/path/': ['path/to/src/*.jade']
    },
    options: {
      wrap: 'node'
    }
  }
}

For pretty-indentation whitespace, add

jade: {
  pretty: {
    files: {
      'dest/path/': ['path/to/src/*.jade']
    },
    options: {
      pretty: true
    }
  }
}

For debug compilation, add:

jade: {
  debug: {
    files: {
      'dest/path/': ['path/to/src/*.jade']
    },
    options: {
      compileDebug: true
    }
  }
}

For HTML compilation (instead of JS), add:

jade: {
  html: {
    files: {
      'dest/path/': ['path/to/src/*.jade']
    },
    options: {
      client: false
    }
  }
}

For unwrapped functions, add:

jade: {
  unwrapped: {
    files: {
      'dest/path/': ['path/to/src/*.jade']
    },
    options: {
      wrap: false // or 'none'
    }
  }
}

To keep directory structure, use basePath:

jade: {
  base_path: {
    files: {
      'dest/path/': ['path/to/src/*.jade'],
    },
    options: {
      basePath: 'path/to/'
    }
  }
}

For no runtime file, add:

jade: {
  no_runtime: {
    files: {
      'dest/path/': ['path/to/src/*.jade']
    },
    options: {
      runtime: false
    }
  }
}

For locals, add:

jade: {
  locals: {
    files: {
      'dest/path/': ['path/to/src/*.jade']
    },
    options: {
      client: false,
      locals: {
        title: 'Welcome to my website!'
      }
    }
  }
}

Or alternatively, use a function:

jade: {
  locals: {
    files: {
      'dest/path/': ['path/to/src/*.jade']
    },
    options: {
      client: false,
      locals: function() {
          return {compiledAt: new Date()};
      }
    }
  }
}

This is useful when you are also using the watch task, since the function will be called on each reload.

For custom extension, add:

jade: {
  custom_extension: {
    files: {
      'dest/path/': ['path/to/src/*.jade']
    },
    options: {
      extension: '.xml',
    }
  }
}

Defaults

Options Defaults

options: {
  client: true,
  runtime: true,
  pretty: false,
  compileDebug: false,
  extension: null,
  wrap: null,
  locals: null,
  basePath: null
}

Wrap Defaults

wrap: {
  wrap: true,
  amd: false,
  node: false,
  dependencies: null
}

Wrap Shorthand

Strings can be passed to options.wrap as a quick config

wrap: 'amd'
// Shorthand for:
// wrap: {
//   wrap: true,
//   amd: true,
//   node: false,
//   dependencies: 'runtime'
// }

wrap: 'global'
// Shorthand for: default wrapper
// wrap: {
//   wrap: true,
//   amd: false,
//   node: false,
//   dependencies: null
// }

wrap: 'node'
// Shorthand for:
// wrap: {
//   wrap: true,
//   amd: false,
//   node: true,
//   dependencies: './runtime'
// }

wrap: 'none'
// Shorthand for:
// wrap: {
//   wrap: false,
//   amd: false,
//   node: false,
//   dependencies: null
// }

Booleans can be passed to options.wrap as a quick config, too

wrap: true
// Shorthand for: 'global' or default wrapper
// wrap: {
//   wrap: true,
//   amd: false,
//   node: false,
//   dependencies: null
// }

wrap: false
// Shorthand for: 'none'
// wrap: {
//   wrap: false,
//   amd: false,
//   node: false,
//   dependencies: null
// }

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using grunt.

Release History

(Nothing yet)

License

Copyright (c) 2013 Blaine Bublitz Licensed under the MIT license.

grunt-jade's People

Contributors

azproduction avatar eush77 avatar logankoester avatar mkatrenik avatar phated avatar surjikal avatar vladtsf avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

grunt-jade's Issues

How do I compile mutliple HTML Jade templates that use the same mixin

mixin hero(title)
    .hero
        .hero__inner
            h1.hero__title #{title}

So, my project uses a Jade mixin like the above on multiple pages and, when I compile the Jade to HTML pages, I have to copy that mixin on each page that it is used.

Can this module be used to globally pass that mixin to all pages so I don't have to copy it everytime?

It would make my life 1000x easier.

Rewrite for 0.4.0rc7

Need to rewrite plugin using the new init template and make code more testable + add more tests.

window declaration on jade template?

Not sure if it is necessary. I saw a branch with window designated, but is it needed or does anyone else want it? The only way I can see it not getting attached to window is if it is used in an AMDed function, and that case is covered.

Grunt 0.4 Release

I'm posting this issue to let you know that we will be publishing Grunt 0.4 on Monday, February 18th.

If your plugin is not already Grunt 0.4 compatible, would you please consider updating it? For an overview of what's changed, please see our migration guide.

If you'd like to develop against the final version of Grunt before Monday, please specify "grunt": "0.4.0rc8" as a devDependency in your project. After Monday's release, you'll be able to use "grunt": "~0.4.0" to actually publish your plugin. If you depend on any plugins from the grunt-contrib series, please see our list of release candidates for compatible versions. All of these will be updated to final status when Grunt 0.4 is published.

Also, in an effort to reduce duplication of effort and fragmentation in the developer community, could you review the grunt-contrib series of plugins to see if any of your functionality overlaps significantly with them? Grunt-contrib is community maintained with 40+ contributors—we'd love to discuss any additions you'd like to make.

Finally, we're working on a new task format that doesn't depend on Grunt: it's called node-task. Once this is complete, there will be one more conversion, and then we'll never ask you to upgrade your plugins to support our changes again. Until that happens, thanks for bearing with us!

If you have any questions about how to proceed, please respond here, or join us in #grunt on irc.freenode.net.

Thanks, we really appreciate your work!

Says "unexpected identifier although it shouldn't

I have newest node and npm. I have tried my jade code with 2 linters. I have used grunt-contrib-jade before and it compiled normally but this one provided more options.

module.exports = function(grunt) {

  grunt.initConfig({
    sass: {
        options: {
            sourceMap: true
        },
        dist: {
            files: {
                'app/static/css/main.css': 'app/static/sass/main.sass'
            }
        }
    },
    jade: {
      html: {
        files: {
          'app/templates/': ['app/templates/*.jade', '!app/templates/layout.jade']
        },
        options: {
          client: false
        }
      }
    },
    ts: {
      options: {
        fast: 'never',
        failOnTypeErrors: false
      },
      default: {
        files: {
          'app/static/js/app.js': 'app/typescript/app.ts'
        }
      }
    },
    watch: {
      files: [
        'app/templates/**/*.jade',
        //'app/typescript/**/*.ts',
        'app/static/**/*.sass'
      ],
      tasks: ['compile']
    }
  });

  grunt.loadNpmTasks("grunt-ts");
  grunt.loadNpmTasks('grunt-jade');
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-sass');

  grunt.registerTask('compile', ['sass', 'jade']);
  grunt.registerTask('default', ['compile', 'watch']);

};

and jade:

extends layout

mixin scripty(url)
  script(src="/js/#{url}")
  script(src="/static/js/#{url}")

block head
    script(src="https://code.angularjs.org/tools/system.js")
    script(src="https://code.angularjs.org/tools/typescript.js")
    script(src="https://code.angularjs.org/2.0.0-alpha.44/angular2.dev.js")
    +scripty("app.js")

block content
  h1= title
  p Welcome to #{title}

  my-app loading...

block scripts

error:

Running "jade:html" (jade) task
Verifying property jade.html exists in config...OK
Files: app/templates/index.jade -> app/templates/
Options: client=false, runtime, pretty=false, compileDebug=false, extension=null, wrap=null, locals=null, basePath=null
Options: client=false, runtime, pretty=false, compileDebug=false, extension=null, wrap=null, locals=null, basePath=null
Reading app/templates/index.jade...OK
Compiling app/templates/index.jade...Warning: Unexpected identifier Used --force, continuing.
Writing app\templates\index.html...OK

Catch compile errors a little more gracefully....

Heya,

Just a small change I feel we could do with looking into... in the helpers we could do with catching jade compile errors a little more gracefully so that when we use growl-notify it doesn't stop grunt continuing the watch tasks.

Will submit a pull request, just that we have a grunt task for development that will allow front-end devs to keep saving the jade file and recompile with growl notifying when a success or failure has happened with jade they have edited.

grunt.template.process on options

Does anyone want the options processed by grunt.template.process before merged with defaults?

If not all the options, what about just locals? This might remove the need for locals to allow a function.

Maintain template folder structure

When compiling, I'm losing the jade templates folder structure and this is problematic for me, as all the html files get mixed in the same directory.

This commit from Richard Butler was very useful for me:
richardbutler@7e34aec

It would be nice if you could merge it.

dependencies parameter in node template

I'm trying to use this in a build step of a component to compile jade templates to javascript. Everything is working great, except I have to make one tiny change to the node template to get it to work properly. I know I'm probably abusing the way the node template is intended to work, so feel free to close this and tell me I'm doing it wrong or that this requires a new template type. In the node template, I have to remove the ./ from the require call. When I remove the ./, it works perfectly and it's able to find the runtime because of the way component require works.

Here is the grunt-jade snippet from my Gruntfile:

    jade:
      all:
        files:
          'dist/table/templates': ['lib/table/templates/*.jade']
        options:
          runtime: false
          wrap:
            wrap: true
            amd: false
            node: true
            dependencies: 'jade-runtime'

HTML Compilation and Maintain Directory Structure

So I'm a bit baffled by all of the options available; say that I have a directory (with sub-directories) containing my *.jade templates. For example:

'app/views/index.jade'
'app/views/partials/home.jade'
'app/views/partials/products/management.jade'
'app/views/partials/users/update.jade'

etc..

and I want to have the compiled HTML files moved to the 'app/public/' folder, but maintain the folder structure, eg.

'app/public/index.html'
'app/public/partials/home.jade'
'app/public/partials/products/management.jade'
'app/public/partials/users/update.jade'

What combination of configuration options do I need to achieve this?

Can I do something like:

html: {
  files: {
    'app/public/': ['app/views/**/*.jade']
  },
  options: {
    client: false
  }
}

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.