From 7e08f0f914df1101444cc4cd2a00c72e1c68bf54 Mon Sep 17 00:00:00 2001
From: Takashi Kato <tohosaku@users.osdn.me>
Date: Sun, 10 Nov 2024 10:28:19 +0000
Subject: [PATCH] Add svg icons sample view

---
 app/assets/stylesheets/application.css  | 12 ++++++++++++
 app/controllers/svg_icons_controller.rb | 26 +++++++++++++++++++++++++
 app/helpers/svg_icon_helper.rb          | 21 ++++++++++++++++++++
 app/views/svg_icons/index.html.erb      |  5 +++++
 config/icon_source.yml                  |  2 ++
 config/routes.rb                        |  4 ++++
 6 files changed, 70 insertions(+)
 create mode 100644 app/controllers/svg_icons_controller.rb
 create mode 100644 app/helpers/svg_icon_helper.rb
 create mode 100644 app/views/svg_icons/index.html.erb

diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css
index 0463ae569a..53fc37268c 100644
--- a/app/assets/stylesheets/application.css
+++ b/app/assets/stylesheets/application.css
@@ -2141,3 +2141,15 @@ th[role=columnheader]:not(.no-sort):hover:after {
 	display: inline;
 	opacity: 1;
 }
+
+.svg-icon-sample {
+  display: flex;
+  flex-wrap: wrap;
+  list-style: none;
+  max-width: 1000px
+}
+
+.svg-icon-sample li {
+  padding: 0.5rem;
+  width: calc(200px - 0.5rem * 2);
+}
diff --git a/app/controllers/svg_icons_controller.rb b/app/controllers/svg_icons_controller.rb
new file mode 100644
index 0000000000..43bf4d9e34
--- /dev/null
+++ b/app/controllers/svg_icons_controller.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+# Redmine - project management software
+# Copyright (C) 2006-  Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+class SvgIconsController < ApplicationController
+  self.main_menu = false
+
+  def index
+    @icons_mapping = YAML.load_file(Rails.root.join('config/icon_source.yml'))
+  end
+end
diff --git a/app/helpers/svg_icon_helper.rb b/app/helpers/svg_icon_helper.rb
new file mode 100644
index 0000000000..7addb397c5
--- /dev/null
+++ b/app/helpers/svg_icon_helper.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+# Redmine - project management software
+# Copyright (C) 2006-  Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+module SvgIconHelper
+end
diff --git a/app/views/svg_icons/index.html.erb b/app/views/svg_icons/index.html.erb
new file mode 100644
index 0000000000..e7459b1e26
--- /dev/null
+++ b/app/views/svg_icons/index.html.erb
@@ -0,0 +1,5 @@
+<ul class="svg-icon-sample">
+  <% @icons_mapping.sort{|a,b| a['name'] <=> b['name']}.each do |icon| %>
+    <li><%= sprite_icon icon['name'], icon['name'] %></li>
+  <% end %>
+</ul>
diff --git a/config/icon_source.yml b/config/icon_source.yml
index 05d024718f..902354bdbb 100644
--- a/config/icon_source.yml
+++ b/config/icon_source.yml
@@ -20,6 +20,8 @@
 #   - name: destination icon name
 #     svg: source icon name from Github repository
 #     style: outline (default) or filled
+#
+# To see the appearance of all icons, visit /rails/info/svg_icons
 
 - name: edit
   svg: pencil
diff --git a/config/routes.rb b/config/routes.rb
index 563ffe1e21..5e51efcaa0 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -409,6 +409,10 @@ Rails.application.routes.draw do
 
   get 'robots.:format', :to => 'welcome#robots', :constraints => {:format => 'txt'}
 
+  if Rails.env.development?
+    get 'rails/info/svg_icons', :to => 'svg_icons#index'
+  end
+
   get 'help/wiki_syntax/(:type)', :controller => 'help', :action => 'show_wiki_syntax', :constraints => { :type => /detailed/ }, :as => 'help_wiki_syntax'
   get 'help/code_highlighting', :controller => 'help', :action => 'show_code_highlighting',  :as => 'help_code_highlighting'
 
-- 
2.39.2

