0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-03 23:00:14 -05:00
ghost/core/client/app/models/slug-generator.js

37 lines
776 B
JavaScript
Raw Normal View History

2015-02-12 21:22:32 -07:00
import Ember from 'ember';
import {request as ajax} from 'ic-ajax';
const {RSVP, inject} = Ember;
export default Ember.Object.extend({
slugType: null,
value: null,
ghostPaths: inject.service('ghost-paths'),
toString() {
return this.get('value');
},
generateSlug(textToSlugify) {
let url;
if (!textToSlugify) {
return RSVP.resolve('');
}
url = this.get('ghostPaths.url').api('slugs', this.get('slugType'), encodeURIComponent(textToSlugify));
return ajax(url, {
type: 'GET'
}).then((response) => {
let [firstSlug] = response.slugs;
let {slug} = firstSlug;
this.set('value', slug);
return slug;
});
}
});