Skip to content

Commit 44d8afc

Browse files
committed
🎨 Cleaned up helper promotion: removed redundant admin_url helper, moved tests, fixed gscan test
- Removed admin_url helper file (superseded by @site.admin_url data) - Moved json, color_to_rgba, contrast_text_color tests to helpers dir - Fixed gscan cross-reference test: tracks exact pending set so it fails if a new helper is added without updating gscan or the pending list - Added middleware test verifying admin_url in @site data
1 parent 758080d commit 44d8afc

7 files changed

Lines changed: 49 additions & 47 deletions

File tree

‎ghost/core/core/frontend/helpers/admin_url.js‎

Lines changed: 0 additions & 6 deletions
This file was deleted.

‎ghost/core/test/unit/frontend/helpers/admin-url.test.js‎

Lines changed: 0 additions & 17 deletions
This file was deleted.

ghost/core/test/unit/frontend/apps/private-blogging/color-to-rgba.test.js renamed to ghost/core/test/unit/frontend/helpers/color-to-rgba.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const assert = require('node:assert/strict');
2-
const {assertExists} = require('../../../../utils/assertions');
2+
const {assertExists} = require('../../../utils/assertions');
33

4-
const color_to_rgba = require('../../../../../core/frontend/helpers/color_to_rgba');
4+
const color_to_rgba = require('../../../../core/frontend/helpers/color_to_rgba');
55

