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
1
Description:
2
    The theme generator creates stubs for a new Redmine gheme.
3

  
4
Example:
5
    bundle exec rails generate redmine_theme_gem foo
6
      create  gems/foo/images
7
      create  gems/foo/javascripts
8
      create  gems/foo/stylesheets
9
      create  gems/foo/stylesheets/application.css
10
      create  gems/foo/Gemfile
11
      create  gems/foo/Rakefile
12
      create  gems/foo/README.rdoc
13
      create  gems/foo/foo.gemspec
lib/generators/redmine_theme_gem/redmine_theme_gem_generator.rb
1
# frozen_string_literal: true
2

  
3
# Redmine - project management software
4
# Copyright (C) 2006-  Jean-Philippe Lang
5
#
6
# This program is free software; you can redistribute it and/or
7
# modify it under the terms of the GNU General Public License
8
# as published by the Free Software Foundation; either version 2
9
# of the License, or (at your option) any later version.
10
#
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
# GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19

  
20
class RedmineThemeGemGenerator < Rails::Generators::NamedBase
21
  source_root File.expand_path('templates', __dir__)
22

  
23
  attr_reader :gem_path, :theme_name, :theme_pretty_name
24

  
25
  def initialize(*args)
26
    super
27
    @theme_name = file_name.underscore
28
    @theme_pretty_name = theme_name.titleize
29
    @gem_path = Rails.root.join('gems', theme_name)
30
  end
31

  
32
  def copy_templates
33
    empty_directory "#{gem_path}/stylesheets"
34
    empty_directory "#{gem_path}/javascripts"
35
    empty_directory "#{gem_path}/images"
36

  
37
    template 'README.rdoc',    "#{gem_path}/README.rdoc"
38
    template 'Gemfile.erb',    "#{gem_path}/Gemfile"
39
    template 'Rakefile',    "#{gem_path}/Rakefile"
40
    template 'application.css', "#{gem_path}/stylesheets/application.css"
41
    template 'gemspec.erb', "#{gem_path}/#{theme_name}.gemspec"
42
  end
43
end
lib/generators/redmine_theme_gem/templates/Gemfile.erb
1
# frozen_string_literal: true
2

  
3
source "https://rubygems.org"
4

  
5
# Specify your gem's dependencies in <%= theme_name %>.gemspec
6
gemspec
7

  
lib/generators/redmine_theme_gem/templates/README.rdoc
1
= <%= file_name %>
2

  
3
Description goes here
lib/generators/redmine_theme_gem/templates/Rakefile
1
# frozen_string_literal: true
2

  
3
require "bundler/gem_tasks"
4
task default: []
lib/generators/redmine_theme_gem/templates/application.css
1
/* load the default Redmine stylesheet */
2
@import url(../../../stylesheets/application.css);
lib/generators/redmine_theme_gem/templates/gemspec.erb
1
# frozen_string_literal: true
2

  
3
Gem::Specification.new do |spec|
4

  
5
  # Do not use constants or variables from the gem's own code in this block, as is normally
6
  # done with gems. (e.g. Foo::VERSION)
7

  
8
  spec.name = "<%= theme_name %>"
9
  spec.version = "0.0.1"
10
  spec.authors = ["johndoe"]
11
  spec.email = ["johndoe@example.org"]
12

  
13
  spec.summary = "<%= theme_pretty_name %> theme"
14
  spec.description = "This is a theme for Redmine"
15
  spec.homepage = "https://example.org"
16
  spec.required_ruby_version = ">= 3.2.0"
17

  
18
  spec.metadata["author_url"] = spec.homepage
19
  spec.files = Dir["{stylesheets,javascripts,img}/**/*", "Gemfile", "README.rdoc"]
20

  
21
  # DO NOT DELETE this attribute
22
  spec.metadata["redmine_theme_id"] = "<%= theme_name %>"
23
end
(8-8/8)