Updated pageUrl helper to page_url

issue #2216
This commit is contained in:
Kyle Nunery 2014-02-19 14:17:43 -06:00
parent 7c2fd9fde8
commit 89cd1a3640
11 changed files with 114 additions and 47 deletions

View File

@ -7,6 +7,6 @@
</div>
<button class="button-save" type="submit">Log in</button>
<section class="meta">
<a class="forgotten-password" href="{{adminUrl}}/forgotten/">Forgotten password?</a>
<a class="forgotten-password" href="{{admin_url}}/forgotten/">Forgotten password?</a>
</section>
</form>

View File

@ -52,7 +52,7 @@
<div class="no-posts-box">
<div class="no-posts">
<h3>You Haven't Written Any Posts Yet!</h3>
<form action="{{adminUrl}}/editor/"><button class="button-add large" title="New Post">Write a new Post</button></form>
<form action="{{admin_url}}/editor/"><button class="button-add large" title="New Post">Write a new Post</button></form>
</div>
</div>
{{/unless}}

View File

@ -90,12 +90,12 @@ coreHelpers.encode = function (context, str) {
// ### Page URL Helper
//
// *Usage example:*
// `{{pageUrl 2}}`
// `{{page_url 2}}`
//
// Returns the URL for the page specified in the current object
// context.
//
coreHelpers.pageUrl = function (context, block) {
coreHelpers.page_url = function (context, block) {
/*jslint unparam:true*/
var url = config().paths.subdir;
@ -112,6 +112,25 @@ coreHelpers.pageUrl = function (context, block) {
return url;
};
// ### Page URL Helper: DEPRECATED
//
// *Usage example:*
// `{{pageUrl 2}}`
//
// Returns the URL for the page specified in the current object
// context. This helper is deprecated and will be removed in future versions.
//
coreHelpers.pageUrl = function (context, block) {
errors.logWarn('Warning: pageUrl is deprecated, please use page_url instead\n' +
'The helper pageUrl has been replaced with page_url in Ghost 0.5, and will be removed entirely in Ghost 0.6\n' +
'In your theme\'s pagination.hbs file, pageUrl should be renamed to page_url');
/*jslint unparam:true*/
var self = this;
return coreHelpers.page_url.call(self, context, block);
};
// ### URL helper
//
// *Usage example:*
@ -297,10 +316,10 @@ coreHelpers.excerpt = function (options) {
// ### Filestorage helper
//
// *Usage example:*
// `{{fileStorage}}`
// `{{file_storage}}`
//
// Returns the config value for fileStorage.
coreHelpers.fileStorage = function (context, options) {
coreHelpers.file_storage = function (context, options) {
/*jslint unparam:true*/
if (config().hasOwnProperty('fileStorage')) {
return config().fileStorage.toString();
@ -308,7 +327,7 @@ coreHelpers.fileStorage = function (context, options) {
return "true";
};
coreHelpers.ghostScriptTags = function () {
coreHelpers.ghost_script_tags = function () {
var scriptList = isProduction ? scriptFiles.production : scriptFiles.development;
scriptList = _.map(scriptList, function (fileName) {
@ -595,7 +614,7 @@ coreHelpers.helperMissing = function (arg) {
// ## Admin URL helper
// uses urlFor to generate a URL for either the admin or the frontend.
coreHelpers.adminUrl = function (options) {
coreHelpers.admin_url = function (options) {
var absolute = options && options.hash && options.hash.absolute,
// Ghost isn't a named route as currently it violates the must start-and-end with slash rule
context = !options || !options.hash || !options.hash.frontend ? {relativeUrl: '/ghost'} : 'home';
@ -603,7 +622,7 @@ coreHelpers.adminUrl = function (options) {
return config.urlFor(context, absolute);
};
coreHelpers.updateNotification = function (options) {
coreHelpers.update_notification = function (options) {
var output = '';
if (config().updateCheck === false || !this.currentUser) {
@ -683,6 +702,8 @@ registerHelpers = function (adminHbs, assetHash) {
registerThemeHelper('foreach', coreHelpers.foreach);
registerThemeHelper('page_url', coreHelpers.page_url);
registerThemeHelper('pageUrl', coreHelpers.pageUrl);
registerThemeHelper('pagination', coreHelpers.pagination);
@ -709,13 +730,13 @@ registerHelpers = function (adminHbs, assetHash) {
// Register admin helpers
registerAdminHelper('asset', coreHelpers.asset);
registerAdminHelper('ghostScriptTags', coreHelpers.ghostScriptTags);
registerAdminHelper('ghost_script_tags', coreHelpers.ghost_script_tags);
registerAdminHelper('fileStorage', coreHelpers.fileStorage);
registerAdminHelper('file_storage', coreHelpers.file_storage);
registerAdminHelper('adminUrl', coreHelpers.adminUrl);
registerAdminHelper('admin_url', coreHelpers.admin_url);
registerAsyncAdminHelper('updateNotification', coreHelpers.updateNotification);
registerAsyncAdminHelper('update_notification', coreHelpers.update_notification);
};
module.exports = coreHelpers;

View File

@ -1,9 +1,9 @@
<nav class="pagination" role="navigation">
{{#if prev}}
<a class="newer-posts" href="{{pageUrl prev}}">&larr; Newer Posts</a>
<a class="newer-posts" href="{{page_url prev}}">&larr; Newer Posts</a>
{{/if}}
<span class="page-number">Page {{page}} of {{pages}}</span>
{{#if next}}
<a class="older-posts" href="{{pageUrl next}}">Older Posts &rarr;</a>
<a class="older-posts" href="{{page_url next}}">Older Posts &rarr;</a>
{{/if}}
</nav>

View File

@ -5,7 +5,7 @@
<section class="content-filter">
<small>All Posts</small>
</section>
<a href="{{adminUrl}}/editor/" class="button button-add" title="New Post"><span class="hidden">New Post</span></a>
<a href="{{admin_url}}/editor/" class="button button-add" title="New Post"><span class="hidden">New Post</span></a>
</header>
<section class="content-list-content">
<ol></ol>

View File

@ -20,7 +20,7 @@
<fieldset>
<div class="form-group">
<label>Export</label>
<a href="{{adminUrl}}/api/v0.1/db/" class="button-save">Export</a>
<a href="{{admin_url}}/api/v0.1/db/" class="button-save">Export</a>
<p>Export the blog settings and data.</p>
</div>
</fieldset>

View File

@ -31,13 +31,13 @@
<link rel="stylesheet" href="{{asset "css/screen.css" ghost="true"}}">
{{{block "pageStyles"}}}
</head>
<body class="{{bodyClass}}{{updateNotification classOnly="true"}}">
<body class="{{bodyClass}}{{update_notification classOnly="true"}}">
{{#unless hideNavbar}}
{{> navbar}}
{{/unless}}
<main role="main" id="main">
{{updateNotification}}
{{update_notification}}
<aside id="notifications" class="notifications">
{{> notifications}}
@ -50,7 +50,7 @@
</div>
<div class="modal-background fade"></div>
{{{ghostScriptTags}}}
{{{ghost_script_tags}}}
{{{block "bodyScripts"}}}
</body>

View File

@ -13,7 +13,7 @@
<small>Markdown</small>
<a class="markdown-help" href="#"><span class="hidden">What is Markdown?</span></a>
</header>
<section id="entry-markdown-content" class="entry-markdown-content" data-filestorage={{fileStorage}}>
<section id="entry-markdown-content" class="entry-markdown-content" data-filestorage={{file_storage}}>
<textarea id="entry-markdown"></textarea>
</section>
</section>{{!.entry-markdown}}

View File

@ -1,11 +1,11 @@
<header id="global-header" class="navbar">
<a class="ghost-logo" href="{{adminUrl absolute="true" frontend="true"}}" data-off-canvas="left" title="{{adminUrl absolute="true" frontend="true"}}">
<a class="ghost-logo" href="{{admin_url absolute="true" frontend="true"}}" data-off-canvas="left" title="{{admin_url absolute="true" frontend="true"}}">
<span class="hidden">Ghost </span>
</a>
<nav id="global-nav" role="navigation">
<ul id="main-menu" >
{{#each adminNav}}
<li class="{{navClass}}{{#if selected}} active{{/if}}"><a href="{{adminUrl}}{{path}}">{{name}}</a></li>
<li class="{{navClass}}{{#if selected}} active{{/if}}"><a href="{{admin_url}}{{path}}">{{name}}</a></li>
{{/each}}
<li id="usermenu" class="usermenu subnav">
@ -14,11 +14,11 @@
<span class="name">{{#if currentUser.name}}{{currentUser.name}}{{else}}{{currentUser.email}}{{/if}}</span>
</a>
<ul class="overlay">
<li class="usermenu-profile"><a href="{{adminUrl}}/settings/user/">Your Profile</a></li>
<li class="usermenu-profile"><a href="{{admin_url}}/settings/user/">Your Profile</a></li>
<li class="divider"></li>
<li class="usermenu-help"><a href="http://ghost.org/forum/">Help / Support</a></li>
<li class="divider"></li>
<li class="usermenu-signout"><a href="{{adminUrl}}/signout/">Sign Out</a></li>
<li class="usermenu-signout"><a href="{{admin_url}}/signout/">Sign Out</a></li>
</ul>
</li>
</ul>

View File

@ -4,5 +4,5 @@
</aside>
<section class="settings-content" data-filestorage={{fileStorage}}></section>
<section class="settings-content" data-filestorage={{file_storage}}></section>
</div>

View File

@ -471,8 +471,54 @@ describe('Core Helpers', function () {
});
});
});
describe('Page Url Helper', function () {
it('has loaded page_url helper', function () {
should.exist(handlebars.helpers.page_url);
});
it('can return a valid url', function () {
helpers.page_url(1).should.equal('/');
helpers.page_url(2).should.equal('/page/2/');
helpers.page_url(50).should.equal('/page/50/');
});
it('can return a valid url with subdirectory', function () {
helpers.__set__('config', function() {
return {
paths: {'subdir': '/blog'}
};
});
helpers.page_url(1).should.equal('/blog/');
helpers.page_url(2).should.equal('/blog/page/2/');
helpers.page_url(50).should.equal('/blog/page/50/');
});
it('can return a valid url for tag pages', function () {
var tagContext = {
tagSlug: 'pumpkin'
};
helpers.page_url.call(tagContext, 1).should.equal('/tag/pumpkin/');
helpers.page_url.call(tagContext, 2).should.equal('/tag/pumpkin/page/2/');
helpers.page_url.call(tagContext, 50).should.equal('/tag/pumpkin/page/50/');
});
it('can return a valid url for tag pages with subdirectory', function () {
helpers.__set__('config', function() {
return {
paths: {'subdir': '/blog'}
};
});
var tagContext = {
tagSlug: 'pumpkin'
};
helpers.page_url.call(tagContext, 1).should.equal('/blog/tag/pumpkin/');
helpers.page_url.call(tagContext, 2).should.equal('/blog/tag/pumpkin/page/2/');
helpers.page_url.call(tagContext, 50).should.equal('/blog/tag/pumpkin/page/50/');
});
});
describe('Page Url Helper: DEPRECATED', function () {
it('has loaded pageUrl helper', function () {
should.exist(handlebars.helpers.pageUrl);
});
@ -886,11 +932,11 @@ describe('Core Helpers', function () {
});
it('has loaded ghostScriptTags helper', function () {
should.exist(helpers.ghostScriptTags);
should.exist(helpers.ghost_script_tags);
});
it('outputs correct scripts for development mode', function () {
rendered = helpers.ghostScriptTags();
rendered = helpers.ghost_script_tags();
should.exist(rendered);
String(rendered).should.equal(
'<script src="/ghost/scripts/vendor.js?v=abc"></script>' +
@ -905,7 +951,7 @@ describe('Core Helpers', function () {
});
// with subdirectory
rendered = helpers.ghostScriptTags();
rendered = helpers.ghost_script_tags();
should.exist(rendered);
String(rendered).should.equal(
'<script src="/blog/ghost/scripts/vendor.js?v=abc"></script>' +
@ -920,7 +966,7 @@ describe('Core Helpers', function () {
helpers.__set__('isProduction', true);
rendered = helpers.ghostScriptTags();
rendered = helpers.ghost_script_tags();
should.exist(rendered);
String(rendered).should.equal('<script src="/ghost/scripts/ghost.min.js?v=abc"></script>');
@ -929,7 +975,7 @@ describe('Core Helpers', function () {
});
// with subdirectory
rendered = helpers.ghostScriptTags();
rendered = helpers.ghost_script_tags();
should.exist(rendered);
String(rendered).should.equal('<script src="/blog/ghost/scripts/ghost.min.js?v=abc"></script>');
});
@ -945,14 +991,14 @@ describe('Core Helpers', function () {
it('should output the path to admin', function () {
rendered = helpers.adminUrl();
rendered = helpers.admin_url();
should.exist(rendered);
rendered.should.equal('/ghost');
});
it('should output the path to admin with subdirectory', function () {
configUpdate({url: 'http://testurl.com/blog/'});
rendered = helpers.adminUrl();
rendered = helpers.admin_url();
should.exist(rendered);
rendered.should.equal('/blog/ghost');
});
@ -961,26 +1007,26 @@ describe('Core Helpers', function () {
// no trailing slash
configUpdate({url: 'http://testurl.com'});
rendered = helpers.adminUrl({"hash": {absolute: true}});
rendered = helpers.admin_url({"hash": {absolute: true}});
should.exist(rendered);
rendered.should.equal('http://testurl.com/ghost');
// test trailing slash
configUpdate({url: 'http://testurl.com/'});
rendered = helpers.adminUrl({"hash": {absolute: true}});
rendered = helpers.admin_url({"hash": {absolute: true}});
should.exist(rendered);
rendered.should.equal('http://testurl.com/ghost');
});
it('should output absolute path with subdirectory', function () {
configUpdate({url: 'http://testurl.com/blog'});
rendered = helpers.adminUrl({"hash": {absolute: true}});
rendered = helpers.admin_url({"hash": {absolute: true}});
should.exist(rendered);
rendered.should.equal('http://testurl.com/blog/ghost');
});
it('should output the path to frontend if frontend is set', function () {
rendered = helpers.adminUrl({"hash": {frontend: true}});
rendered = helpers.admin_url({"hash": {frontend: true}});
should.exist(rendered);
rendered.should.equal('/');
});
@ -988,26 +1034,26 @@ describe('Core Helpers', function () {
it('should output the absolute path to frontend if both are set', function () {
configUpdate({url: 'http://testurl.com'});
rendered = helpers.adminUrl({"hash": {frontend: true, absolute: true}});
rendered = helpers.admin_url({"hash": {frontend: true, absolute: true}});
should.exist(rendered);
rendered.should.equal('http://testurl.com/');
configUpdate({url: 'http://testurl.com/'});
rendered = helpers.adminUrl({"hash": {frontend: true, absolute: true}});
rendered = helpers.admin_url({"hash": {frontend: true, absolute: true}});
should.exist(rendered);
rendered.should.equal('http://testurl.com/');
});
it('should output the path to frontend with subdirectory', function () {
configUpdate({url: 'http://testurl.com/blog/'});
rendered = helpers.adminUrl({"hash": {frontend: true}});
rendered = helpers.admin_url({"hash": {frontend: true}});
should.exist(rendered);
rendered.should.equal('/blog/');
});
it('should output the absolute path to frontend with subdirectory', function () {
configUpdate({url: 'http://testurl.com/blog/'});
rendered = helpers.adminUrl({"hash": {frontend: true, absolute: true}});
rendered = helpers.admin_url({"hash": {frontend: true, absolute: true}});
should.exist(rendered);
rendered.should.equal('http://testurl.com/blog/');
});
@ -1026,13 +1072,13 @@ describe('Core Helpers', function () {
return when({value: futureversion.join('.')});
});
helpers.updateNotification.call({currentUser: {name: 'bob'}}).then(function (rendered) {
helpers.update_notification.call({currentUser: {name: 'bob'}}).then(function (rendered) {
should.exist(rendered);
rendered.should.equal(defaultOutput);
// Test classOnly option
return helpers.updateNotification.call({currentUser: {name: 'bob'}}, {'hash': {'classOnly': 'true'}});
return helpers.update_notification.call({currentUser: {name: 'bob'}}, {'hash': {'classOnly': 'true'}});
}).then(function (rendered) {
should.exist(rendered);
@ -1048,7 +1094,7 @@ describe('Core Helpers', function () {
return when({value: packageInfo.version});
});
helpers.updateNotification.call({currentUser: {name: 'bob'}}).then(function (rendered) {
helpers.update_notification.call({currentUser: {name: 'bob'}}).then(function (rendered) {
should.exist(rendered);
rendered.should.equal('');
done();
@ -1063,7 +1109,7 @@ describe('Core Helpers', function () {
return when({value: 'true'});
});
helpers.updateNotification.call({currentUser: {name: 'bob'}}).then(function (rendered) {
helpers.update_notification.call({currentUser: {name: 'bob'}}).then(function (rendered) {
should.exist(rendered);
rendered.should.equal('');
done();
@ -1078,7 +1124,7 @@ describe('Core Helpers', function () {
return when({value: futureversion.join('.')});
});
helpers.updateNotification.call().then(function (rendered) {
helpers.update_notification.call().then(function (rendered) {
should.exist(rendered);
rendered.should.equal('');
done();