Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ gem 'propshaft'
gem 'puma'
gem 'stimulus-rails'
gem 'turbo-rails'

# TODO: figure out why these need to be here for the specs to run
gem 'doorkeeper'
gem 'mcp'

Expand Down
4 changes: 2 additions & 2 deletions bin/dummy_app_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def ruby_version = nil
def node_version = nil

def generate_test_dummy
invoke Rails::Generators::AppGenerator, [ File.expand_path(dummy_path) ], {
invoke Rails::Generators::AppGenerator, [ File.expand_path(app_path) ], {
dummy_app: true,
force: true,
database: 'postgresql',
Expand All @@ -30,6 +30,6 @@ def generate_test_dummy
end

def test_dummy_config
template 'boot.rb', "#{dummy_path}/config/boot.rb", force: true
directory 'config', "#{app_path}/config", force: true
end
end
23 changes: 15 additions & 8 deletions bin/new_generator
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env ruby
require 'thor'
require 'active_support/core_ext/string/inflections'
require 'active_support'
require 'active_support/core_ext'

class NewGenerator < Thor::Group
include Thor::Actions
Expand All @@ -16,19 +17,25 @@ class NewGenerator < Thor::Group
directory 'generator_spec', "spec/generators/rolemodel/#{module_name.underscore}"
end

def bump_version_number
in_root do
run 'bin/bump_version'
end
end

private

def module_name = name.camelize.deconstantize
def class_name = name.camelize.demodulize + 'Generator'
def filename = class_name.underscore
def command_name = ['rolemodel', *name.split('/').map(&:underscore)].join(':')

def modules
@modules ||= name.camelize.split("::")[0...-1].unshift('Rolemodel')
end

def wrap_in_modules(&)
modules.each_with_index do |mod, index|
concat "#{' ' * index}module #{mod}\n"
end
(capture(&).strip + "\n").each_line { concat ' ' * modules.size + it }
modules.size.times.reverse_each { concat ' ' * it + "end\n" }
end

class << self
def banner
<<~BANNER
Expand All @@ -40,7 +47,7 @@ private
end

def desc = 'New Generator Scaffold'
def source_root = File.expand_path('lib/generators/templates')
def source_root = File.expand_path('templates/new_generator', __dir__)
end
end

Expand Down
8 changes: 2 additions & 6 deletions bin/recreate_current_example
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ RAILS_VERSION = '8.1.3'
require_relative 'dummy_app_builder'

class RecreateCurrentExample < Rails::Generators::AppBase
source_root File.expand_path('templates', __dir__)
source_root File.expand_path('templates/dummy_app', __dir__)

def recreate_example
shell.mute do
Expand All @@ -16,11 +16,7 @@ class RecreateCurrentExample < Rails::Generators::AppBase

private

def dummy_path
@dummy_path ||= "./example_rails_current"
end

def get_builder_class = BuilderClass
end

RecreateCurrentExample.start(["--app-path=example_rails_current"])
RecreateCurrentExample.start(["example_rails_current"])
File renamed without changes.
9 changes: 9 additions & 0 deletions bin/templates/new_generator/generator/%filename%.rb.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<% wrap_in_modules do %>
class <%= class_name %> < ::Rolemodel::GeneratorBase
source_root File.expand_path('templates', __dir__)

def generate_stuff
say 'generating stuff', :green
end
end
<% end %>
2 changes: 1 addition & 1 deletion example_rails_current/config/database.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# PostgreSQL. Versions 9.3 and up are supported.
# PostgreSQL. Versions 9.5 and up are supported.
#
# Install the pg driver:
# gem install pg
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rolemodel/all_generator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Rolemodel
class AllGenerator < BaseGenerator
class AllGenerator < GeneratorBase
source_root File.expand_path('templates', __dir__)

def run_all_the_generators
Expand Down
16 changes: 0 additions & 16 deletions lib/generators/rolemodel/base_generator.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/generators/rolemodel/editors/editors_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module Rolemodel
# Add standard editorconfig and any extensions to enable it
class EditorsGenerator < BaseGenerator
class EditorsGenerator < GeneratorBase
include Rolemodel::VSCodeHelpers

# This is bringing in the root from this gem, so we only modify
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rolemodel/github/github_generator.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Rolemodel
class GithubGenerator < BaseGenerator
class GithubGenerator < GeneratorBase
GITHUB_ACTIONS_REPO = 'https://github.com/RoleModel/actions.git'
# Files which are both used by the gem source and copied to the target app without modification
# are placed in the `.github` folder at the top level of this repository. This folder is then
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rolemodel/good_job/good_job_generator.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Rolemodel
class GoodJobGenerator < BaseGenerator
class GoodJobGenerator < GeneratorBase
source_root File.expand_path('templates', __dir__)

def install_good_job
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rolemodel/heroku/heroku_generator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Rolemodel
class HerokuGenerator < BaseGenerator
class HerokuGenerator < GeneratorBase
source_root File.expand_path('templates', __dir__)

def install_app_json
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rolemodel/kaminari/kaminari_generator.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Rolemodel
class KaminariGenerator < BaseGenerator
class KaminariGenerator < GeneratorBase
source_root File.expand_path('templates', __dir__)

def install_kaminari
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rolemodel/linters/all_generator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Rolemodel
module Linters
class AllGenerator < BaseGenerator
class AllGenerator < GeneratorBase
source_root File.expand_path('templates', __dir__)

def run_all_the_generators
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Rolemodel
module Linters
class EslintGenerator < BaseGenerator
class EslintGenerator < GeneratorBase
include ReplaceContentHelper
source_root File.expand_path('templates', __dir__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Rolemodel
module Linters
# Install the standard rubocop and a custom cop
class RubocopGenerator < BaseGenerator
class RubocopGenerator < GeneratorBase
source_root File.expand_path('templates', __dir__)

def install_rubocop
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rolemodel/lograge/lograge_generator.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Rolemodel
class LogrageGenerator < BaseGenerator
class LogrageGenerator < GeneratorBase
source_root File.expand_path('templates', __dir__)

def install_lograge
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rolemodel/mailers/mailers_generator.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Rolemodel
class MailersGenerator < BaseGenerator
class MailersGenerator < GeneratorBase
source_root File.expand_path('templates', __dir__)

def install_premailer_rails
Expand Down
5 changes: 3 additions & 2 deletions lib/generators/rolemodel/mcp/mcp_generator.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Rolemodel
class MCPGenerator < BaseGenerator
class McpGenerator < GeneratorBase
source_root File.expand_path('templates', __dir__)

def update_inflections
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the generator going to be able to be run a second time if the inflections are setup? Or don't inflections affect gems?

Copy link
Copy Markdown
Member Author

@OutlawAndy OutlawAndy Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just testing on the example app, host application inflections do not affect gem file loading. Which I think makes sense. Rails inflections affect constant look up because they're tied into the Rails autoloader, but RMR's generators are not loaded by the Zeitwerk autoloader. They are just added to the Ruby FILE_PATH

Expand Down Expand Up @@ -53,6 +53,7 @@ def add_sample_mcp_tool

def install_doorkeeper
bundle_command 'add doorkeeper'
run_bundle
generate 'doorkeeper:install'
end

Expand Down Expand Up @@ -103,7 +104,7 @@ def add_well_known_route
private

def application_name
Rails.application.class.try(:parent_name) || Rails.application.class.module_parent_name
Rails.application.name
end
end
end
2 changes: 1 addition & 1 deletion lib/generators/rolemodel/optics/all_generator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Rolemodel
module Optics
class AllGenerator < Rolemodel::BaseGenerator
class AllGenerator < Rolemodel::GeneratorBase
source_root File.expand_path('templates', __dir__)

def run_all_the_generators
Expand Down
4 changes: 2 additions & 2 deletions lib/generators/rolemodel/optics/base/base_generator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Rolemodel
module Optics
class BaseGenerator < Rolemodel::BaseGenerator
class BaseGenerator < Rolemodel::GeneratorBase
source_root File.expand_path('templates', __dir__)

def add_optics_package
Expand All @@ -12,7 +12,7 @@ def add_optics_package
def copy_templates
say 'importing stylesheet', :green

prepend_to_file 'app/assets/stylesheets/application.scss', <<~SCSS
prepend_to_file Dir.glob('app/assets/stylesheets/application.*').first, <<~SCSS
@import '@rolemodel/optics/dist/css/optics';
SCSS
end
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rolemodel/optics/icons/icons_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Rolemodel
module Optics
# Generates the icon helper and icon builders for the chosen icon library
class IconsGenerator < Rolemodel::BaseGenerator
class IconsGenerator < Rolemodel::GeneratorBase
SUPPORTED_LIBRARIES = HashWithIndifferentAccess.new(
material: 'filled, size, weight, emphasis, additional_classes, color, hover_text',
phosphor: 'duotone, filled, size, weight, additional_classes, color, hover_text',
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rolemodel/react/react_generator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Rolemodel
class ReactGenerator < BaseGenerator
class ReactGenerator < GeneratorBase
source_root File.expand_path('templates', __dir__)

def add_npm_packages
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rolemodel/readme/readme_generator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Rolemodel
class ReadmeGenerator < BaseGenerator
class ReadmeGenerator < GeneratorBase
source_root File.expand_path('templates', __dir__)

def install_readme
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rolemodel/saas/all_generator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Rolemodel
module Saas
class AllGenerator < BaseGenerator
class AllGenerator < GeneratorBase
source_root File.expand_path('templates', __dir__)

def run_all_the_generators
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rolemodel/saas/devise/devise_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Rolemodel
module Saas
class DeviseGenerator < BaseGenerator
class DeviseGenerator < GeneratorBase
source_root File.expand_path('templates', __dir__)

def add_organization
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rolemodel/semaphore/semaphore_generator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Rolemodel
class SemaphoreGenerator < BaseGenerator
class SemaphoreGenerator < GeneratorBase
source_root File.expand_path('templates', __dir__)

def create_base_semaphore_config
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Rolemodel
class SimpleFormGenerator < BaseGenerator
class SimpleFormGenerator < GeneratorBase
source_root File.expand_path('templates', __dir__)

def add_gem
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rolemodel/slim/slim_generator.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Rolemodel
class SlimGenerator < BaseGenerator
class SlimGenerator < GeneratorBase
source_root File.expand_path('templates', __dir__)

def add_slim
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Rolemodel
class SoftDestroyableGenerator < BaseGenerator
class SoftDestroyableGenerator < GeneratorBase
source_root File.expand_path('templates', __dir__)

def add_concern
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Rolemodel
class SourceMapGenerator < BaseGenerator
class SourceMapGenerator < GeneratorBase
source_root File.expand_path('templates', __dir__)

def inject_config_for_production
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Rolemodel
class TailoredSelectGenerator < BaseGenerator
class TailoredSelectGenerator < GeneratorBase
source_root File.expand_path('templates', __dir__)

def add_tailored_select_package
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rolemodel/testing/all_generator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Rolemodel
module Testing
class AllGenerator < BaseGenerator
class AllGenerator < GeneratorBase
source_root File.expand_path('templates', __dir__)

def run_all_the_generators
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Rolemodel
module Testing
class FactoryBotGenerator < BaseGenerator
class FactoryBotGenerator < GeneratorBase
source_root File.expand_path('templates', __dir__)

def install_factory_bot_rails
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Rolemodel
module Testing
class JasminePlaywrightGenerator < BaseGenerator
class JasminePlaywrightGenerator < GeneratorBase
include ReplaceContentHelper
source_root File.expand_path('templates', __dir__)
class_option :github_package_token, type: :string, default: ENV['GITHUB_PACKAGES_TOKEN'], desc: 'GitHub Packages token with access to @rolemodel packages'
Expand Down
Loading