Permalink
Browse files

remove grunt as a dependency of prettify helper. update js-beautify d…

…evDependency now that my HTML formatting options have been merged in.
  • Loading branch information...
1 parent ad1eabd commit 3fbf3c4b5f5083d9ae950970e002350faf329683 @jonschlinkert jonschlinkert committed Aug 18, 2013
Showing with 32 additions and 28 deletions.
  1. +2 −0 .gitignore
  2. +1 −4 Gruntfile.js
  3. +0 −1 button-1/button.hbs
  4. +2 −2 package.json
  5. +1 −1 templates/condense.hbs
  6. +26 −20 templates/helpers/helper-prettify.js
View
@@ -14,5 +14,7 @@ results
npm-debug.log
node_modules
+tmp
+temp
vendor
*.sublime-*
View
@@ -41,10 +41,7 @@ module.exports = function(grunt) {
layout: 'layout.hbs',
},
button1: {
- files: {'_demo/button-1/': ['button-1/index.hbs']},
- options: {
- partials: 'button-1/button.hbs'
- }
+ files: {'_demo/button-1/': ['button-1/index.hbs']}
},
button2: {
files: {'_demo/button-2/': ['button-2/index.hbs']},
View
@@ -1 +0,0 @@
-<button class="effeckt-button {{modifier}} topcoat-button"><span class="label">{{label}}</span> <span class="spinner"></span></button>
View
@@ -24,8 +24,8 @@
"assemble": "~0.4.4",
"grunt": "~0.4.1",
"grunt-contrib-clean": "~0.4.1",
- "js-beautify": "~1.4.0",
- "lodash": "~1.3.1"
+ "lodash": "~1.3.1",
+ "js-beautify": "~1.4.0"
},
"licenses": [
{
View
@@ -1,3 +1,3 @@
-{{#condense}}{{#prettify indent="4"}}
+{{#condense}}{{#prettify indent="2"}}
{{> body }}
{{/prettify}}{{/condense}}
@@ -8,31 +8,34 @@
var _ = require('lodash');
module.exports.register = function(Handlebars, options) {
+
var prettify = require('js-beautify').html;
+
/**
* Prettify HTML output
- * @param {indent} hash [the level to indent output HTML] @default [2]
+ *
* @example:
- * {{#prettify indent="6"}}
+ * {{#prettify indent="2"}}
* {{> body }}
* {{/prettify}}
*/
Handlebars.registerHelper('prettify', function (options) {
var hash = options.hash;
- opts = _.extend(hash, opts);
- // reduce multiple newlines to a single newline then add a newline above each comment.
- return prettifyHTML(options.fn(this).replace(/(\n|\r){2,}/g, '\n').replace(/(\s*<!--)/g, '\n$1'),
- _.extend(opts, options.hash)
- );
+ defaults = _.extend(hash, defaults);
+
+ return prettifyHTML(options.fn(this)
+ .replace(/(\n|\r){2,}/g, '\n') // reduce multiple newlines to a single newline
+ .replace(/(\s+<!--)/g, '\n$1'), defaults); // add a newline above each comment
});
+
/**
* Default options passed to js-beautify.
- * @param {hash arguments} [Options received as hash arguments will override these defaults.]
- * @param {task options} [Options defined in the Assemble task/target overrides hash arguments.]
+ * @param {hash arguments} [Options received as hash arguments will override defaults.]
+ * @param {task options} [Options defined in the task/target override hash arguments.]
*/
- var opts = {
+ var defaults = {
condense: true,
indent_size: 2,
indent_char: " ",
@@ -41,21 +44,24 @@ module.exports.register = function(Handlebars, options) {
brace_style: "expand",
preserve_newline: false,
max_preserve_newline: 0,
- unformatted: []
+ unformatted: ['code', 'pre']
};
- opts = _.extend(opts, options.prettify);
+ defaults = _.extend(defaults, options.prettify);
+ defaults.indent_size = defaults.indent;
- // Alias
- opts.indent_size = opts.indent;
- // Format HTML with js-beautify, pass in options.
- var prettifyHTML = function(source, opts) {
+ /**
+ * Format HTML with js-beautify, pass in options.
+ * @param {String} source [The un-prettified HTML.]
+ * @param {Object} options [Object of options passed to js-beautify.]
+ * @returns {String} [Stunning HTML.]
+ */
+ var prettifyHTML = function(source, options) {
try {
- return prettify(source, opts);
+ return prettify(source, options);
} catch (e) {
- grunt.log.error(e);
- grunt.fail.warn('HTML beautification failed.');
+ console.error(e);
+ console.warn('HTML beautification failed.');
}
};
};
-

0 comments on commit 3fbf3c4

Please sign in to comment.