mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-13 22:41:32 -05:00
Merge pull request #4868 from jaswilli/url-preview
Simplify url preview component, add test
This commit is contained in:
commit
43f2be4d79
5 changed files with 45 additions and 12 deletions
|
@ -27,7 +27,7 @@
|
|||
"google-caja": "5669.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ember-mocha": "~0.1.4",
|
||||
"ember-mocha": "~0.3.0",
|
||||
"ember-cli-test-loader": "dgeb/ember-cli-test-loader#test-agnostic",
|
||||
"ember-cli-shims": "stefanpenner/ember-cli-shims#~0.0.3"
|
||||
}
|
||||
|
|
|
@ -6,22 +6,21 @@ var urlPreview = Ember.Component.extend({
|
|||
classNames: 'ghost-url-preview',
|
||||
prefix: null,
|
||||
slug: null,
|
||||
theUrl: null,
|
||||
|
||||
generateUrl: function () {
|
||||
url: Ember.computed('slug', function () {
|
||||
// Get the blog URL and strip the scheme
|
||||
var blogUrl = this.get('config').blogUrl,
|
||||
noSchemeBlogUrl = blogUrl.substr(blogUrl.indexOf('://') + 3), // Remove `http[s]://`
|
||||
|
||||
// Get the prefix and slug values
|
||||
prefix = this.get('prefix') ? this.get('prefix') + '/' : '',
|
||||
slug = this.get('slug') ? this.get('slug') : '',
|
||||
slug = this.get('slug') ? this.get('slug') + '/' : '',
|
||||
|
||||
// Join parts of the URL together with slashes
|
||||
theUrl = noSchemeBlogUrl + '/' + prefix + (slug ? slug + '/' : '');
|
||||
theUrl = noSchemeBlogUrl + '/' + prefix + slug;
|
||||
|
||||
this.set('the-url', theUrl);
|
||||
}.on('didInsertElement').observes('slug')
|
||||
return theUrl;
|
||||
})
|
||||
});
|
||||
|
||||
export default urlPreview;
|
||||
|
|
|
@ -1 +1 @@
|
|||
{{the-url}}
|
||||
{{url}}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
{
|
||||
"node": false,
|
||||
"browser": true,
|
||||
"nomen": false,
|
||||
"bitwise": true,
|
||||
"curly": true,
|
||||
"eqeqeq": true,
|
||||
|
@ -16,11 +15,8 @@
|
|||
"regexp": true,
|
||||
"undef": true,
|
||||
"unused": true,
|
||||
"trailing": true,
|
||||
"indent": 4,
|
||||
"esnext": true,
|
||||
"onevar": true,
|
||||
"white": true,
|
||||
"quotmark": "single",
|
||||
"globals": {
|
||||
"Ember": true,
|
||||
|
|
38
core/test/client/unit/components/gh-url-preview_test.js
Normal file
38
core/test/client/unit/components/gh-url-preview_test.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
/* jshint expr:true */
|
||||
import {
|
||||
describeComponent,
|
||||
it
|
||||
} from 'ember-mocha';
|
||||
|
||||
describeComponent('gh-url-preview',
|
||||
function () {
|
||||
it('generates the correct preview URL with a prefix', function () {
|
||||
var component = this.subject({
|
||||
prefix: 'tag',
|
||||
slug: 'test-slug',
|
||||
tagName: 'p',
|
||||
classNames: 'test-class',
|
||||
|
||||
config: {blogUrl: 'http://my-ghost-blog.com'}
|
||||
});
|
||||
|
||||
this.render();
|
||||
|
||||
expect(component.get('url')).to.equal('my-ghost-blog.com/tag/test-slug/');
|
||||
});
|
||||
|
||||
it('generates the correct preview URL without a prefix', function () {
|
||||
var component = this.subject({
|
||||
slug: 'test-slug',
|
||||
tagName: 'p',
|
||||
classNames: 'test-class',
|
||||
|
||||
config: {blogUrl: 'http://my-ghost-blog.com'}
|
||||
});
|
||||
|
||||
this.render();
|
||||
|
||||
expect(component.get('url')).to.equal('my-ghost-blog.com/test-slug/');
|
||||
});
|
||||
}
|
||||
);
|
Loading…
Reference in a new issue