66
describe('{{color_to_rgba}} helper', function () {
77
it('has color_to_rgba helper', function () {

ghost/core/test/unit/frontend/apps/private-blogging/contrast-text-color.test.js renamed to ghost/core/test/unit/frontend/helpers/contrast-text-color.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const assert = require('node:assert/strict');
2-
const {assertExists} = require('../../../../utils/assertions');
2+
const {assertExists} = require('../../../utils/assertions');
33

4-
const contrast_text_color = require('../../../../../core/frontend/helpers/contrast_text_color');
4+
const contrast_text_color = require('../../../../core/frontend/helpers/contrast_text_color');
55

66
describe('{{contrast_text_color}} helper', function () {
77
it('has contrast_text_color helper', function () {

ghost/core/test/unit/frontend/apps/private-blogging/json.test.js renamed to ghost/core/test/unit/frontend/helpers/json.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const assert = require('node:assert/strict');
22

3-
const json = require('../../../../../core/frontend/helpers/json');
3+
const json = require('../../../../core/frontend/helpers/json');
44

55
describe('{{json}} helper', function () {
66
it('serializes values safely for inline JSON', function () {

‎ghost/core/test/unit/frontend/services/theme-engine/handlebars/helpers.test.js‎

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const helpers = require('../../../../../../core/frontend/services/helpers');
1010
describe('Helpers', function () {
1111
const hbsHelpers = ['each', 'if', 'unless', 'with', 'helperMissing', 'blockHelperMissing', 'log', 'lookup', 'block', 'contentFor'];
1212
const ghostHelpers = [
13-
'admin_url', 'asset', 'authors', 'body_class', 'cancel_link', 'color_to_rgba', 'concat', 'content', 'content_api_key', 'content_api_url', 'contrast_text_color', 'date', 'encode', 'excerpt', 'facebook_url', 'foreach', 'get',
13+
'asset', 'authors', 'body_class', 'cancel_link', 'color_to_rgba', 'concat', 'content', 'content_api_key', 'content_api_url', 'contrast_text_color', 'date', 'encode', 'excerpt', 'facebook_url', 'foreach', 'get',
1414
'ghost_foot', 'ghost_head', 'has', 'img_url', 'is', 'json', 'link', 'link_class', 'meta_description', 'meta_title', 'navigation',
1515
'next_post', 'page_url', 'pagination', 'plural', 'post_class', 'prev_post', 'price', 'raw', 'reading_time', 'split', 't', 'tags', 'title','total_members', 'total_paid_members', 'twitter_url',
1616
'url', 'comment_count', 'collection', 'recommendations', 'readable_url', 'social_url'
@@ -37,23 +37,24 @@ describe('Helpers', function () {
3737
});
3838

3939
describe('gscan compatibility', function () {
40-
// Helpers that are intentionally NOT added to gscan's knownHelpers.
41-
// Each entry must have a comment explaining why it's excluded.
42-
// gscan already knows about 'search' via its own knownHelpers list — check
43-
// if there's a version mismatch. The remaining entries are intentionally excluded:
44-
const intentionallyExcluded = [
45-
'raw', // internal helper used by Ghost's own templates, not intended for theme developers
46-
'collection', // experimental helper, not yet stable enough for gscan enforcement
40+
// Ghost helpers that are not intended for theme developers and are
41+
// legitimately absent from gscan's knownHelpers.
42+
const internalHelpers = [
43+
'raw', // internal helper used by Ghost's own templates
44+
'collection', // experimental, not yet stable for themes
45+
'search' // experimental, not yet in gscan
46+
];
4747

48-
// The following helpers need gscan bumps (tracked separately):
49-
'admin_url', // new in this PR — gscan PR pending
50-
'json', // new in this PR — gscan PR pending
51-
'color_to_rgba', // new in this PR — gscan PR pending
52-
'contrast_text_color', // new in this PR — gscan PR pending
53-
'search' // pre-existing gap — gscan doesn't know about this helper yet
48+
// Helpers that are available for themes but gscan doesn't know about yet.
49+
// When gscan is updated, remove entries here — the test will fail if you
50+
// add a new helper without updating either this list or gscan.
51+
const pendingGscanUpdate = [
52+
'json',
53+
'color_to_rgba',
54+
'contrast_text_color'
5455
];
5556

56-
it('all global helpers should be known to gscan', function () {
57+
it('should track helpers not yet known to gscan', function () {
5758
const gscanSpec = require('gscan/lib/specs/v6');
5859
const gscanKnownHelpers = new Set(gscanSpec.knownHelpers);
5960

@@ -63,12 +64,15 @@ describe('Helpers', function () {
6364
.map(f => f.replace('.js', ''));
6465

6566
const missing = globalHelperFiles
66-
.filter(h => !intentionallyExcluded.includes(h))
67+
.filter(h => !internalHelpers.includes(h))
6768
.filter(h => !gscanKnownHelpers.has(h));
6869

69-
assert.deepEqual(missing, [],
70-
`Helpers in core/frontend/helpers/ but missing from gscan\'s knownHelpers: ${missing.join(', ')}. ` +
71-
'Either add them to gscan or add to intentionallyExcluded with a reason.'
70+
// This assertion ensures the missing set matches exactly what we expect.
71+
// If you add a new helper, it will fail until you either:
72+
// 1. Add it to gscan's knownHelpers (preferred), or
73+
// 2. Add it to pendingGscanUpdate with a tracking issue
74+
assert.deepEqual(missing.sort(), pendingGscanUpdate.sort(),
75+
'gscan helper mismatch. If you added a new helper, update gscan or add to pendingGscanUpdate.'
7276
);
7377
});
7478
});

‎ghost/core/test/unit/frontend/services/theme-engine/middleware.test.js‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,27 @@ describe('Themes middleware', function () {
211211
});
212212
});
213213

214+
describe('updateLocalTemplateOptions', function () {
215+
it('includes admin_url in site data', function (done) {
216+
executeMiddleware(middleware, req, res, function next(err) {
217+
try {
218+
assert.equal(err, undefined);
219+
220+
sinon.assert.calledOnce(hbsUpdateLocalTemplateOptionsStub);
221+
const templateOptions = hbsUpdateLocalTemplateOptionsStub.firstCall.args[1];
222+
const data = templateOptions.data;
223+
224+
assert(data.site.admin_url, 'admin_url should be set in site data');
225+
assert.equal(typeof data.site.admin_url, 'string');
226+
227+
done();
228+
} catch (error) {
229+
done(error);
230+
}
231+
});
232+
});
233+
});
234+
214235
describe('Preview Mode', function () {
215236
it('calls updateLocalTemplateOptions with correct data when one parameter is set', function (done) {
216237
const previewString = 'c=%23000fff';

0 commit comments

Comments
 (0)