DEV: Apply syntax_tree formatting to lib/*

This commit is contained in:
David Taylor
2023-01-09 12:10:19 +00:00
parent b0fda61a8e
commit 6417173082
507 changed files with 16550 additions and 12627 deletions

View File

@@ -2,7 +2,6 @@
class Wizard
class Builder
def initialize(user)
@wizard = Wizard.new(user)
end
@@ -10,18 +9,31 @@ class Wizard
def build
return @wizard unless SiteSetting.wizard_enabled? && @wizard.user.try(:staff?)
@wizard.append_step('introduction') do |step|
@wizard.append_step("introduction") do |step|
step.banner = "welcome-illustration"
step.emoji = "wave"
step.description_vars = { base_path: Discourse.base_path }
step.add_field(id: 'title', type: 'text', required: true, value: SiteSetting.title == SiteSetting.defaults[:title] ? "" : SiteSetting.title)
step.add_field(id: 'site_description', type: 'text', required: false, value: SiteSetting.site_description)
step.add_field(
id: "title",
type: "text",
required: true,
value: SiteSetting.title == SiteSetting.defaults[:title] ? "" : SiteSetting.title,
)
step.add_field(
id: "site_description",
type: "text",
required: false,
value: SiteSetting.site_description,
)
languages = step.add_field(id: 'default_locale',
type: 'dropdown',
required: false,
value: SiteSetting.default_locale)
languages =
step.add_field(
id: "default_locale",
type: "dropdown",
required: false,
value: SiteSetting.default_locale,
)
LocaleSiteSetting.values.each do |locale|
languages.add_choice(locale[:value], label: locale[:name])
@@ -30,9 +42,7 @@ class Wizard
step.on_update do |updater|
updater.ensure_changed(:title)
if updater.errors.blank?
updater.apply_settings(:title, :site_description)
end
updater.apply_settings(:title, :site_description) if updater.errors.blank?
old_locale = SiteSetting.default_locale
updater.apply_setting(:default_locale)
@@ -48,44 +58,44 @@ class Wizard
end
end
@wizard.append_step('privacy') do |step|
@wizard.append_step("privacy") do |step|
step.banner = "members-illustration"
step.emoji = "hugs"
step.add_field(
id: 'login_required',
type: 'checkbox',
icon: 'unlock',
value: SiteSetting.login_required
id: "login_required",
type: "checkbox",
icon: "unlock",
value: SiteSetting.login_required,
)
step.add_field(
id: 'invite_only',
type: 'checkbox',
icon: 'user-plus',
value: SiteSetting.invite_only
id: "invite_only",
type: "checkbox",
icon: "user-plus",
value: SiteSetting.invite_only,
)
step.add_field(
id: 'must_approve_users',
type: 'checkbox',
icon: 'user-shield',
value: SiteSetting.must_approve_users
id: "must_approve_users",
type: "checkbox",
icon: "user-shield",
value: SiteSetting.must_approve_users,
)
if defined?(::Chat)
step.add_field(
id: 'chat_enabled',
type: 'checkbox',
icon: 'comment',
value: SiteSetting.chat_enabled
id: "chat_enabled",
type: "checkbox",
icon: "comment",
value: SiteSetting.chat_enabled,
)
end
step.add_field(
id: 'enable_sidebar',
type: 'checkbox',
icon: 'bars',
value: SiteSetting.navigation_menu == NavigationMenuSiteSetting::SIDEBAR
id: "enable_sidebar",
type: "checkbox",
icon: "bars",
value: SiteSetting.navigation_menu == NavigationMenuSiteSetting::SIDEBAR,
)
step.on_update do |updater|
@@ -97,27 +107,27 @@ class Wizard
end
end
@wizard.append_step('ready') do |step|
@wizard.append_step("ready") do |step|
# no form on this page, just info.
step.banner = "finished-illustration"
step.emoji = "rocket"
end
@wizard.append_step('branding') do |step|
@wizard.append_step("branding") do |step|
step.emoji = "framed_picture"
step.add_field(id: 'logo', type: 'image', value: SiteSetting.site_logo_url)
step.add_field(id: 'logo_small', type: 'image', value: SiteSetting.site_logo_small_url)
step.add_field(id: "logo", type: "image", value: SiteSetting.site_logo_url)
step.add_field(id: "logo_small", type: "image", value: SiteSetting.site_logo_small_url)
step.on_update do |updater|
if SiteSetting.site_logo_url != updater.fields[:logo] ||
SiteSetting.site_logo_small_url != updater.fields[:logo_small]
SiteSetting.site_logo_small_url != updater.fields[:logo_small]
updater.apply_settings(:logo, :logo_small)
updater.refresh_required = true
end
end
end
@wizard.append_step('styling') do |step|
@wizard.append_step("styling") do |step|
step.emoji = "art"
default_theme = Theme.find_by(id: SiteSetting.default_theme_id)
default_theme_override = SiteSetting.exists?(name: "default_theme_id")
@@ -125,15 +135,17 @@ class Wizard
base_scheme = default_theme&.color_scheme&.base_scheme_id
color_scheme_name = default_theme&.color_scheme&.name
scheme_id = default_theme_override ? (base_scheme || color_scheme_name) : ColorScheme::LIGHT_THEME_ID
scheme_id =
default_theme_override ? (base_scheme || color_scheme_name) : ColorScheme::LIGHT_THEME_ID
themes = step.add_field(
id: 'color_scheme',
type: 'dropdown',
required: !default_theme_override,
value: scheme_id || ColorScheme::LIGHT_THEME_ID,
show_in_sidebar: true
)
themes =
step.add_field(
id: "color_scheme",
type: "dropdown",
required: !default_theme_override,
value: scheme_id || ColorScheme::LIGHT_THEME_ID,
show_in_sidebar: true,
)
# fix for the case when base_scheme is nil
if scheme_id && default_theme_override && base_scheme.nil?
@@ -145,102 +157,116 @@ class Wizard
themes.add_choice(t[:id], data: { colors: t[:colors] })
end
body_font = step.add_field(
id: 'body_font',
type: 'dropdown',
value: SiteSetting.base_font,
show_in_sidebar: true
)
body_font =
step.add_field(
id: "body_font",
type: "dropdown",
value: SiteSetting.base_font,
show_in_sidebar: true,
)
heading_font = step.add_field(
id: 'heading_font',
type: 'dropdown',
value: SiteSetting.heading_font,
show_in_sidebar: true
)
heading_font =
step.add_field(
id: "heading_font",
type: "dropdown",
value: SiteSetting.heading_font,
show_in_sidebar: true,
)
DiscourseFonts.fonts.each do |font|
body_font.add_choice(font[:key], label: font[:name])
heading_font.add_choice(font[:key], label: font[:name])
end
current = SiteSetting.top_menu.starts_with?("categories") ? SiteSetting.desktop_category_page_style : "latest"
style = step.add_field(id: 'homepage_style', type: 'dropdown', required: false, value: current, show_in_sidebar: true)
style.add_choice('latest')
CategoryPageStyle.values.each do |page|
style.add_choice(page[:value])
end
current =
(
if SiteSetting.top_menu.starts_with?("categories")
SiteSetting.desktop_category_page_style
else
"latest"
end
)
style =
step.add_field(
id: "homepage_style",
type: "dropdown",
required: false,
value: current,
show_in_sidebar: true,
)
style.add_choice("latest")
CategoryPageStyle.values.each { |page| style.add_choice(page[:value]) }
step.add_field(
id: 'styling_preview',
type: 'component'
)
step.add_field(id: "styling_preview", type: "component")
step.on_update do |updater|
updater.update_setting(:base_font, updater.fields[:body_font])
updater.update_setting(:heading_font, updater.fields[:heading_font])
top_menu = SiteSetting.top_menu.split("|")
if updater.fields[:homepage_style] == 'latest' && top_menu[0] != "latest"
if updater.fields[:homepage_style] == "latest" && top_menu[0] != "latest"
top_menu.delete("latest")
top_menu.insert(0, "latest")
elsif updater.fields[:homepage_style] != 'latest'
elsif updater.fields[:homepage_style] != "latest"
top_menu.delete("categories")
top_menu.insert(0, "categories")
updater.update_setting(:desktop_category_page_style, updater.fields[:homepage_style])
end
updater.update_setting(:top_menu, top_menu.join("|"))
scheme_name = (
(updater.fields[:color_scheme] || "") ||
ColorScheme::LIGHT_THEME_ID
)
scheme_name = ((updater.fields[:color_scheme] || "") || ColorScheme::LIGHT_THEME_ID)
next unless scheme_name.present? && ColorScheme.is_base?(scheme_name)
name = I18n.t("color_schemes.#{scheme_name.downcase.gsub(' ', '_')}_theme_name")
name = I18n.t("color_schemes.#{scheme_name.downcase.gsub(" ", "_")}_theme_name")
scheme = ColorScheme.find_by(base_scheme_id: scheme_name, via_wizard: true)
scheme ||= ColorScheme.create_from_base(name: name, via_wizard: true, base_scheme_id: scheme_name)
scheme ||=
ColorScheme.create_from_base(name: name, via_wizard: true, base_scheme_id: scheme_name)
if default_theme
default_theme.color_scheme_id = scheme.id
default_theme.save!
else
theme = Theme.create!(
name: I18n.t("color_schemes.default_theme_name"),
user_id: @wizard.user.id,
color_scheme_id: scheme.id
)
theme =
Theme.create!(
name: I18n.t("color_schemes.default_theme_name"),
user_id: @wizard.user.id,
color_scheme_id: scheme.id,
)
theme.set_default!
end
if scheme.is_dark?
updater.update_setting(:default_dark_mode_color_scheme_id, -1)
end
updater.update_setting(:default_dark_mode_color_scheme_id, -1) if scheme.is_dark?
updater.refresh_required = true
end
end
@wizard.append_step('corporate') do |step|
@wizard.append_step("corporate") do |step|
step.emoji = "briefcase"
step.description_vars = { base_path: Discourse.base_path }
step.add_field(id: 'company_name', type: 'text', value: SiteSetting.company_name)
step.add_field(id: 'governing_law', type: 'text', value: SiteSetting.governing_law)
step.add_field(id: 'contact_url', type: 'text', value: SiteSetting.contact_url)
step.add_field(id: 'city_for_disputes', type: 'text', value: SiteSetting.city_for_disputes)
step.add_field(id: 'contact_email', type: 'text', value: SiteSetting.contact_email)
step.add_field(id: "company_name", type: "text", value: SiteSetting.company_name)
step.add_field(id: "governing_law", type: "text", value: SiteSetting.governing_law)
step.add_field(id: "contact_url", type: "text", value: SiteSetting.contact_url)
step.add_field(id: "city_for_disputes", type: "text", value: SiteSetting.city_for_disputes)
step.add_field(id: "contact_email", type: "text", value: SiteSetting.contact_email)
step.on_update do |updater|
update_tos do |raw|
replace_setting_value(updater, raw, 'company_name')
replace_setting_value(updater, raw, 'governing_law')
replace_setting_value(updater, raw, 'city_for_disputes')
replace_setting_value(updater, raw, "company_name")
replace_setting_value(updater, raw, "governing_law")
replace_setting_value(updater, raw, "city_for_disputes")
end
if updater.errors.blank?
updater.apply_settings(:company_name, :governing_law, :city_for_disputes, :contact_url, :contact_email)
updater.apply_settings(
:company_name,
:governing_law,
:city_for_disputes,
:contact_url,
:contact_email,
)
end
end
end
@@ -262,7 +288,7 @@ class Wizard
end
def reserved_usernames
@reserved_usernames ||= SiteSetting.defaults[:reserved_usernames].split('|')
@reserved_usernames ||= SiteSetting.defaults[:reserved_usernames].split("|")
end
def update_tos

View File

@@ -1,7 +1,6 @@
# frozen_string_literal: true
class Wizard
class Choice
attr_reader :id, :label, :icon, :data, :extra_label
attr_accessor :field
@@ -39,6 +38,5 @@ class Wizard
@choices << choice
choice
end
end
end

View File

@@ -34,11 +34,18 @@ class Wizard
value = value.strip if value.is_a?(String)
if !value.is_a?(Upload) && SiteSetting.type_supervisor.get_type(id) == :upload
value = Upload.get_from_url(value) || ''
value = Upload.get_from_url(value) || ""
end
if id == :navigation_menu
value = value.to_s == "true" ? NavigationMenuSiteSetting::SIDEBAR : NavigationMenuSiteSetting::HEADER_DROPDOWN
value =
(
if value.to_s == "true"
NavigationMenuSiteSetting::SIDEBAR
else
NavigationMenuSiteSetting::HEADER_DROPDOWN
end
)
end
SiteSetting.set_and_log(id, value, @current_user) if SiteSetting.get(id) != value
@@ -51,12 +58,11 @@ class Wizard
end
def ensure_changed(id)
errors.add(id, '') if @fields[id] == SiteSetting.defaults[id]
errors.add(id, "") if @fields[id] == SiteSetting.defaults[id]
end
def apply_settings(*ids)
ids.each { |id| apply_setting(id) }
end
end
end