2018-11-26 16:49:57 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module SvgSprite
|
|
|
|
SVG_ICONS ||= Set.new([
|
|
|
|
"adjust",
|
2020-01-27 08:29:43 -05:00
|
|
|
"address-book",
|
2018-12-07 07:00:02 -05:00
|
|
|
"ambulance",
|
2018-11-26 16:49:57 -05:00
|
|
|
"anchor",
|
|
|
|
"angle-double-down",
|
|
|
|
"angle-double-up",
|
2019-02-19 07:56:01 -05:00
|
|
|
"angle-double-right",
|
|
|
|
"angle-double-left",
|
2018-11-26 16:49:57 -05:00
|
|
|
"angle-down",
|
|
|
|
"angle-right",
|
|
|
|
"angle-up",
|
|
|
|
"archive",
|
|
|
|
"arrow-down",
|
|
|
|
"arrow-left",
|
2019-01-24 06:25:37 -05:00
|
|
|
"arrow-up",
|
|
|
|
"arrows-alt-h",
|
|
|
|
"arrows-alt-v",
|
2018-11-26 16:49:57 -05:00
|
|
|
"at",
|
2019-08-29 11:03:43 -04:00
|
|
|
"asterisk",
|
2018-11-26 16:49:57 -05:00
|
|
|
"backward",
|
|
|
|
"ban",
|
|
|
|
"bars",
|
|
|
|
"bed",
|
2019-09-09 11:03:57 -04:00
|
|
|
"bell",
|
2018-11-26 16:49:57 -05:00
|
|
|
"bell-slash",
|
|
|
|
"bold",
|
|
|
|
"book",
|
2019-08-27 08:09:00 -04:00
|
|
|
"book-reader",
|
2018-11-26 16:49:57 -05:00
|
|
|
"bookmark",
|
|
|
|
"briefcase",
|
|
|
|
"calendar-alt",
|
|
|
|
"caret-down",
|
|
|
|
"caret-left",
|
|
|
|
"caret-right",
|
|
|
|
"caret-up",
|
|
|
|
"certificate",
|
|
|
|
"chart-bar",
|
|
|
|
"chart-pie",
|
|
|
|
"check",
|
|
|
|
"check-circle",
|
|
|
|
"check-square",
|
|
|
|
"chevron-down",
|
2019-04-10 12:23:18 -04:00
|
|
|
"chevron-left",
|
2018-11-26 16:49:57 -05:00
|
|
|
"chevron-right",
|
|
|
|
"chevron-up",
|
|
|
|
"circle",
|
|
|
|
"code",
|
|
|
|
"cog",
|
|
|
|
"columns",
|
|
|
|
"comment",
|
|
|
|
"compress",
|
|
|
|
"copy",
|
|
|
|
"crosshairs",
|
|
|
|
"cube",
|
|
|
|
"desktop",
|
2021-04-08 09:58:12 -04:00
|
|
|
"discourse-amazon",
|
2019-12-19 14:39:29 -05:00
|
|
|
"discourse-bell-exclamation",
|
|
|
|
"discourse-bell-one",
|
|
|
|
"discourse-bell-slash",
|
2021-04-08 09:58:12 -04:00
|
|
|
"discourse-bookmark-clock",
|
2018-12-03 22:29:20 -05:00
|
|
|
"discourse-compress",
|
2021-06-23 11:12:48 -04:00
|
|
|
"discourse-emojis",
|
2018-12-03 22:29:20 -05:00
|
|
|
"discourse-expand",
|
2018-11-26 16:49:57 -05:00
|
|
|
"download",
|
|
|
|
"ellipsis-h",
|
|
|
|
"ellipsis-v",
|
|
|
|
"envelope",
|
|
|
|
"envelope-square",
|
|
|
|
"exchange-alt",
|
|
|
|
"exclamation-circle",
|
|
|
|
"exclamation-triangle",
|
|
|
|
"external-link-alt",
|
2018-12-07 10:49:18 -05:00
|
|
|
"fab-android",
|
2019-01-24 06:25:37 -05:00
|
|
|
"fab-apple",
|
2019-05-30 09:29:43 -04:00
|
|
|
"fab-chrome",
|
2019-08-30 05:54:19 -04:00
|
|
|
"fab-discord",
|
2018-11-28 09:53:06 -05:00
|
|
|
"fab-discourse",
|
2018-11-26 16:49:57 -05:00
|
|
|
"fab-facebook-square",
|
2019-02-27 09:52:06 -05:00
|
|
|
"fab-facebook",
|
2018-11-26 16:49:57 -05:00
|
|
|
"fab-github",
|
|
|
|
"fab-instagram",
|
|
|
|
"fab-linux",
|
2019-01-24 06:25:37 -05:00
|
|
|
"fab-twitter",
|
2018-11-26 16:49:57 -05:00
|
|
|
"fab-twitter-square",
|
2021-04-08 09:58:12 -04:00
|
|
|
"fab-wikipedia-w",
|
2018-11-26 16:49:57 -05:00
|
|
|
"fab-windows",
|
|
|
|
"far-bell",
|
|
|
|
"far-bell-slash",
|
|
|
|
"far-calendar-plus",
|
|
|
|
"far-chart-bar",
|
|
|
|
"far-check-square",
|
|
|
|
"far-circle",
|
|
|
|
"far-clipboard",
|
|
|
|
"far-clock",
|
|
|
|
"far-comment",
|
2020-12-10 12:02:07 -05:00
|
|
|
"far-comments",
|
2019-01-10 14:26:53 -05:00
|
|
|
"far-copyright",
|
2018-11-26 16:49:57 -05:00
|
|
|
"far-dot-circle",
|
|
|
|
"far-edit",
|
|
|
|
"far-envelope",
|
|
|
|
"far-eye",
|
|
|
|
"far-eye-slash",
|
|
|
|
"far-file-alt",
|
|
|
|
"far-frown",
|
|
|
|
"far-heart",
|
|
|
|
"far-image",
|
|
|
|
"far-list-alt",
|
2020-07-16 19:26:17 -04:00
|
|
|
"far-meh",
|
2018-11-26 16:49:57 -05:00
|
|
|
"far-moon",
|
|
|
|
"far-smile",
|
|
|
|
"far-square",
|
2021-06-01 04:33:40 -04:00
|
|
|
"far-star",
|
2018-11-26 16:49:57 -05:00
|
|
|
"far-sun",
|
|
|
|
"far-thumbs-down",
|
|
|
|
"far-thumbs-up",
|
|
|
|
"far-trash-alt",
|
|
|
|
"fast-backward",
|
|
|
|
"fast-forward",
|
|
|
|
"file",
|
|
|
|
"file-alt",
|
|
|
|
"filter",
|
|
|
|
"flag",
|
|
|
|
"folder",
|
|
|
|
"folder-open",
|
|
|
|
"forward",
|
|
|
|
"gavel",
|
|
|
|
"globe",
|
|
|
|
"globe-americas",
|
|
|
|
"hand-point-right",
|
2019-03-08 03:48:35 -05:00
|
|
|
"hands-helping",
|
2018-11-26 16:49:57 -05:00
|
|
|
"heart",
|
2020-11-12 08:11:03 -05:00
|
|
|
"history",
|
2018-11-26 16:49:57 -05:00
|
|
|
"home",
|
2020-10-30 10:22:56 -04:00
|
|
|
"hourglass-start",
|
2019-12-09 14:15:47 -05:00
|
|
|
"id-card",
|
2022-03-08 12:39:46 -05:00
|
|
|
"image",
|
2018-11-26 16:49:57 -05:00
|
|
|
"info-circle",
|
|
|
|
"italic",
|
|
|
|
"key",
|
2021-09-16 15:15:00 -04:00
|
|
|
"layer-group",
|
2018-11-26 16:49:57 -05:00
|
|
|
"link",
|
|
|
|
"list",
|
|
|
|
"list-ol",
|
|
|
|
"list-ul",
|
|
|
|
"lock",
|
|
|
|
"magic",
|
2019-01-24 06:25:37 -05:00
|
|
|
"map-marker-alt",
|
2018-11-26 16:49:57 -05:00
|
|
|
"microphone-slash",
|
|
|
|
"minus",
|
|
|
|
"minus-circle",
|
|
|
|
"mobile-alt",
|
2020-12-18 10:03:51 -05:00
|
|
|
"moon",
|
2018-11-26 16:49:57 -05:00
|
|
|
"paint-brush",
|
|
|
|
"paper-plane",
|
2021-04-28 10:48:00 -04:00
|
|
|
"pause",
|
2018-11-26 16:49:57 -05:00
|
|
|
"pencil-alt",
|
2018-12-07 07:00:02 -05:00
|
|
|
"play",
|
2018-11-26 16:49:57 -05:00
|
|
|
"plug",
|
|
|
|
"plus",
|
|
|
|
"plus-circle",
|
|
|
|
"plus-square",
|
|
|
|
"power-off",
|
2019-02-20 14:58:31 -05:00
|
|
|
"puzzle-piece",
|
2018-11-26 16:49:57 -05:00
|
|
|
"question",
|
|
|
|
"question-circle",
|
|
|
|
"quote-left",
|
|
|
|
"quote-right",
|
|
|
|
"random",
|
|
|
|
"redo",
|
|
|
|
"reply",
|
|
|
|
"rocket",
|
|
|
|
"search",
|
|
|
|
"share",
|
|
|
|
"shield-alt",
|
2019-03-27 09:25:04 -04:00
|
|
|
"sign-in-alt",
|
2018-11-26 16:49:57 -05:00
|
|
|
"sign-out-alt",
|
2019-01-24 06:25:37 -05:00
|
|
|
"signal",
|
2021-10-06 11:42:52 -04:00
|
|
|
"sliders-h",
|
2020-06-10 12:11:49 -04:00
|
|
|
"star",
|
2018-11-26 16:49:57 -05:00
|
|
|
"step-backward",
|
|
|
|
"step-forward",
|
2019-09-09 11:03:57 -04:00
|
|
|
"stream",
|
2020-03-16 14:32:38 -04:00
|
|
|
"sync-alt",
|
2018-11-26 16:49:57 -05:00
|
|
|
"sync",
|
|
|
|
"table",
|
|
|
|
"tag",
|
2021-06-03 18:33:36 -04:00
|
|
|
"tags",
|
2018-11-26 16:49:57 -05:00
|
|
|
"tasks",
|
|
|
|
"thermometer-three-quarters",
|
|
|
|
"thumbs-down",
|
|
|
|
"thumbs-up",
|
|
|
|
"thumbtack",
|
|
|
|
"times",
|
|
|
|
"times-circle",
|
2020-12-31 09:39:06 -05:00
|
|
|
"toggle-off",
|
|
|
|
"toggle-on",
|
2018-11-26 16:49:57 -05:00
|
|
|
"trash-alt",
|
|
|
|
"undo",
|
|
|
|
"unlink",
|
|
|
|
"unlock",
|
|
|
|
"unlock-alt",
|
|
|
|
"upload",
|
|
|
|
"user",
|
2019-04-19 03:18:01 -04:00
|
|
|
"user-edit",
|
2021-07-20 13:58:38 -04:00
|
|
|
"user-friends",
|
2018-11-26 16:49:57 -05:00
|
|
|
"user-plus",
|
|
|
|
"user-secret",
|
2019-04-23 03:37:33 -04:00
|
|
|
"user-shield",
|
2018-11-26 16:49:57 -05:00
|
|
|
"user-times",
|
|
|
|
"users",
|
2020-03-30 17:17:00 -04:00
|
|
|
"wrench",
|
|
|
|
"spinner"
|
2018-11-26 16:49:57 -05:00
|
|
|
])
|
|
|
|
|
|
|
|
FA_ICON_MAP = { 'far fa-' => 'far-', 'fab fa-' => 'fab-', 'fas fa-' => '', 'fa-' => '' }
|
|
|
|
|
2019-03-15 02:16:15 -04:00
|
|
|
CORE_SVG_SPRITES = Dir.glob("#{Rails.root}/vendor/assets/svg-icons/**/*.svg")
|
|
|
|
|
|
|
|
THEME_SPRITE_VAR_NAME = "icons-sprite"
|
|
|
|
|
2021-06-03 04:14:56 -04:00
|
|
|
def self.preload
|
|
|
|
settings_icons
|
|
|
|
group_icons
|
|
|
|
badge_icons
|
|
|
|
end
|
|
|
|
|
2021-06-15 02:57:17 -04:00
|
|
|
def self.custom_svg_sprites(theme_id)
|
|
|
|
get_set_cache("custom_svg_sprites_#{Theme.transform_ids(theme_id).join(',')}") do
|
2021-06-22 14:07:23 -04:00
|
|
|
plugin_paths = []
|
|
|
|
Discourse.plugins.map { |plugin| File.dirname(plugin.path) }.each do |path|
|
|
|
|
plugin_paths << "#{path}/svg-icons/*.svg"
|
|
|
|
end
|
|
|
|
|
|
|
|
custom_sprite_paths = Dir.glob(plugin_paths)
|
2019-03-15 02:16:15 -04:00
|
|
|
|
2021-06-15 02:57:17 -04:00
|
|
|
if theme_id.present?
|
|
|
|
ThemeField.where(type_id: ThemeField.types[:theme_upload_var], name: THEME_SPRITE_VAR_NAME, theme_id: Theme.transform_ids(theme_id))
|
2021-06-01 02:57:24 -04:00
|
|
|
.pluck(:upload_id).each do |upload_id|
|
2019-03-15 02:16:15 -04:00
|
|
|
|
2021-06-01 02:57:24 -04:00
|
|
|
upload = Upload.find(upload_id) rescue nil
|
2019-05-28 10:57:44 -04:00
|
|
|
|
2021-06-01 02:57:24 -04:00
|
|
|
if Discourse.store.external?
|
|
|
|
external_copy = Discourse.store.download(upload) rescue nil
|
|
|
|
original_path = external_copy.try(:path)
|
|
|
|
else
|
|
|
|
original_path = Discourse.store.path_for(upload)
|
|
|
|
end
|
2020-05-13 11:11:44 -04:00
|
|
|
|
2021-06-01 02:57:24 -04:00
|
|
|
custom_sprite_paths << original_path if original_path.present?
|
|
|
|
end
|
2019-03-15 02:16:15 -04:00
|
|
|
end
|
|
|
|
|
2021-06-22 14:07:23 -04:00
|
|
|
custom_sprite_paths.map do |path|
|
|
|
|
if File.exist?(path)
|
|
|
|
{
|
|
|
|
filename: "#{File.basename(path, ".svg")}",
|
|
|
|
sprite: File.read(path)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2019-03-15 02:16:15 -04:00
|
|
|
end
|
|
|
|
end
|
2019-01-12 09:59:12 -05:00
|
|
|
|
2021-06-15 02:57:17 -04:00
|
|
|
def self.all_icons(theme_id = nil)
|
|
|
|
get_set_cache("icons_#{Theme.transform_ids(theme_id).join(',')}") do
|
2019-02-06 10:51:23 -05:00
|
|
|
Set.new()
|
|
|
|
.merge(settings_icons)
|
|
|
|
.merge(plugin_icons)
|
|
|
|
.merge(badge_icons)
|
|
|
|
.merge(group_icons)
|
2021-06-15 02:57:17 -04:00
|
|
|
.merge(theme_icons(theme_id))
|
|
|
|
.merge(custom_icons(theme_id))
|
2019-02-06 10:51:23 -05:00
|
|
|
.delete_if { |i| i.blank? || i.include?("/") }
|
|
|
|
.map! { |i| process(i.dup) }
|
|
|
|
.merge(SVG_ICONS)
|
|
|
|
.sort
|
|
|
|
end
|
2018-11-26 16:49:57 -05:00
|
|
|
end
|
|
|
|
|
2021-06-15 02:57:17 -04:00
|
|
|
def self.version(theme_id = nil)
|
|
|
|
get_set_cache("version_#{Theme.transform_ids(theme_id).join(',')}") do
|
|
|
|
Digest::SHA1.hexdigest(bundle(theme_id))
|
2019-02-06 10:51:23 -05:00
|
|
|
end
|
2018-11-26 16:49:57 -05:00
|
|
|
end
|
|
|
|
|
2021-06-15 02:57:17 -04:00
|
|
|
def self.path(theme_id = nil)
|
|
|
|
"/svg-sprite/#{Discourse.current_hostname}/svg-#{theme_id}-#{version(theme_id)}.js"
|
2018-11-26 16:49:57 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.expire_cache
|
2019-02-06 10:51:23 -05:00
|
|
|
cache&.clear
|
2018-11-26 16:49:57 -05:00
|
|
|
end
|
|
|
|
|
2021-06-15 02:57:17 -04:00
|
|
|
def self.sprite_sources(theme_id)
|
2021-06-22 14:07:23 -04:00
|
|
|
sprites = []
|
|
|
|
|
|
|
|
CORE_SVG_SPRITES.each do |path|
|
|
|
|
if File.exist?(path)
|
|
|
|
sprites << {
|
|
|
|
filename: "#{File.basename(path, ".svg")}",
|
|
|
|
sprite: File.read(path)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2021-06-01 02:57:24 -04:00
|
|
|
|
2021-06-15 02:57:17 -04:00
|
|
|
if theme_id.present?
|
2021-06-22 14:07:23 -04:00
|
|
|
sprites = sprites + custom_svg_sprites(theme_id)
|
2021-06-01 02:57:24 -04:00
|
|
|
end
|
|
|
|
|
2021-06-22 14:07:23 -04:00
|
|
|
sprites
|
2021-06-01 02:57:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.core_svgs
|
|
|
|
@core_svgs ||= begin
|
|
|
|
symbols = {}
|
|
|
|
|
|
|
|
CORE_SVG_SPRITES.each do |filename|
|
|
|
|
svg_filename = "#{File.basename(filename, ".svg")}"
|
|
|
|
|
|
|
|
Nokogiri::XML(File.open(filename)) do |config|
|
|
|
|
config.options = Nokogiri::XML::ParseOptions::NOBLANKS
|
|
|
|
end.css('symbol').each do |sym|
|
|
|
|
icon_id = prepare_symbol(sym, svg_filename)
|
|
|
|
sym.attributes['id'].value = icon_id
|
|
|
|
symbols[icon_id] = sym.to_xml
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
symbols
|
|
|
|
end
|
2019-03-15 02:16:15 -04:00
|
|
|
end
|
|
|
|
|
2021-06-15 02:57:17 -04:00
|
|
|
def self.bundle(theme_id = nil)
|
|
|
|
icons = all_icons(theme_id)
|
2018-11-26 16:49:57 -05:00
|
|
|
|
|
|
|
svg_subset = """<!--
|
2019-03-06 09:21:31 -05:00
|
|
|
Discourse SVG subset of Font Awesome Free by @fontawesome - https://fontawesome.com
|
|
|
|
License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License)
|
2018-11-26 16:49:57 -05:00
|
|
|
-->
|
|
|
|
<svg xmlns='http://www.w3.org/2000/svg' style='display: none;'>
|
|
|
|
""".dup
|
|
|
|
|
2021-06-01 02:57:24 -04:00
|
|
|
core_svgs.each do |icon_id, sym|
|
|
|
|
if icons.include?(icon_id)
|
|
|
|
svg_subset << sym
|
2018-11-26 16:49:57 -05:00
|
|
|
end
|
2021-06-01 02:57:24 -04:00
|
|
|
end
|
2018-11-26 16:49:57 -05:00
|
|
|
|
2021-06-22 14:07:23 -04:00
|
|
|
custom_svg_sprites(theme_id).each do |item|
|
2021-07-14 15:18:29 -04:00
|
|
|
begin
|
|
|
|
svg_file = Nokogiri::XML(item[:sprite]) do |config|
|
|
|
|
config.options = Nokogiri::XML::ParseOptions::NOBLANKS
|
|
|
|
end
|
|
|
|
rescue => e
|
|
|
|
Rails.logger.warn("Bad XML in custom sprite in theme with ID=#{theme_id}. Error info: #{e.inspect}")
|
2021-06-01 22:36:16 -04:00
|
|
|
end
|
2018-11-26 16:49:57 -05:00
|
|
|
|
2021-07-14 15:18:29 -04:00
|
|
|
next if !svg_file
|
|
|
|
|
2021-06-01 22:36:16 -04:00
|
|
|
svg_file.css("symbol").each do |sym|
|
2021-06-22 14:07:23 -04:00
|
|
|
icon_id = prepare_symbol(sym, item[:filename])
|
2021-06-01 02:57:24 -04:00
|
|
|
|
2021-06-01 22:36:16 -04:00
|
|
|
if icons.include? icon_id
|
|
|
|
sym.attributes['id'].value = icon_id
|
|
|
|
sym.css('title').each(&:remove)
|
|
|
|
svg_subset << sym.to_xml
|
2018-11-26 16:49:57 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
svg_subset << '</svg>'
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.search(searched_icon)
|
|
|
|
searched_icon = process(searched_icon.dup)
|
|
|
|
|
2021-06-22 14:07:23 -04:00
|
|
|
sprite_sources(SiteSetting.default_theme_id).each do |item|
|
|
|
|
svg_file = Nokogiri::XML(item[:sprite])
|
2018-11-26 16:49:57 -05:00
|
|
|
|
|
|
|
svg_file.css('symbol').each do |sym|
|
2021-06-22 14:07:23 -04:00
|
|
|
icon_id = prepare_symbol(sym, item[:filename])
|
2018-11-26 16:49:57 -05:00
|
|
|
|
|
|
|
if searched_icon == icon_id
|
|
|
|
sym.attributes['id'].value = icon_id
|
2019-01-24 06:25:37 -05:00
|
|
|
sym.css('title').each(&:remove)
|
2018-11-26 16:49:57 -05:00
|
|
|
return sym.to_xml
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-01-24 06:25:37 -05:00
|
|
|
false
|
2018-11-26 16:49:57 -05:00
|
|
|
end
|
|
|
|
|
2020-02-04 18:41:10 -05:00
|
|
|
def self.icon_picker_search(keyword)
|
|
|
|
results = Set.new
|
|
|
|
|
2021-06-22 14:07:23 -04:00
|
|
|
sprite_sources(SiteSetting.default_theme_id).each do |item|
|
|
|
|
svg_file = Nokogiri::XML(item[:sprite])
|
2020-02-04 18:41:10 -05:00
|
|
|
|
|
|
|
svg_file.css('symbol').each do |sym|
|
2021-06-22 14:07:23 -04:00
|
|
|
icon_id = prepare_symbol(sym, item[:filename])
|
2020-02-04 18:41:10 -05:00
|
|
|
if keyword.empty? || icon_id.include?(keyword)
|
|
|
|
sym.attributes['id'].value = icon_id
|
|
|
|
sym.css('title').each(&:remove)
|
|
|
|
results.add(id: icon_id, symbol: sym.to_xml)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
results.sort_by { |icon| icon[:id] }
|
|
|
|
end
|
|
|
|
|
2019-08-08 05:44:04 -04:00
|
|
|
# For use in no_ember .html.erb layouts
|
|
|
|
def self.raw_svg(name)
|
|
|
|
get_set_cache("raw_svg_#{name}") do
|
|
|
|
symbol = search(name)
|
|
|
|
break "" unless symbol
|
|
|
|
symbol = Nokogiri::XML(symbol).children.first
|
|
|
|
symbol.name = "svg"
|
|
|
|
<<~HTML
|
|
|
|
<svg class="fa d-icon svg-icon svg-node" aria-hidden="true">#{symbol}</svg>
|
|
|
|
HTML
|
|
|
|
end.html_safe
|
|
|
|
end
|
|
|
|
|
2019-03-15 02:16:15 -04:00
|
|
|
def self.theme_sprite_variable_name
|
|
|
|
THEME_SPRITE_VAR_NAME
|
|
|
|
end
|
|
|
|
|
2021-06-22 14:07:23 -04:00
|
|
|
def self.prepare_symbol(symbol, svg_filename = nil)
|
2018-11-26 16:49:57 -05:00
|
|
|
icon_id = symbol.attr('id')
|
|
|
|
|
|
|
|
case svg_filename
|
|
|
|
when "regular"
|
|
|
|
icon_id = icon_id.prepend('far-')
|
|
|
|
when "brands"
|
|
|
|
icon_id = icon_id.prepend('fab-')
|
|
|
|
end
|
|
|
|
|
|
|
|
icon_id
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.settings_icons
|
2021-06-03 04:14:56 -04:00
|
|
|
get_set_cache("settings_icons") do
|
|
|
|
# includes svg_icon_subset and any settings containing _icon (incl. plugin settings)
|
|
|
|
site_setting_icons = []
|
2018-11-26 16:49:57 -05:00
|
|
|
|
2021-06-03 04:14:56 -04:00
|
|
|
SiteSetting.settings_hash.select do |key, value|
|
|
|
|
if key.to_s.include?("_icon") && String === value
|
|
|
|
site_setting_icons |= value.split('|')
|
|
|
|
end
|
2018-11-26 16:49:57 -05:00
|
|
|
end
|
|
|
|
|
2021-06-03 04:14:56 -04:00
|
|
|
site_setting_icons
|
|
|
|
end
|
2018-11-26 16:49:57 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.plugin_icons
|
|
|
|
DiscoursePluginRegistry.svg_icons
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.badge_icons
|
2021-06-03 04:14:56 -04:00
|
|
|
get_set_cache("badge_icons") do
|
|
|
|
Badge.pluck(:icon).uniq
|
|
|
|
end
|
2018-11-26 16:49:57 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.group_icons
|
2021-06-03 04:14:56 -04:00
|
|
|
get_set_cache("group_icons") do
|
|
|
|
Group.pluck(:flair_icon).uniq
|
|
|
|
end
|
2018-11-26 16:49:57 -05:00
|
|
|
end
|
|
|
|
|
2021-06-15 02:57:17 -04:00
|
|
|
def self.theme_icons(theme_id)
|
|
|
|
return [] if theme_id.blank?
|
2021-06-01 02:57:24 -04:00
|
|
|
|
2018-11-26 16:49:57 -05:00
|
|
|
theme_icon_settings = []
|
2021-06-17 22:16:26 -04:00
|
|
|
theme_ids = Theme.transform_ids(theme_id)
|
2018-11-26 16:49:57 -05:00
|
|
|
|
2019-02-06 10:51:23 -05:00
|
|
|
# Need to load full records for default values
|
2021-06-17 22:16:26 -04:00
|
|
|
Theme.where(id: theme_ids).each do |theme|
|
2018-11-26 16:49:57 -05:00
|
|
|
settings = theme.cached_settings.each do |key, value|
|
2018-11-29 19:11:32 -05:00
|
|
|
if key.to_s.include?("_icon") && String === value
|
2018-11-26 16:49:57 -05:00
|
|
|
theme_icon_settings |= value.split('|')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-06-17 22:16:26 -04:00
|
|
|
theme_icon_settings |= ThemeModifierHelper.new(theme_ids: theme_ids).svg_icons
|
2020-03-11 09:30:45 -04:00
|
|
|
|
2018-11-26 16:49:57 -05:00
|
|
|
theme_icon_settings
|
|
|
|
end
|
|
|
|
|
2021-06-15 02:57:17 -04:00
|
|
|
def self.custom_icons(theme_id)
|
2019-03-15 02:16:15 -04:00
|
|
|
# Automatically register icons in sprites added via themes or plugins
|
|
|
|
icons = []
|
2021-06-22 14:07:23 -04:00
|
|
|
custom_svg_sprites(theme_id).each do |item|
|
|
|
|
svg_file = Nokogiri::XML(item[:sprite])
|
2019-03-15 02:16:15 -04:00
|
|
|
svg_file.css('symbol').each do |sym|
|
2019-03-18 22:07:19 -04:00
|
|
|
icons << sym.attributes['id'].value if sym.attributes['id'].present?
|
2019-03-15 02:16:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
icons
|
|
|
|
end
|
|
|
|
|
2018-11-26 16:49:57 -05:00
|
|
|
def self.process(icon_name)
|
2020-02-04 18:41:10 -05:00
|
|
|
icon_name = icon_name.strip
|
|
|
|
FA_ICON_MAP.each { |k, v| icon_name = icon_name.sub(k, v) }
|
2020-05-26 14:53:32 -04:00
|
|
|
icon_name
|
2018-11-26 16:49:57 -05:00
|
|
|
end
|
2019-02-06 10:51:23 -05:00
|
|
|
|
2021-06-03 02:02:40 -04:00
|
|
|
def self.get_set_cache(key, &block)
|
|
|
|
cache.defer_get_set(key, &block)
|
2019-02-06 10:51:23 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.cache
|
|
|
|
@cache ||= DistributedCache.new('svg_sprite')
|
|
|
|
end
|
2018-11-26 16:49:57 -05:00
|
|
|
end
|