-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactor package * Upgrade packages * Fix tests * Upgrade qunit
- Loading branch information
Showing
25 changed files
with
223 additions
and
151 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 was deleted.
Oops, something went wrong.
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,27 @@ | ||
import Ember from 'ember'; | ||
import hash from 'object-hash'; | ||
import SvgGenerator from '../utils/generators/svg'; | ||
|
||
const { computed, Service } = Ember; | ||
|
||
export default Service.extend({ | ||
initials: {}, | ||
|
||
generator: computed(function() { | ||
return new SvgGenerator; | ||
}), | ||
|
||
removeAll() { | ||
Object.keys(this.get(`initials`)).forEach((key) => this.get('generator').revoke(key)) | ||
this.set('initials', {}); | ||
}, | ||
|
||
initialsFor(properties) { | ||
let key = hash(properties); | ||
return this.get(`initials`)[key] || this._create(key, properties); | ||
}, | ||
|
||
_create(key, properties) { | ||
return this.get('initials')[key] = this.get('generator').generate(properties); | ||
} | ||
}); |
This file was deleted.
Oops, something went wrong.
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,23 @@ | ||
// This is an Initials Image Generator Interface | ||
// You have to implement these methods if you want to create your own generator | ||
|
||
// revoke(url) { | ||
// should revoke image from browser cache | ||
// } | ||
|
||
// generate(properties) { | ||
// should return generated image url | ||
// } | ||
|
||
export default class { | ||
constructor() { | ||
this._implement(this.revoke, 'revoke'); | ||
this._implement(this.generate, 'generate'); | ||
} | ||
|
||
_implement(fn, name) { | ||
if (typeof fn !== "function" || fn.length !== 1) { | ||
throw `Base Generator: '${name}' function has to be implemented with exactly one argument!` | ||
} | ||
} | ||
} |
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,45 @@ | ||
import Ember from 'ember'; | ||
import Base from './base'; | ||
|
||
export default class extends Base { | ||
revoke(url) { | ||
URL.revokeObjectURL(url); | ||
} | ||
|
||
generate(properties) { | ||
let textElement = this._generateTextElement(properties.initials, properties.initialsColor, properties.textStyles); | ||
let svgElement = this._generateSvgElement(properties.width, properties.height, properties.backgroundStyles); | ||
|
||
svgElement.append(textElement); | ||
let finalElement = Ember.$('<div>').append(svgElement); | ||
let blob = new Blob([finalElement.html()], { type: "image/svg+xml" }); | ||
return URL.createObjectURL(blob); | ||
} | ||
|
||
// Private | ||
|
||
_generateTextElement(text, color, styles = {}) { | ||
return this._generateElement('<text></text>', styles, { | ||
y: '50%', | ||
x: '50%', | ||
dy: '0.35em', | ||
'text-anchor': 'middle', | ||
'pointer-events': 'auto', | ||
fill: color, | ||
}).html(text); | ||
} | ||
|
||
_generateElement(name, styles = {}, attrs = {}) { | ||
return Ember.$(name).attr(attrs).css(styles); | ||
} | ||
|
||
_generateSvgElement(width, height, styles = {}) { | ||
return this._generateElement('<svg></svg>', styles, { | ||
width, | ||
height, | ||
xmlns: 'http://www.w3.org/2000/svg', | ||
'pointer-events': 'none', | ||
'viewBox': '0 0 100 100' | ||
}); | ||
} | ||
} |
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,20 @@ | ||
export default function(name) { | ||
let initials = name ? name.trim() : ''; | ||
let letters = initials.split(' '); | ||
|
||
if (letters.length > 1) { | ||
let first = capitalizedFirstLetter(letters.shift()); | ||
let last = capitalizedFirstLetter(letters.pop()); | ||
initials = first + last; | ||
} else if (letters.length === 1) { | ||
initials = capitalizedFirstLetter(letters.shift()); | ||
} | ||
|
||
return initials; | ||
} | ||
|
||
// Private | ||
|
||
function capitalizedFirstLetter(word) { | ||
return word ? word[0].toUpperCase() : ''; | ||
} |
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 } from 'ember-initials/services/ember-initials-store'; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
import resolver from './helpers/resolver'; | ||
import { setResolver } from 'ember-qunit'; | ||
import { start } from 'ember-cli-qunit'; | ||
|
||
setResolver(resolver); | ||
start(); |
Oops, something went wrong.