Skip to content

Kagami/jade-pages-brunch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jade-pages-brunch

Adds Jade static pages support to brunch.

This plugin compile Jade templates into their HTML representation and create separate file for each input source file without wrapping it in AMD/CommonJS modules.

Usage

Install the plugin via npm with npm install --save jade-pages-brunch.

Or, do manual install:

  • Add "jade-pages-brunch": "x.y.z" to package.json of your brunch app.
  • If you want to use git version of plugin, add "jade-pages-brunch": "git+https://github.com/Kagami/jade-pages-brunch.git".

Brunch plugin settings

Plugin settings could be defined in the plugins.jadePages section of the brunch config. Defaults are:

exports.config =
  ...
  plugins:
    jadePages:
      destination: (path) ->
        path.replace /^app[\/\\](.*)\.jade$/, "$1.html"
      jade:
        doctype: "html"
      htmlmin: false

Pattern

You could compile only certian Jade pages by specifying pattern option. By default all files with jade extension are compiled.

Example:

exports.config =
  ...
  plugins:
    jadePages:
      pattern: /^app\/pages\/.*\.jade$/

Destination

You could specify custom place for compiled Jade pages via destination option. It should be Function which takes path of the source file and return destination file path String (relative to the public path). All intermediate directories in the path are created automatically.

By default all Jade pages in app/ are compiled to public/ with the same directory structure and have html extension.

Jade options

You could specify Jade options and template locals in the jade and jade.locals sections accordingly. Example:

exports.config =
  ...
  plugins:
    jadePages:
      jade:
        doctype: "xml"
        pretty: true
        locals:
          varname: "123"

Jade filters

You could specify Jade filters in the filters section. Example:

exports.config =
  ...
  plugins:
    jadePages:
      filters:
        php: (text) -> '<?php \n' + text + '\n?>'
      destination: (path) ->
        path.replace /^app[\/\\](.*)\.jade$/, "$1"

test.php.jade:

:php
  // ...
  $answer = 42;
  // ...

doctype html
html(lang="de")
  body
    p It's <?= $answer ?>!

Output (test.php):

<?php
// ...
$answer = 42;
// ...
?>
<!DOCTYPE html>
<html lang="de">
  <body>
    <p>It's <?= $answer ?>!</p>
  </body>
</html>

HTML minification

You could minify compiled templates using html-minifier by passing following values to the htmlmin section:

  • Enable with default options with true. Default options are:
removeComments: true
removeCommentsFromCDATA: true
removeCDATASectionsFromCDATA: true
collapseBooleanAttributes: true
useShortDoctype: true
removeEmptyAttributes: true
removeScriptTypeAttributes: true
removeStyleLinkTypeAttributes: true
  • Specify custom options by passing Object; see options description here.

Note that by default HTML minification is disabled and using minification with agressive options could break things.

Example:

exports.config =
  ...
  plugins:
    jadePages:
      htmlmin:
        removeComments: true
        collapseWhitespace: true
        removeEmptyAttributes: true

FAQ

Why do you need yet another Jade plugin for Brunch?

Because static-jade-brunch and jaded-brunch don't compatible with another plugin which I use, jade-ngtemplates-brunch. They are both using templates brunch option and enter into a conflict with each other.

And I don't want to implement jade-pages functionality as a part of jade-ngtemplates-brunch (like it was done for example in jade-angularjs-brunch) because it contradicts with plugins modularity spirit.

Then move htmlmin feature inside the separate optimizer plugin.

Unfortunately Brunch doesn't provide a lot of flexibility for plugins. From it's point of view templates are always compiled into single JS file so we need to hack it out and write resulting compiled pages by ourself. Since we did it, another plugin wouldn't make any sense.

In this issue goes discussion about Brunch architecture improvements but no real progress is done for now.

License

jade-pages-brunch - Adds Jade static pages support to brunch

Written in 2014 by Kagami Hiiragi [email protected]

To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.

You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see http://creativecommons.org/publicdomain/zero/1.0/.

About

Adds Jade static pages support to brunch

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •