Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
71 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { helper } from '@ember/component/helper'; | ||
|
||
export default helper(function defaultsTo(params/*, hash*/) { | ||
let [param, defaultParam] = params; | ||
return param === undefined ? defaultParam : param; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
<ContentLoaderSvg | ||
@animate={{or @animate true}} | ||
@ariaLabel={{or @ariaLabel "Loading interface..."}} | ||
@baseUrl={{or @baseUrl ""}} | ||
@gradientRatio={{or @gradientRatio 2}} | ||
@height={{or @height 130}} | ||
@interval={{or @interval 0.25}} | ||
@preserveAspectRatio={{or @preserveAspectRatio "none"}} | ||
@primaryColor={{or @primaryColor "#f0f0f0"}} | ||
@primaryOpacity={{or @primaryOpacity 1}} | ||
@rtl={{or @rtl false}} | ||
@secondaryColor={{or @secondaryColor "#e0e0e0"}} | ||
@secondaryOpacity={{or @secondaryOpacity 1}} | ||
@speed={{or @speed 2}} | ||
@width={{or @width 400}} | ||
@animate={{defaults-to @animate true}} | ||
@ariaLabel={{defaults-to @ariaLabel "Loading interface..."}} | ||
@baseUrl={{defaults-to @baseUrl ""}} | ||
@gradientRatio={{defaults-to @gradientRatio 2}} | ||
@height={{defaults-to @height 130}} | ||
@interval={{defaults-to @interval 0.25}} | ||
@preserveAspectRatio={{defaults-to @preserveAspectRatio "none"}} | ||
@primaryColor={{defaults-to @primaryColor "#f0f0f0"}} | ||
@primaryOpacity={{defaults-to @primaryOpacity 1}} | ||
@rtl={{defaults-to @rtl false}} | ||
@secondaryColor={{defaults-to @secondaryColor "#e0e0e0"}} | ||
@secondaryOpacity={{defaults-to @secondaryOpacity 1}} | ||
@speed={{defaults-to @speed 2}} | ||
@width={{defaults-to @width 400}} | ||
...attributes | ||
> | ||
{{#if (has-block)}} | ||
{{yield}} | ||
{{else}} | ||
<rect x="0" y="0" rx="5" ry="5" width={{or @width 400}} height={{or @height 130}} /> | ||
<rect x="0" y="0" rx="5" ry="5" width={{defaults-to @width 400}} height={{defaults-to @height 130}} /> | ||
{{/if}} | ||
</ContentLoaderSvg> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default, defaultsTo } from 'ember-content-loader/helpers/defaults-to'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { module, test } from 'qunit'; | ||
import { setupRenderingTest } from 'ember-qunit'; | ||
import { render } from '@ember/test-helpers'; | ||
import hbs from 'htmlbars-inline-precompile'; | ||
|
||
module('Integration | Helper | defaults-to', function(hooks) { | ||
setupRenderingTest(hooks); | ||
|
||
// Replace this with your real tests. | ||
test('it defaults if undefined', async function(assert) { | ||
this.set('inputValue', undefined); | ||
|
||
await render(hbs`{{defaults-to inputValue '1234'}}`); | ||
|
||
assert.equal(this.element.textContent.trim(), '1234'); | ||
}); | ||
|
||
test('it does not defaults if 0', async function(assert) { | ||
this.set('inputValue', 0); | ||
|
||
await render(hbs`{{defaults-to inputValue '1234'}}`); | ||
|
||
assert.equal(this.element.textContent.trim(), '0'); | ||
}); | ||
|
||
test('it does not defaults if empty string', async function(assert) { | ||
this.set('inputValue', ''); | ||
|
||
await render(hbs`{{defaults-to inputValue '1234'}}`); | ||
|
||
assert.equal(this.element.textContent.trim(), ''); | ||
}); | ||
|
||
test('it does not defaults if null', async function(assert) { | ||
this.set('inputValue', null); | ||
|
||
await render(hbs`{{defaults-to inputValue '1234'}}`); | ||
|
||
assert.equal(this.element.textContent.trim(), ''); | ||
}); | ||
|
||
test('it does not defaults if false', async function(assert) { | ||
this.set('inputValue', false); | ||
|
||
await render(hbs`{{defaults-to inputValue '1234'}}`); | ||
|
||
assert.equal(this.element.textContent.trim(), 'false'); | ||
}); | ||
}); |