2015-02-13 07:22:32 +03:00
|
|
|
import Ember from 'ember';
|
2014-11-28 13:15:48 +03:00
|
|
|
/*
|
|
|
|
Example usage:
|
|
|
|
{{gh-url-preview prefix="tag" slug=theSlugValue tagName="p" classNames="description"}}
|
|
|
|
*/
|
2015-08-19 14:55:40 +03:00
|
|
|
export default Ember.Component.extend({
|
2014-11-28 13:15:48 +03:00
|
|
|
classNames: 'ghost-url-preview',
|
|
|
|
prefix: null,
|
|
|
|
slug: null,
|
|
|
|
|
2015-05-26 05:10:50 +03:00
|
|
|
config: Ember.inject.service(),
|
|
|
|
|
2015-01-29 20:05:16 +03:00
|
|
|
url: Ember.computed('slug', function () {
|
2014-11-28 13:15:48 +03:00
|
|
|
// Get the blog URL and strip the scheme
|
2015-05-26 05:10:50 +03:00
|
|
|
var blogUrl = this.get('config.blogUrl'),
|
2014-11-28 13:15:48 +03:00
|
|
|
noSchemeBlogUrl = blogUrl.substr(blogUrl.indexOf('://') + 3), // Remove `http[s]://`
|
|
|
|
|
|
|
|
// Get the prefix and slug values
|
|
|
|
prefix = this.get('prefix') ? this.get('prefix') + '/' : '',
|
2015-01-29 20:05:16 +03:00
|
|
|
slug = this.get('slug') ? this.get('slug') + '/' : '',
|
2014-11-28 13:15:48 +03:00
|
|
|
|
|
|
|
// Join parts of the URL together with slashes
|
2015-01-29 20:05:16 +03:00
|
|
|
theUrl = noSchemeBlogUrl + '/' + prefix + slug;
|
2014-11-28 13:15:48 +03:00
|
|
|
|
2015-01-29 20:05:16 +03:00
|
|
|
return theUrl;
|
|
|
|
})
|
2014-11-28 13:15:48 +03:00
|
|
|
});
|