Skip to content

Commit

Permalink
Support colour background for think-cell (compiler-explorer#6223)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattgodbolt authored Mar 6, 2024
1 parent d392f13 commit b658e25
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions etc/config/sponsors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ levels:
topIconShowEvery: 3
displayType: SideBySide
statsId: thinkcell
bgColour: rgb(110, 166, 0)
- name: Patreon Legends
description: 'These amazing people have pledged at the highest level of support. Huge thanks to these fine folks:'
class: legendary
Expand Down
1 change: 1 addition & 0 deletions lib/sponsors.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export type Sponsor = {
topIconShowEvery: number;
displayType: DisplayType;
statsId?: string;
style: Record<string, string>;
};

export type Level = {
Expand Down
5 changes: 5 additions & 0 deletions lib/sponsors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ import type {Level, Sponsor, Sponsors} from './sponsors.interfaces.js';
export function parse(mapOrString: Record<string, any> | string): Sponsor {
if (typeof mapOrString == 'string') mapOrString = {name: mapOrString};
const displayType = mapOrString.displayType || 'Above';
const style = {};
if (mapOrString.bgColour) {
style['background-color'] = mapOrString.bgColour;
}
return {
name: mapOrString.name,
description: typeof mapOrString.description === 'string' ? [mapOrString.description] : mapOrString.description,
Expand All @@ -41,6 +45,7 @@ export function parse(mapOrString: Record<string, any> | string): Sponsor {
displayType: displayType,
priority: mapOrString.priority || 0,
statsId: mapOrString.statsId,
style: style,
};
}

Expand Down
5 changes: 3 additions & 2 deletions test/sponsors-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ describe('Sponsors', () => {
obj.topIconShowEvery.should.eq(0);
obj.displayType.should.eq('Above');
should.equal(obj.statsId, undefined);
obj.style.should.deep.equal({});
});
it('should make descriptions always one-sized arrays', () => {
unwrap(parse({name: 'moo', description: 'desc'}).description).should.deep.eq(['desc']);
Expand All @@ -67,8 +68,8 @@ describe('Sponsors', () => {
it('should pick dark icons if specified', () => {
unwrap(parse({name: 'bob', icon: 'icon', icon_dark: 'icon_dark'}).icon_dark).should.eq('icon_dark');
});
it('should handle topIcons', () => {
parse({name: 'bob', topIconShowEvery: 2}).topIconShowEvery.should.eq(2);
it('should handle styles', () => {
parse({name: 'bob', bgColour: 'red'}).style.should.deep.eq({'background-color': 'red'});
});
it('should handle clicks', () => {
parse({
Expand Down
2 changes: 1 addition & 1 deletion views/bits/sponsors-content.pug
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ block content
.ces-top
each sponsor in level.sponsors
.ces
button.btn-block.btn-secondary(title=sponsor.title onclick=sponsor.onclick disabled=!sponsor.url)
button.btn-block.btn-secondary(title=sponsor.title onclick=sponsor.onclick disabled=!sponsor.url style=sponsor.style)
if sponsor.displayType === 'SideBySide'
.d-flex
.ces-item-title
Expand Down

0 comments on commit b658e25

Please sign in to comment.