Skip to content

Commit

Permalink
Shared folder asset handling
Browse files Browse the repository at this point in the history
fixes TryGhost#1659, fixes TryGhost#1668

- removed relative asset url from css
- added asset helper to client
- updated references to shared assets
- added functional tests
  • Loading branch information
ErisDS committed Dec 28, 2013
1 parent 25f3df2 commit a8e987e
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 9 deletions.
1 change: 0 additions & 1 deletion core/client/assets/sass/layouts/users.scss
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@
display: block;
width: 110px;
height: 110px;
background-image: url(/shared/img/user-image.png);
background-size: cover;
background-position: center center;
border-radius: 100%;
Expand Down
18 changes: 18 additions & 0 deletions core/client/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,22 @@
Handlebars.registerHelper('url', function () {
return Ghost.paths.subdir;
});

Handlebars.registerHelper('asset', function (context, options) {
var output = '',
isAdmin = options && options.hash && options.hash.ghost;

output += Ghost.paths.subdir + '/';

if (!context.match(/^shared/)) {
if (isAdmin) {
output += 'ghost/';
} else {
output += 'assets/';
}
}

output += context;
return new Handlebars.SafeString(output);
});
}());
5 changes: 3 additions & 2 deletions core/client/tpl/settings/user-profile.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
<section class="content no-padding">

<header class="user-profile-header">
<img id="user-cover" class="cover-image" src="{{#if cover}}{{cover}}{{else}}/shared/img/user-cover.png{{/if}}" title="{{name}}'s Cover Image"/>
<img id="user-cover" class="cover-image" src="{{#if cover}}{{cover}}{{else}}{{asset "shared/img/user-cover.png"}}{{/if}}" title="{{name}}'s Cover Image"/>

<a class="edit-cover-image js-modal-cover button" href="#">Change Cover</a>
</header>

Expand All @@ -18,7 +19,7 @@
<fieldset class="user-details-top">

<figure class="user-image">
<div id="user-image" class="img" {{#if image}}style="background-image: url({{image}});"{{/if}} href="#"><span class="hidden">{{name}}'s Picture</span></div>
<div id="user-image" class="img" style="background-image: url({{#if image}}{{image}}{{else}}{{asset "shared/img/user-image.png"}}{{/if}});" href="#"><span class="hidden">{{name}}'s Picture</span></div>
<a href="#" class="edit-user-image js-modal-image">Edit Picture</a>
</figure>

Expand Down
10 changes: 6 additions & 4 deletions core/server/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,12 @@ coreHelpers.asset = function (context, options) {

output += config.paths().subdir + '/';

if (isAdmin) {
output += 'ghost/';
} else {
output += 'assets/';
if (!context.match(/^shared/)) {
if (isAdmin) {
output += 'ghost/';
} else {
output += 'assets/';
}
}

output += context;
Expand Down
6 changes: 5 additions & 1 deletion core/test/functional/admin/content_test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*globals casper, __utils__, url, testPost */

CasperTest.begin("Content screen is correct", 20, function suite(test) {
CasperTest.begin("Content screen is correct", 21, function suite(test) {
// Create a sample post
casper.thenOpen(url + 'ghost/editor/', function testTitleAndUrl() {
test.assertTitle('Ghost Admin', 'Ghost admin has no title');
Expand Down Expand Up @@ -37,6 +37,10 @@ CasperTest.begin("Content screen is correct", 20, function suite(test) {
test.assertSelectorHasText("#usermenu .usermenu-profile a", "Your Profile");
test.assertSelectorHasText("#usermenu .usermenu-help a", "Help / Support");
test.assertSelectorHasText("#usermenu .usermenu-signout a", "Sign Out");

test.assertResourceExists(function (resource) {
return resource.url.match(/user-image\.png$/) && (resource.status === 200 || resource.status === 304);
}, 'Default user image');
});

casper.then(function testViews() {
Expand Down
12 changes: 11 additions & 1 deletion core/test/functional/admin/settings_test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*globals casper, __utils__, url */

CasperTest.begin("Settings screen is correct", 15, function suite(test) {
CasperTest.begin("Settings screen is correct", 17, function suite(test) {
casper.thenOpen(url + "ghost/settings/", function testTitleAndUrl() {
test.assertTitle("Ghost Admin", "Ghost admin has no title");
test.assertUrlMatch(/ghost\/settings\/general\/$/, "Ghost doesn't require login this time");
Expand Down Expand Up @@ -32,6 +32,16 @@ CasperTest.begin("Settings screen is correct", 15, function suite(test) {
test.assertEval(function testContentIsUser() {
return document.querySelector('.settings-content').id === 'user';
}, "loaded content is user screen");

test.assertResourceExists(function (resource) {
return resource.url.match(/user-image\.png$/) && (resource.status === 200 || resource.status === 304);
}, 'Default user image');

test.assertResourceExists(function (resource) {
return resource.url.match(/user-cover\.png$/) && (resource.status === 200 || resource.status === 304);
}, 'Default cover image');


}, function onTimeOut() {
test.fail('User screen failed to load');
});
Expand Down

0 comments on commit a8e987e

Please sign in to comment.