Permalink
Browse files

Deprecate whenDepth in favor of ifDepth and unlessDepth.

  • Loading branch information...
1 parent 63d52cd commit e157372fc9b57585d9ba4c987b3046d897da7cb9 @JohnAlbin JohnAlbin committed Jul 23, 2014
Showing with 34 additions and 9 deletions.
  1. +28 −3 bin/kss-node
  2. +6 −6 lib/template/index.html
View
@@ -397,20 +397,36 @@ handlebars.registerHelper('eachRoot', function(options) {
/**
* Equivalent to "if the current section is X levels deep". e.g:
*
- * {{#refDepth 1}}
+ * {{#ifDepth 1}}
* ROOT ELEMENTS ONLY
* {{else}}
* ANYTHING ELSE
- * {{/refDepth}}
+ * {{/ifDepth}}
*/
-handlebars.registerHelper('whenDepth', function(depth, options) {
+handlebars.registerHelper('ifDepth', function(depth, options) {
if (!this.refDepth) {
return '';
}
return (depth == this.refDepth) ? options.fn(this) : options.inverse(this);
});
/**
+ * Equivalent to "unless the current section is X levels deep". e.g:
+ *
+ * {{#unlessDepth 1}}
+ * ANYTHING ELSE
+ * {{else}}
+ * ROOT ELEMENTS ONLY
+ * {{/unlessDepth}}
+ */
+handlebars.registerHelper('unlessDepth', function(depth, options) {
+ if (!this.refDepth) {
+ return '';
+ }
+ return (depth == this.refDepth) ? options.inverse(this) : options.fn(this);
+});
+
+/**
* Similar to the {#eachSection} helper, however will loop over each modifier
* @param {Object} section Supply a section object to loop over it's modifiers. Defaults to the current section.
*/
@@ -467,6 +483,15 @@ handlebars.registerHelper('html', function(arg) {
return new handlebars.SafeString(arg || '');
});
+/**
+ * Equivalent to "if the current section is X levels deep".
+ */
+handlebars.registerHelper('whenDepth', function(depth, options) {
+ // Warn the user that whenDepth is deprecated.
+ console.log('{{whenDepth expression}} is deprecated; use {{ifDepth expression}} instead.');
+ return handlebars.helpers.ifDepth.call(this, depth, options);
+});
+
process.on('exit', function() {
if (!KSS_FAILED) {
console.log('');
View
@@ -42,14 +42,14 @@
layout instead.
The "root" element comes first in this loop, and can be detected using
- the "#whenDepth 1" block as seen below.
+ the "#ifDepth 1" block as seen below.
}}
{{#eachSection rootNumber}}
- {{#whenDepth 1}} {{else}}
+ {{#unlessDepth 1}}
<section class="kss-depth-{{ refDepth }}">
- {{/whenDepth}}
+ {{/unlessDepth}}
- <h1 class="kss-title"><span class="kss-ref">{{ reference }}{{#whenDepth 1}}.0{{/whenDepth}}</span> - {{ header }}</h1>
+ <h1 class="kss-title"><span class="kss-ref">{{ reference }}{{#ifDepth 1}}.0{{/ifDepth}}</span> - {{ header }}</h1>
{{#if description}}
<div class="kss-box">{{{description}}}</div>
@@ -80,9 +80,9 @@ <h1 class="kss-title"><span class="kss-ref">{{ reference }}{{#whenDepth 1}}.0{{/
</div>
{{/if}}
- {{#whenDepth 1}} {{else}}
+ {{#unlessDepth 1}}
</section>
- {{/whenDepth}}
+ {{/unlessDepth}}
{{/eachSection}}
{{/if}}
</article>

0 comments on commit e157372

Please sign in to comment.