Skip to content

Commit

Permalink
DEV: Lowercase all settings (#38)
Browse files Browse the repository at this point in the history
Why this change?

It isn't really in our convention to use uppercase characters in
settings so we are renaming the settings.
  • Loading branch information
tgxworld authored Jan 26, 2024
1 parent cc69e05 commit a766346
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 18 deletions.
16 changes: 10 additions & 6 deletions javascripts/discourse/components/custom-footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import Component from "@glimmer/component";
import { dasherize } from "@ember/string";

export default class extends Component {
mainHeading = settings.Heading;
blurb = settings.Blurb;
mainHeading = settings.heading;
blurb = settings.blurb;

linkArray = settings.Links.split("|")
linkArray = settings.links
.split("|")
.filter(Boolean)
.map((link) => {
const fragments = link.split(",").map((fragment) => fragment.trim());
Expand All @@ -26,7 +27,8 @@ export default class extends Component {
};
});

linkSections = settings.Link_sections.split("|")
linkSections = settings.link_sections
.split("|")
.filter(Boolean)
.map((section) => {
const fragments = section.split(",").map((fragment) => fragment.trim());
Expand All @@ -46,7 +48,8 @@ export default class extends Component {
};
});

smallLinks = settings.Small_links.split("|")
smallLinks = settings.small_links
.split("|")
.filter(Boolean)
.map((link) => {
const fragments = link.split(",").map((fragment) => fragment.trim());
Expand All @@ -63,7 +66,8 @@ export default class extends Component {
};
});

socialLinks = settings.Social_links.split("|")
socialLinks = settings.social_links
.split("|")
.filter(Boolean)
.map((link) => {
const fragments = link.split(",").map((fragment) => fragment.trim());
Expand Down
41 changes: 41 additions & 0 deletions migrations/settings/0001-rename-settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
export default function migrate(settings) {
if (settings.has("Heading")) {
settings.set("heading", settings.get("Heading"));
settings.delete("Heading");
}

if (settings.has("Blurb")) {
settings.set("blurb", settings.get("Blurb"));
settings.delete("Blurb");
}

if (settings.has("Link_sections")) {
settings.set("link_sections", settings.get("Link_sections"));
settings.delete("Link_sections");
}

if (settings.has("Links")) {
settings.set("links", settings.get("Links"));
settings.delete("Links");
}

if (settings.has("Small_links")) {
settings.set("small_links", settings.get("Small_links"));
settings.delete("Small_links");
}

if (settings.has("Social_links")) {
settings.set("social_links", settings.get("Social_links"));
settings.delete("Social_links");
}

if (settings.has("Show_footer_on_login_required_page")) {
settings.set(
"show_footer_on_login_required_page",
settings.get("Show_footer_on_login_required_page")
);
settings.delete("Show_footer_on_login_required_page");
}

return settings;
}
14 changes: 7 additions & 7 deletions settings.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
Heading:
heading:
default: "This is a header"
max: 25
description:
en: "Text for the heading in the footer - you can use your site name for example - Max length 25 characters"
Blurb:
blurb:
default: "Ius vitae ornatus at, ei mea sumo quot dicant. Ei tale democritum eos, in mea timeam accumsan forensibus. Ei his aperiam suavitate. Et debitis convenire sea, viris dictas latine."
max: 180
description:
en: "Enter a short blurb about your community - Max length 180 characters"
Link_sections:
link_sections:
type: list
list_type: simple
default: "Design, Get inspired!|Code, Learn new things!|Business, Start a new career!|Shop, Buy cool stuff!|Community, The latest news about the people you care about!|World, Check out what's happening"
description:
en: "Add link sections. The ideal number of sections is six. One item per line in this order:<br> Text, title<br><b>Text:</b> what appears on in the footer<br><b>Title:</b> the text that appears when the item is hovered."
Links:
links:
type: list
list_type: simple
default: "Design, Design process, #, blank, Learn the basics|Design, Blog design, #, blank, What makes for a great blog?|Design, Photoshop tutorials, #, blank, Photoshop for beginners|Design, Design trends, #, blank, Stay on top of the current trends!|Code, Wordpress, #, blank, Wordpress code examples|Code, Tools, #, blank, Tools that will make your life easier!|Code, Tutorials, #, blank, Just starting out? We'll guide you through the basics|Business, Blogging, #, blank, Why not start a blog?|Business, Social media, #, blank, Learn how to leverage Social media and make it work for your business|Business, Make money, #, blank, Everyone likes to be paid!|Business, Marketing, #, blank, No business will survive without customers...Here's how to get'em!|Shop, Vectors, #, blank, buy vectors|Shop, Textures, #, blank, buy textures|Shop, UI kits, #, blank, buy UI kits|Shop, PSDs, #, blank, Ready-made PSD's|Community, Your corner, #, blank, Tell us how you feel!|Community, Questions, #, blank, Feel like answering some questions?|Community, Members, #, blank, Say hi to new members|Community, trending, #, blank, Catch up with the latest trending topics!|World, Politics, #, blank, Stay up to date|World, Education, #, blank, The latest research|World, Automotive, #, blank, We cover the latest models!|World, Sports, #, The latest scores|World, Tech, #, Never miss a new gadget"
description:
en: "Add links to link sections. One item per line in this order:<br>Parent, text, URL, target, title<br>It is a good idea to keep the number of links under each section similar<br><b>Parent:</b> the name of the parent section which this link shows under. Use the `text` value from the list above<br><b>Text:</b> the text that shows for this link<br><b>URL:</b> the path this item links to. You can use relative paths as well.<br><b>Target:</b> Choose whether this item will open in a new tab or in the same tab. Use blank to open the link in a new tab, or use self to open it in the same tab.<br><b>Title:</b> the text that shows when the link is hovered."
Small_links:
small_links:
type: list
list_type: simple
default: "Privacy, #, self|Terms of service, #, self| About, #, self"
description:
en: "You can add small links at the bottom of the footer like Terms of Service and Privacy. One item per line in this order:<br>Text, URL, target<br><b>Text:</b> The text that shows for the small link<br><b>URL:</b> The path of the link<br><b>Target:</b> Use blank to open the link in a new tab and use self to open it in the same tab"
Social_links:
social_links:
type: list
list_type: simple
default: "Facebook, Join us on Facebook, #, blank,fab-facebook|Twitter, show some love on Twitter, #, blank,fab-twitter| Youtube, Check out our latest videos on Youtube, #, blank,fab-youtube"
description:
en: "Enter the social links you'd like to add to the footer in this format:<br> provider, title, URL, target<br><b>Provider:</b> is the name of the provider like Facebook or Twitter<br><b>Title:</b> The text that shows when the link is hovered<br><b>URL:</b> The path you'd like the link to have<br><b>Target:</b> Use blank to open the link in a new tab and use self to open it in the same tab<br><b>Icon:</b> use a FontAwesome5 icon name (brand icons need a 'fab-' prefix)."
Show_footer_on_login_required_page:
show_footer_on_login_required_page:
default: true
description:
en: "Check this setting if you want the footer to be displayed on the login-required page (only applies if your site is private)"
Expand Down
10 changes: 5 additions & 5 deletions spec/system/footer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
let!(:theme) { upload_theme_component }

it "should display the footer" do
theme.update_setting(:Link_sections, "Section 1, Section 1 title|Section 2, Section 2 title")
theme.update_setting(:link_sections, "Section 1, Section 1 title|Section 2, Section 2 title")
theme.update_setting(
:Links,
:links,
"Section 1, Section 1 Link, http://some.url.com/section1/link1, blank, Section 1 Link Title|Section 1, Section 1 Link 2, http://some.url.com/section1/link2, blank, Section 1 Link 2 Title|Section 2, Section 2 Link, http://some.url.com/section2/link1, blank, Section 2 Link Title|Section 2, Section 2 Link 2, http://some.url.com/section2/link2, blank, Section 2 Link 2 Title",
)
theme.save!

visit("/")

expect(page).to have_css(".below-footer-outlet.custom-footer")
expect(page).to have_css(".below-footer-outlet .heading", text: theme.get_setting(:Heading))
expect(page).to have_css(".below-footer-outlet .blurb", text: theme.get_setting(:Blurb))
expect(page).to have_css(".below-footer-outlet .heading", text: theme.get_setting(:heading))
expect(page).to have_css(".below-footer-outlet .blurb", text: theme.get_setting(:blurb))

within(".below-footer-outlet .links .list[data-easyfooter-section='section-1']") do
expect(page).to have_css("span[title='Section 1 title']", text: "Section 1")
Expand Down Expand Up @@ -77,7 +77,7 @@
it "should not display the footer to anon users when `Show_footer_on_login_required_page` is false" do
SiteSetting.login_required = true

theme.update_setting(:Show_footer_on_login_required_page, false)
theme.update_setting(:show_footer_on_login_required_page, false)
theme.save!

visit("/")
Expand Down
37 changes: 37 additions & 0 deletions test/unit/migrations/settings/0001-rename-settings-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { module, test } from "qunit";
import migrate from "../../../../migrations/settings/0001-rename-settings";

module("Unit | Migrations | Settings | 0001-rename-settings", function () {
test("migrate", function (assert) {
const settings = new Map(
Object.entries({
Heading: "some header",
Blurb: "some blurb",
Link_sections: "section1|section2",
Links: "some_links",
Small_links: "some,small,links",
Social_links: "some,social,links",
Show_footer_on_login_required_page: true,
})
);

const result = migrate(settings);

assert.deepEqual(
Array.from(result),
Array.from(
new Map(
Object.entries({
heading: "some header",
blurb: "some blurb",
link_sections: "section1|section2",
links: "some_links",
small_links: "some,small,links",
social_links: "some,social,links",
show_footer_on_login_required_page: true,
})
)
)
);
});
});

0 comments on commit a766346

Please sign in to comment.