Sha256: 3aeca41e300d9ce869d09633250f8b8b319a90b13972a95a7afe8bd17fccec12

Contents?: true

Size: 1.38 KB

Versions: 6

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

module Boring
  module SimpleForm
    class InstallGenerator < Rails::Generators::Base
      desc "Adds SimpleForm to the application"
      source_root File.expand_path("templates", __dir__)

      class_option :css_framework, type: :string, aliases: "-css",
                   desc: "Skip before_action to ensure user is authorized"
      class_option :skip_generator, type: :boolean, aliases: "-sg",
                   desc: "Skip running Pundit install generator"

      ALLOWED_CSS_FRAMEWORK = %w(bootstrap foundation)

      def add_bullet_gem
        say "Adding SimpleForm gem", :green
        Bundler.with_unbundled_env do
          run "bundle add simple_form"
        end
      end

      def run_simple_form_generator
        return if options[:skip_generator]

        say "Running SimpleForm Generator", :green
        if options[:css_framework].present? && ALLOWED_CSS_FRAMEWORK.include?(options[:css_framework])
          run "DISABLE_SPRING=1 bundle exec rails generate simple_form:install --#{options[:css_framework]}"
        elsif options[:css_framework].present?
          say <<~WARNING, :red
            ERROR: Invalid option css_framework: #{options[:css_framework]}. Generator allows css_framework: #{ALLOWED_CSS_FRAMEWORK.join(", ")}
          WARNING
        else
          run "rails generate simple_form:install"
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
boring_generators-0.15.0 lib/generators/boring/simple_form/install/install_generator.rb
boring_generators-0.14.0 lib/generators/boring/simple_form/install/install_generator.rb
boring_generators-0.13.0 lib/generators/boring/simple_form/install/install_generator.rb
boring_generators-0.12.0 lib/generators/boring/simple_form/install/install_generator.rb
boring_generators-0.11.0 lib/generators/boring/simple_form/install/install_generator.rb
boring_generators-0.10.0 lib/generators/boring/simple_form/install/install_generator.rb