Commit c401c9d7 by Joffrey JAFFEUX

initial commit

parents
{
"extends": "eslint-config-discourse",
"globals": {
"settings": "readonly",
"themePrefix": "readonly"
}
}
.discourse-site
node_modules
HELP
module.exports = {
plugins: ["ember-template-lint-plugin-discourse"],
extends: "discourse:recommended",
};
Copyright 2024 joffreyjaffeux
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
{
"about_url": "Put your theme's public repo or Meta topic URL here",
"license_url": "Put your theme's LICENSE URL here",
"assets": {},
"name": "discourse-custom-logo-link",
"component": true
}
import { apiInitializer } from "discourse/lib/api";
import getURL from "discourse-common/lib/get-url";
export default apiInitializer("1.8.0", (api) => {
api.registerHomeLogoHrefCallback(() => {
const site = api.container.lookup("service:site");
const user = api.getCurrentUser();
let url;
if (site.desktopView) {
url = user ? settings.logged_in_desktop_url : settings.desktop_url;
} else {
url = user ? settings.logged_in_mobile_url : settings.mobile_url;
}
if (!url.length) {
return getURL("/");
}
if (user) {
url = url.replace("$username", user.username);
url = url.replace("$user_id", user.id);
}
return url;
});
});
en:
theme_metadata:
description: "Allows to define a custom logo link on desktop and on mobile."
settings:
desktop_url: "The URL to link the logo to on desktop for anonymous users."
mobile_url: "The URL to link the logo to on desktop for anonymous users."
logged_in_desktop_url: "The URL to link the logo to on desktop for logged in users. Accepts the following tokets to interpolate: $username, $user_id."
logged_in_mobile_url: "The URL to link the logo to on desktop for logged in users. Accepts the following tokets to interpolate: $username, $user_id."
{
"author": "joffreyjaffeux",
"license": "MIT",
"devDependencies": {
"eslint-config-discourse": "latest"
}
}
desktop_url:
default: ""
mobile_url:
default: ""
logged_in_desktop_url:
default: ""
logged_in_mobile_url:
default: ""
RSpec.describe "Discourse custom logo link", system: true do
let(:theme) { Fabricate(:theme) }
let!(:component) { upload_theme_component(parent_theme_id: theme.id) }
before { theme.set_default! }
context "with anonymous user" do
context "when on desktop" do
context "when the desktop_url is set" do
before do
component.update_setting(:desktop_url, "http://www.example.com")
component.save!
end
it "uses the desktop_url" do
visit("/")
expect(page.find(".home-logo-wrapper-outlet")).to have_link(
href: "http://www.example.com",
)
end
end
context "when the desktop_url is not set" do
it "defaults to root" do
visit("/")
expect(page.find(".home-logo-wrapper-outlet")).to have_link(href: "/")
end
end
end
context "when on mobile", mobile: true do
context "when the mobile_url is set" do
before do
component.update_setting(:mobile_url, "http://www.example.com")
component.save!
end
it "uses the mobile_url" do
visit("/")
expect(page.find(".home-logo-wrapper-outlet")).to have_link(
href: "http://www.example.com",
)
end
end
context "when the mobile_url is not set" do
it "defaults to root" do
visit("/")
expect(page.find(".home-logo-wrapper-outlet")).to have_link(href: "/")
end
end
end
end
context "with logged in user" do
fab!(:user)
before { sign_in(user) }
context "when on desktop" do
context "when the logged_in_desktop_url is set" do
before do
component.update_setting(:logged_in_desktop_url, "http://www.example.com")
component.save!
end
it "uses the logged_in_desktop_url" do
visit("/")
expect(page.find(".home-logo-wrapper-outlet")).to have_link(
href: "http://www.example.com",
)
end
context "when using tokens" do
before do
component.update_setting(
:logged_in_desktop_url,
"http://www.example.com/$username/$user_id",
)
component.save!
end
it "interpolates tokens" do
visit("/")
expect(page.find(".home-logo-wrapper-outlet")).to have_link(
href: "http://www.example.com/#{user.username}/#{user.id}",
)
end
end
end
context "when the logged_in_desktop_url is not set" do
it "defaults to root" do
visit("/")
expect(page.find(".home-logo-wrapper-outlet")).to have_link(href: "/")
end
end
end
context "when on mobile", mobile: true do
context "when the logged_in_mobile_url is set" do
before do
component.update_setting(:logged_in_mobile_url, "http://www.example.com")
component.save!
end
it "uses the logged_in_mobile_url" do
visit("/")
expect(page.find(".home-logo-wrapper-outlet")).to have_link(
href: "http://www.example.com",
)
end
context "when using tokens" do
before do
component.update_setting(
:logged_in_mobile_url,
"http://www.example.com/$username/$user_id",
)
component.save!
end
it "interpolates tokens" do
visit("/")
expect(page.find(".home-logo-wrapper-outlet")).to have_link(
href: "http://www.example.com/#{user.username}/#{user.id}",
)
end
end
end
context "when the logged_in_mobile_url is not set" do
it "defaults to root" do
visit("/")
expect(page.find(".home-logo-wrapper-outlet")).to have_link(href: "/")
end
end
end
end
end
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment