From 714bf71620e99f6f6638b1af8435c5c07057c829 Mon Sep 17 00:00:00 2001
From: Takashi Kato <tohosaku@users.osdn.me>
Date: Tue, 23 Sep 2025 11:37:54 +0000
Subject: [PATCH 5/5] Add redmine_theme_gem generator

---
 lib/generators/redmine_theme_gem/USAGE        | 13 ++++++
 .../redmine_theme_gem_generator.rb            | 43 +++++++++++++++++++
 .../redmine_theme_gem/templates/Gemfile.erb   |  7 +++
 .../redmine_theme_gem/templates/README.rdoc   |  3 ++
 .../redmine_theme_gem/templates/Rakefile      |  4 ++
 .../templates/application.css                 |  2 +
 .../redmine_theme_gem/templates/gemspec.erb   | 23 ++++++++++
 7 files changed, 95 insertions(+)
 create mode 100644 lib/generators/redmine_theme_gem/USAGE
 create mode 100644 lib/generators/redmine_theme_gem/redmine_theme_gem_generator.rb
 create mode 100644 lib/generators/redmine_theme_gem/templates/Gemfile.erb
 create mode 100644 lib/generators/redmine_theme_gem/templates/README.rdoc
 create mode 100644 lib/generators/redmine_theme_gem/templates/Rakefile
 create mode 100644 lib/generators/redmine_theme_gem/templates/application.css
 create mode 100644 lib/generators/redmine_theme_gem/templates/gemspec.erb

diff --git a/lib/generators/redmine_theme_gem/USAGE b/lib/generators/redmine_theme_gem/USAGE
new file mode 100644
index 0000000000..32aa6638fc
--- /dev/null
+++ b/lib/generators/redmine_theme_gem/USAGE
@@ -0,0 +1,13 @@
+Description:
+    The theme generator creates stubs for a new Redmine gheme.
+
+Example:
+    bundle exec rails generate redmine_theme_gem foo
+      create  gems/foo/images
+      create  gems/foo/javascripts
+      create  gems/foo/stylesheets
+      create  gems/foo/stylesheets/application.css
+      create  gems/foo/Gemfile
+      create  gems/foo/Rakefile
+      create  gems/foo/README.rdoc
+      create  gems/foo/foo.gemspec
diff --git a/lib/generators/redmine_theme_gem/redmine_theme_gem_generator.rb b/lib/generators/redmine_theme_gem/redmine_theme_gem_generator.rb
new file mode 100644
index 0000000000..4368a3c989
--- /dev/null
+++ b/lib/generators/redmine_theme_gem/redmine_theme_gem_generator.rb
@@ -0,0 +1,43 @@
+# 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 RedmineThemeGemGenerator < Rails::Generators::NamedBase
+  source_root File.expand_path('templates', __dir__)
+
+  attr_reader :gem_path, :theme_name, :theme_pretty_name
+
+  def initialize(*args)
+    super
+    @theme_name = file_name.underscore
+    @theme_pretty_name = theme_name.titleize
+    @gem_path = Rails.root.join('gems', theme_name)
+  end
+
+  def copy_templates
+    empty_directory "#{gem_path}/stylesheets"
+    empty_directory "#{gem_path}/javascripts"
+    empty_directory "#{gem_path}/images"
+
+    template 'README.rdoc',    "#{gem_path}/README.rdoc"
+    template 'Gemfile.erb',    "#{gem_path}/Gemfile"
+    template 'Rakefile',    "#{gem_path}/Rakefile"
+    template 'application.css', "#{gem_path}/stylesheets/application.css"
+    template 'gemspec.erb', "#{gem_path}/#{theme_name}.gemspec"
+  end
+end
diff --git a/lib/generators/redmine_theme_gem/templates/Gemfile.erb b/lib/generators/redmine_theme_gem/templates/Gemfile.erb
new file mode 100644
index 0000000000..054aca95bd
--- /dev/null
+++ b/lib/generators/redmine_theme_gem/templates/Gemfile.erb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+source "https://rubygems.org"
+
+# Specify your gem's dependencies in <%= theme_name %>.gemspec
+gemspec
+
diff --git a/lib/generators/redmine_theme_gem/templates/README.rdoc b/lib/generators/redmine_theme_gem/templates/README.rdoc
new file mode 100644
index 0000000000..7a31a890e8
--- /dev/null
+++ b/lib/generators/redmine_theme_gem/templates/README.rdoc
@@ -0,0 +1,3 @@
+= <%= file_name %>
+
+Description goes here
diff --git a/lib/generators/redmine_theme_gem/templates/Rakefile b/lib/generators/redmine_theme_gem/templates/Rakefile
new file mode 100644
index 0000000000..b5ce21be19
--- /dev/null
+++ b/lib/generators/redmine_theme_gem/templates/Rakefile
@@ -0,0 +1,4 @@
+# frozen_string_literal: true
+
+require "bundler/gem_tasks"
+task default: []
diff --git a/lib/generators/redmine_theme_gem/templates/application.css b/lib/generators/redmine_theme_gem/templates/application.css
new file mode 100644
index 0000000000..34a9cae501
--- /dev/null
+++ b/lib/generators/redmine_theme_gem/templates/application.css
@@ -0,0 +1,2 @@
+/* load the default Redmine stylesheet */
+@import url(../../../stylesheets/application.css);
diff --git a/lib/generators/redmine_theme_gem/templates/gemspec.erb b/lib/generators/redmine_theme_gem/templates/gemspec.erb
new file mode 100644
index 0000000000..88226ad64e
--- /dev/null
+++ b/lib/generators/redmine_theme_gem/templates/gemspec.erb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+Gem::Specification.new do |spec|
+
+  # Do not use constants or variables from the gem's own code in this block, as is normally
+  # done with gems. (e.g. Foo::VERSION)
+
+  spec.name = "<%= theme_name %>"
+  spec.version = "0.0.1"
+  spec.authors = ["johndoe"]
+  spec.email = ["johndoe@example.org"]
+
+  spec.summary = "<%= theme_pretty_name %> theme"
+  spec.description = "This is a theme for Redmine"
+  spec.homepage = "https://example.org"
+  spec.required_ruby_version = ">= 3.2.0"
+
+  spec.metadata["author_url"] = spec.homepage
+  spec.files = Dir["{stylesheets,javascripts,img}/**/*", "Gemfile", "README.rdoc"]
+
+  # DO NOT DELETE this attribute
+  spec.metadata["redmine_theme_id"] = "<%= theme_name %>"
+end
-- 
2.39.5

