Project

General

Profile

Feature #27705 » 0005-Add-redmine_theme_gem-generator.patch

Takashi Kato, 2025-09-24 16:20

View differences:

lib/generators/redmine_theme_gem/USAGE
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
lib/generators/redmine_theme_gem/redmine_theme_gem_generator.rb
# 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
lib/generators/redmine_theme_gem/templates/Gemfile.erb
# frozen_string_literal: true
source "https://rubygems.org"
# Specify your gem's dependencies in <%= theme_name %>.gemspec
gemspec
lib/generators/redmine_theme_gem/templates/README.rdoc
= <%= file_name %>
Description goes here
lib/generators/redmine_theme_gem/templates/Rakefile
# frozen_string_literal: true
require "bundler/gem_tasks"
task default: []
lib/generators/redmine_theme_gem/templates/application.css
/* load the default Redmine stylesheet */
@import url(../../../stylesheets/application.css);
lib/generators/redmine_theme_gem/templates/gemspec.erb
# 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
(8-8/8)