Skip to content

Commit

Permalink
Merge pull request #62 from jamesreggio/liquid-unless
Browse files Browse the repository at this point in the history
Add `liquid-unless` helper
  • Loading branch information
jamesreggio committed Sep 10, 2014
2 parents fef67ea + c0081a3 commit 3725e7c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
25 changes: 17 additions & 8 deletions app-addon/helpers/liquid-if.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import Ember from "ember";

export default function(property, options) {
var View = options.data.view.container.lookupFactory('view:liquid-if');
options.hash.firstTemplate = options.fn;
delete options.fn;
options.hash.secondTemplate = options.inverse;
delete options.inverse;
options.hash.showFirstBinding = property;
return Ember.Handlebars.helpers.view.call(this, View, options);
export function factory(invert) {
return function(property, options) {
var View = options.data.view.container.lookupFactory('view:liquid-if');

var templates = [options.fn, options.inverse];
if (invert) {
templates.reverse();
}
delete options.fn;
delete options.inverse;

options.hash.templates = templates;
options.hash.showFirstBinding = property;
return Ember.Handlebars.helpers.view.call(this, View, options);
};
}

export default factory(false);
2 changes: 2 additions & 0 deletions app-addon/helpers/liquid-unless.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { factory } from "./liquid-if";
export default factory(true);
2 changes: 1 addition & 1 deletion app-addon/views/liquid-if.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Ember from "ember";

export default LiquidOutlet.extend({
liquidUpdate: Ember.on('init', Ember.observer('showFirst', function(){
var template = this.get((this.get('showFirst') ? 'first' : 'second') + 'Template');
var template = this.get('templates')[this.get('showFirst') ? 0 : 1];
var view = Ember._MetamorphView.create({
container: this.container,
template: template,
Expand Down
3 changes: 3 additions & 0 deletions app/templates/helpers-documentation/liquid-if.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ and <code>false</code> states.</li>
helpers.
</ul>

<p><code>\{{#liquid-unless}}</code> is the complement to
<code>\{{#liquid-if}}</code>.</p>

<h3>Demo</h3>

<p>Here's a bit of a silly example that shows off the flexibility of
Expand Down

0 comments on commit 3725e7c

Please sign in to comment.