This repository has been archived by the owner on Nov 28, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add {{background-image-style}} helper
no issue - cleans up multiple CPs that were only outputting a background image style - moves URL decoding/encoding and `htmlSafe` output into one place
- Loading branch information
1 parent
c714370
commit 902e361
Showing
8 changed files
with
57 additions
and
36 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
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
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
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,13 @@ | ||
import {helper} from '@ember/component/helper'; | ||
import {htmlSafe} from '@ember/string'; | ||
|
||
export function backgroundImageStyle([url]/*, hash*/) { | ||
if (url) { | ||
let safeUrl = encodeURI(decodeURI(url)); | ||
return htmlSafe(`background-image: url(${safeUrl});`); | ||
} | ||
|
||
return ''; | ||
} | ||
|
||
export default helper(backgroundImageStyle); |
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
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
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
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,39 @@ | ||
import hbs from 'htmlbars-inline-precompile'; | ||
import {describe, it} from 'mocha'; | ||
import {expect} from 'chai'; | ||
import {setupComponentTest} from 'ember-mocha'; | ||
|
||
describe('Integration: Helper: background-image-style', function () { | ||
setupComponentTest('background-image-style', { | ||
integration: true | ||
}); | ||
|
||
it('renders', function () { | ||
this.render(hbs`{{background-image-style "test.png"}}`); | ||
expect(this.$().text().trim()).to.equal('background-image: url(test.png);'); | ||
}); | ||
|
||
it('escapes URLs', function () { | ||
this.render(hbs`{{background-image-style "test image.png"}}`); | ||
expect(this.$().text().trim()).to.equal('background-image: url(test%20image.png);'); | ||
}); | ||
|
||
it('handles already escaped URLs', function () { | ||
this.render(hbs`{{background-image-style "test%20image.png"}}`); | ||
expect(this.$().text().trim()).to.equal('background-image: url(test%20image.png);'); | ||
}); | ||
|
||
it('handles empty URLs', function () { | ||
this.set('testImage', undefined); | ||
this.render(hbs`{{background-image-style testImage}}`); | ||
expect(this.$().text().trim(), 'undefined').to.equal(''); | ||
|
||
this.set('testImage', null); | ||
this.render(hbs`{{background-image-style testImage}}`); | ||
expect(this.$().text().trim(), 'null').to.equal(''); | ||
|
||
this.set('testImage', ''); | ||
this.render(hbs`{{background-image-style testImage}}`); | ||
expect(this.$().text().trim(), 'blank').to.equal(''); | ||
}); | ||
}); |