Last active
January 24, 2021 21:34
-
-
Save mike-north/8b70661d5ce7b3b9372f5a8a5d801b0b to your computer and use it in GitHub Desktop.
EL - helper
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
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle' | |
}); |
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
import Ember from 'ember'; | |
/** | |
* We have a need for placeholder images in our | |
* app, and it would be great to have a helper | |
* that consistently builds URLs for us of the form | |
* | |
* http://placecorgi.com/260/180 | |
* http://placekitten.com/260/180 | |
* | |
* In this case, 260 would be the width, and | |
* 180 the height. The API we're looking for is | |
* | |
* {{placeholder-url w=260 h=180}} | |
* | |
* You may pick either placecorgi or placekitten, | |
* and if you're really clever you can use one | |
* as a default, and allow the user to optionally | |
* use the other. | |
* | |
* REQIUREMENTS: | |
* | |
* - Specifying width and/or height is optional, | |
* where 120px is used for default height, | |
* 100px default width. | |
* - Minimum allowable width and height is 10px. | |
* If anything less than this is specified | |
* for either dimension, use 10px in its place. | |
*/ | |
export function placeholderUrl(params, hash) { | |
return 'TODO'; | |
} | |
export default Ember.Helper.helper(placeholderUrl); |
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
import Ember from 'ember'; | |
export default function destroyApp(application) { | |
Ember.run(application, 'destroy'); | |
} |
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
import Resolver from '../../resolver'; | |
import config from '../../config/environment'; | |
const resolver = Resolver.create(); | |
resolver.namespace = { | |
modulePrefix: config.modulePrefix, | |
podModulePrefix: config.podModulePrefix | |
}; | |
export default resolver; |
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
import Ember from 'ember'; | |
import Application from '../../app'; | |
import config from '../../config/environment'; | |
const { run } = Ember; | |
const assign = Ember.assign || Ember.merge; | |
export default function startApp(attrs) { | |
let application; | |
let attributes = assign({rootElement: "#test-root"}, config.APP); | |
attributes = assign(attributes, attrs); // use defaults, but you can override; | |
run(() => { | |
application = Application.create(attributes); | |
application.setupForTesting(); | |
application.injectTestHelpers(); | |
}); | |
return application; | |
} |
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
import resolver from './helpers/resolver'; | |
import { | |
setResolver | |
} from 'ember-qunit'; | |
setResolver(resolver); |
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
import { module, test } from 'qunit'; | |
if (require.entries['twiddle/helpers/placeholder-url']) { | |
const placeholderUrl = require('twiddle/helpers/placeholder-url').placeholderUrl; | |
module('placeholder-url helper'); | |
// Replace this with your real tests. | |
test('conventional usage', function(assert) { | |
let result = placeholderUrl([], {w: 300, h: 302}); | |
assert.equal(result, 'http://placekitten.com/300/302', 'w=300, h=302 --> http://placekitten.com/300/302'); | |
}); | |
test('in absense of a dimension, falls back to reasonable values', function(assert) { | |
assert.equal(placeholderUrl([], {w: 300}), 'http://placekitten.com/300/120', 'w=300 --> http://placekitten.com/300/120 (120 as default height)'); | |
assert.equal(placeholderUrl([], {h: 300}), 'http://placekitten.com/100/300', 'h=300 --> http://placekitten.com/100/300 (100 as default width)'); | |
}); | |
test('Enforces minimum dimensions of 10', function(assert) { | |
assert.equal(placeholderUrl([], {w: 2}), 'http://placekitten.com/10/120', 'w=2 results in a 10px wide placeholder image'); | |
assert.equal(placeholderUrl([], {h: 1}), 'http://placekitten.com/100/10', 'h=2 results in a 10px high placeholder image'); | |
}); | |
test('Falls back to default in the absence of options entirely', function(assert) { | |
assert.equal(placeholderUrl(), 'http://placekitten.com/100/120', 'if hash is undefined, falls back to 100x120'); | |
}); | |
} |
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
{ | |
"version": "0.12.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.12.0", | |
"ember-template-compiler": "2.12.0", | |
"ember-testing": "2.12.0" | |
}, | |
"addons": { | |
"ember-data": "2.12.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this exercise examples.
There is a small typo on https://gist.github.com/mike-north/8b70661d5ce7b3b9372f5a8a5d801b0b#file-helpers-placeholder-url-js-L20