mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-15 11:34:24 +03:00
c3ad1ae9e2
No Issue - Switches to the newer style of dependency injection. - Instead of injection Controllers via "needs," use Ember.inject.controller(). - Get rid of initializers that were only injecting objects into various factories. Converts these objects into Ember.Service objects and declaratively inject them where needed via Ember.inject.service(). The added benefit to this is that it's no longer a mystery where these properties/methods come from and it's straightforward to inject them where needed.
35 lines
775 B
JavaScript
35 lines
775 B
JavaScript
import Ember from 'ember';
|
|
import {request as ajax} from 'ic-ajax';
|
|
|
|
export default Ember.Object.extend({
|
|
slugType: null,
|
|
value: null,
|
|
|
|
ghostPaths: Ember.inject.service('ghost-paths'),
|
|
|
|
toString: function () {
|
|
return this.get('value');
|
|
},
|
|
|
|
generateSlug: function (textToSlugify) {
|
|
var self = this,
|
|
url;
|
|
|
|
if (!textToSlugify) {
|
|
return Ember.RSVP.resolve('');
|
|
}
|
|
|
|
url = this.get('ghostPaths.url').api('slugs', this.get('slugType'), encodeURIComponent(textToSlugify));
|
|
|
|
return ajax(url, {
|
|
type: 'GET'
|
|
}).then(function (response) {
|
|
var slug = response.slugs[0].slug;
|
|
|
|
self.set('value', slug);
|
|
|
|
return slug;
|
|
});
|
|
}
|
|
});
|