Coder Social home page Coder Social logo

makotot / handlebars-helper-minify Goto Github PK

View Code? Open in Web Editor NEW

This project forked from helpers/handlebars-helper-minify

0.0 3.0 0.0 102 KB

{{minify}} handlebars helper, for minification of HTML with html-minifier.

License: MIT License

JavaScript 100.00%

handlebars-helper-minify's Introduction

{{minify}} NPM version

{{minify}} handlebars helper, for minification of HTML with html-minifier.

This helper depends on and extends js-beautify. Please visit and star that project to show your support.

Quickstart

In the root of your project, run the following in the command line:

npm i handlebars-helper-minify --save-dev

Options

All options from js-beautify are available in this helper, as well as a few custom options that were specially created for this helper. The helper comes with some sensible defaults (in the humble opinion of the helper creator), but it's easy to customize them if you need to. Here are are two (convenient) ways to set options:

  • options object: pass an options object to the helper as a parameter. E.g. {{#minify opts.obj}}.
  • options hash: this is an easy way to set options on the helper, and it also gives you granular control over how the helper renders content.
  • Gruntfile: if you use both Grunt and Assemble, you can define options in the Assemble task options of your project's Gruntfile.

options hash

By design, options define here will override options defined anywhere else. This approach also provides granular control over options, allowing you to defined different options on multiple instances of the helper in the same file.

Example:

{{#minify removeComments="true"}}
  {{> header }}
{{/minify}}
{{#minify removeEmptyElements="true"}}
  {{> body }}
{{/minify}}
{{#minify removeComments="true"}}
  {{> footer }}
{{/minify}}

"assemble" task options

The helper can be used without Grunt or Assemble. But if you happen to use these two awesome tools you can define options for the helper in your Gruntfile in the minify sub-options for Assemble:

grunt.initConfig({
  assemble: {
    options: {
      minify: {
        removeAttributeQuotes: false
      }
    },
    files: {}
  }
});

Options defined in the Assemble task can be viewed as custom "global" defaults, which can be overridden by options defined in the options hash.

option defaults

{
  collapseBooleanAttributes: false,
  collapseWhitespace: true,
  removeAttributeQuotes: false,
  removeCDATASectionsFromCDATA: false,
  removeComments: false,
  removeCommentsFromCDATA: false,
  removeEmptyAttributes: false,
  removeEmptyElements: false,
  removeOptionalTags: false,
  removeRedundantAttributes: false,
  useShortDoctype: false
}

Example

Before

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>Document</title>
  </head>
  <body>

    <!-- code comment -->
    <h1>My Blog</h1>
    <h2>Post of the day</h2>

    <!-- scripts -->
    <a href="#">Read more...</a>
  </body>
</html>

After

<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title></title></head><body><!-- code comment --><h1>My Blog</h1><h2>Post of the day</h2><!-- scripts --><a href="#">Read more...</a></body></html>

Contributing

Please see the Contributing to Assemble guide for information on contributing to this project.

Author

Jon Schlinkert

Related Projects and Links

License

Copyright (c) 2014 Jon Schlinkert, contributors. Released under the MIT license


This file was generated on March 10, 2014.

handlebars-helper-minify's People

Contributors

jonschlinkert avatar stevenblack avatar

Watchers

James Cloos avatar Makoto Tateno avatar  avatar

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.