Module: SuperSettings::Helper
- Included in:
- Application
- Defined in:
- lib/super_settings/application/helper.rb
Overview
Helper functions used for rendering the Super Settings HTML application. These methods are mixed in to the Application class so they are accessible from the ERB templates.
Constant Summary collapse
- ICON_SVG =
Dir.glob(File.join(__dir__, "images", "*.svg")).each_with_object({}) do |file, cache| svg = File.read(file).chomp cache[File.basename(file, ".svg")] = svg end.freeze
- GEAR_SVG =
'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><path d="M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"/><circle cx="12" cy="12" r="3"/></svg>'- ICON_BUTTON_STYLE =
{ cursor: "pointer", width: "1.35rem", height: "1.35rem", "min-width": "20px", "min-height": "20px", "margin-top": "0.25rem", "margin-right": "0.5rem" }.freeze
- DEFAULT_ICON_STYLE =
{ width: "1rem", height: "1rem", display: "inline-block" }.freeze
Class Method Summary collapse
-
.application_header(locale: nil) ⇒ String
Render the header HTML for the web pages using values set in the configuration.
Instance Method Summary collapse
-
#add_to_head ⇒ String
Additional HTML code that should go into the
element on the page. -
#api_base_url ⇒ String
The base URL for the REST API.
-
#application_header ⇒ String
Render the header for the web pages using values set in the configuration.
-
#application_name ⇒ Object
Return the application name set by the configuration or a default value.
-
#color_scheme ⇒ Boolean?
Whether to use dark mode for the application UI.
-
#content_tag(tag, body, options) ⇒ Object
Render an HTML tag with body content.
-
#dark_mode_selector ⇒ String?
A CSS selector that sets dark mode when it matches an element in the page.
-
#html_attributes(options) ⇒ Object
Format a hash into HTML attributes.
-
#html_escape(text) ⇒ String
Escape text for use in HTML.
-
#icon_button(icon, title:, color:, js_class:, url: nil, disabled: false, style: {}, link_style: nil) ⇒ String
Render an icon image as a link tag.
-
#icon_image(name, options = {}) ⇒ String
Render an image tag for one of the SVG images in the images directory.
-
#javascript_tag ⇒ Object
Render the scripts.js file as an inline
Render the header HTML for the web pages using values set in the configuration. Uses the custom application name as the title if set, otherwise falls back to the localized brand title. Uses the gear icon if no application logo is configured.
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
# File 'lib/super_settings/application/helper.rb', line 146 def application_header(locale: nil) config = SuperSettings.configuration.controller locale ||= SuperSettings::MiniI18n::DEFAULT_LOCALE escape = ->(text) { ERB::Util.html_escape(text) } mark_content = if Coerce.present?(config.application_logo) "<img src=\"#{escape.call(config.application_logo)}\" alt=\"\">" else GEAR_SVG end mark = "<div class=\"super-settings-page-header-mark\" aria-hidden=\"true\">" \ "#{mark_content}</div>" title_text = escape.call(config.application_name || SuperSettings::MiniI18n.t("page.brand_title", locale: locale)) title = "<h1 class=\"super-settings-page-header-title\">#{title_text}</h1>" brand_content = mark + title if config.application_link href = escape.call(config.application_link) "<a href=\"#{href}\" class=\"super-settings-page-header-brand\">" \ "#{brand_content}</a>" else "<div class=\"super-settings-page-header-brand\">#{brand_content}</div>" end end