mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-27 22:49:56 -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"
|
"google-caja": "5669.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"ember-mocha": "~0.1.4",
|
"ember-mocha": "~0.3.0",
|
||||||
"ember-cli-test-loader": "dgeb/ember-cli-test-loader#test-agnostic",
|
"ember-cli-test-loader": "dgeb/ember-cli-test-loader#test-agnostic",
|
||||||
"ember-cli-shims": "stefanpenner/ember-cli-shims#~0.0.3"
|
"ember-cli-shims": "stefanpenner/ember-cli-shims#~0.0.3"
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,22 +6,21 @@ var urlPreview = Ember.Component.extend({
|
||||||
classNames: 'ghost-url-preview',
|
classNames: 'ghost-url-preview',
|
||||||
prefix: null,
|
prefix: null,
|
||||||
slug: null,
|
slug: null,
|
||||||
theUrl: null,
|
|
||||||
|
|
||||||
generateUrl: function () {
|
url: Ember.computed('slug', function () {
|
||||||
// Get the blog URL and strip the scheme
|
// Get the blog URL and strip the scheme
|
||||||
var blogUrl = this.get('config').blogUrl,
|
var blogUrl = this.get('config').blogUrl,
|
||||||
noSchemeBlogUrl = blogUrl.substr(blogUrl.indexOf('://') + 3), // Remove `http[s]://`
|
noSchemeBlogUrl = blogUrl.substr(blogUrl.indexOf('://') + 3), // Remove `http[s]://`
|
||||||
|
|
||||||
// Get the prefix and slug values
|
// Get the prefix and slug values
|
||||||
prefix = this.get('prefix') ? this.get('prefix') + '/' : '',
|
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
|
// Join parts of the URL together with slashes
|
||||||
theUrl = noSchemeBlogUrl + '/' + prefix + (slug ? slug + '/' : '');
|
theUrl = noSchemeBlogUrl + '/' + prefix + slug;
|
||||||
|
|
||||||
this.set('the-url', theUrl);
|
return theUrl;
|
||||||
}.on('didInsertElement').observes('slug')
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
export default urlPreview;
|
export default urlPreview;
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
{{the-url}}
|
{{url}}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
{
|
{
|
||||||
"node": false,
|
"node": false,
|
||||||
"browser": true,
|
"browser": true,
|
||||||
"nomen": false,
|
|
||||||
"bitwise": true,
|
"bitwise": true,
|
||||||
"curly": true,
|
"curly": true,
|
||||||
"eqeqeq": true,
|
"eqeqeq": true,
|
||||||
|
@ -16,11 +15,8 @@
|
||||||
"regexp": true,
|
"regexp": true,
|
||||||
"undef": true,
|
"undef": true,
|
||||||
"unused": true,
|
"unused": true,
|
||||||
"trailing": true,
|
|
||||||
"indent": 4,
|
"indent": 4,
|
||||||
"esnext": true,
|
"esnext": true,
|
||||||
"onevar": true,
|
|
||||||
"white": true,
|
|
||||||
"quotmark": "single",
|
"quotmark": "single",
|
||||||
"globals": {
|
"globals": {
|
||||||
"Ember": true,
|
"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…
Add table
Reference in a new issue