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> </div>
<button class="button-save" type="submit">Log in</button> <button class="button-save" type="submit">Log in</button>
<section class="meta"> <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> </section>
</form> </form>

View File

@ -52,7 +52,7 @@
<div class="no-posts-box"> <div class="no-posts-box">
<div class="no-posts"> <div class="no-posts">
<h3>You Haven't Written Any Posts Yet!</h3> <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>
</div> </div>
{{/unless}} {{/unless}}

View File

@ -90,12 +90,12 @@ coreHelpers.encode = function (context, str) {
// ### Page URL Helper // ### Page URL Helper
// //
// *Usage example:* // *Usage example:*
// `{{pageUrl 2}}` // `{{page_url 2}}`
// //
// Returns the URL for the page specified in the current object // Returns the URL for the page specified in the current object
// context. // context.
// //
coreHelpers.pageUrl = function (context, block) { coreHelpers.page_url = function (context, block) {
/*jslint unparam:true*/ /*jslint unparam:true*/
var url = config().paths.subdir; var url = config().paths.subdir;
@ -112,6 +112,25 @@ coreHelpers.pageUrl = function (context, block) {
return url; 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 // ### URL helper
// //
// *Usage example:* // *Usage example:*
@ -297,10 +316,10 @@ coreHelpers.excerpt = function (options) {
// ### Filestorage helper // ### Filestorage helper
// //
// *Usage example:* // *Usage example:*
// `{{fileStorage}}` // `{{file_storage}}`
// //
// Returns the config value for fileStorage. // Returns the config value for fileStorage.
coreHelpers.fileStorage = function (context, options) { coreHelpers.file_storage = function (context, options) {
/*jslint unparam:true*/ /*jslint unparam:true*/
if (config().hasOwnProperty('fileStorage')) { if (config().hasOwnProperty('fileStorage')) {
return config().fileStorage.toString(); return config().fileStorage.toString();
@ -308,7 +327,7 @@ coreHelpers.fileStorage = function (context, options) {
return "true"; return "true";
}; };
coreHelpers.ghostScriptTags = function () { coreHelpers.ghost_script_tags = function () {
var scriptList = isProduction ? scriptFiles.production : scriptFiles.development; var scriptList = isProduction ? scriptFiles.production : scriptFiles.development;
scriptList = _.map(scriptList, function (fileName) { scriptList = _.map(scriptList, function (fileName) {
@ -595,7 +614,7 @@ coreHelpers.helperMissing = function (arg) {
// ## Admin URL helper // ## Admin URL helper
// uses urlFor to generate a URL for either the admin or the frontend. // 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, 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 // 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'; context = !options || !options.hash || !options.hash.frontend ? {relativeUrl: '/ghost'} : 'home';
@ -603,7 +622,7 @@ coreHelpers.adminUrl = function (options) {
return config.urlFor(context, absolute); return config.urlFor(context, absolute);
}; };
coreHelpers.updateNotification = function (options) { coreHelpers.update_notification = function (options) {
var output = ''; var output = '';
if (config().updateCheck === false || !this.currentUser) { if (config().updateCheck === false || !this.currentUser) {
@ -683,6 +702,8 @@ registerHelpers = function (adminHbs, assetHash) {
registerThemeHelper('foreach', coreHelpers.foreach); registerThemeHelper('foreach', coreHelpers.foreach);
registerThemeHelper('page_url', coreHelpers.page_url);
registerThemeHelper('pageUrl', coreHelpers.pageUrl); registerThemeHelper('pageUrl', coreHelpers.pageUrl);
registerThemeHelper('pagination', coreHelpers.pagination); registerThemeHelper('pagination', coreHelpers.pagination);
@ -709,13 +730,13 @@ registerHelpers = function (adminHbs, assetHash) {
// Register admin helpers // Register admin helpers
registerAdminHelper('asset', coreHelpers.asset); 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; module.exports = coreHelpers;

View File

@ -1,9 +1,9 @@
<nav class="pagination" role="navigation"> <nav class="pagination" role="navigation">
{{#if prev}} {{#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}} {{/if}}
<span class="page-number">Page {{page}} of {{pages}}</span> <span class="page-number">Page {{page}} of {{pages}}</span>
{{#if next}} {{#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}} {{/if}}
</nav> </nav>

View File

@ -5,7 +5,7 @@
<section class="content-filter"> <section class="content-filter">
<small>All Posts</small> <small>All Posts</small>
</section> </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> </header>
<section class="content-list-content"> <section class="content-list-content">
<ol></ol> <ol></ol>

View File

@ -20,7 +20,7 @@
<fieldset> <fieldset>
<div class="form-group"> <div class="form-group">
<label>Export</label> <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> <p>Export the blog settings and data.</p>
</div> </div>
</fieldset> </fieldset>

View File

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

View File

@ -13,7 +13,7 @@
<small>Markdown</small> <small>Markdown</small>
<a class="markdown-help" href="#"><span class="hidden">What is Markdown?</span></a> <a class="markdown-help" href="#"><span class="hidden">What is Markdown?</span></a>
</header> </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> <textarea id="entry-markdown"></textarea>
</section> </section>
</section>{{!.entry-markdown}} </section>{{!.entry-markdown}}

View File

@ -1,11 +1,11 @@
<header id="global-header" class="navbar"> <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> <span class="hidden">Ghost </span>
</a> </a>
<nav id="global-nav" role="navigation"> <nav id="global-nav" role="navigation">
<ul id="main-menu" > <ul id="main-menu" >
{{#each adminNav}} {{#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}} {{/each}}
<li id="usermenu" class="usermenu subnav"> <li id="usermenu" class="usermenu subnav">
@ -14,11 +14,11 @@
<span class="name">{{#if currentUser.name}}{{currentUser.name}}{{else}}{{currentUser.email}}{{/if}}</span> <span class="name">{{#if currentUser.name}}{{currentUser.name}}{{else}}{{currentUser.email}}{{/if}}</span>
</a> </a>
<ul class="overlay"> <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="divider"></li>
<li class="usermenu-help"><a href="http://ghost.org/forum/">Help / Support</a></li> <li class="usermenu-help"><a href="http://ghost.org/forum/">Help / Support</a></li>
<li class="divider"></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> </ul>
</li> </li>
</ul> </ul>

View File

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

View File

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