diff --git a/config/application.rb b/config/application.rb index 4297d3e4..c8f35ab7 100644 --- a/config/application.rb +++ b/config/application.rb @@ -26,11 +26,11 @@ class Application < Rails::Application # config.active_record.allow_deprecated_singular_associations_name = true # config.active_support.raise_on_invalid_cache_expiration_time = false # config.active_record.sqlite3_adapter_strict_strings_by_default = false - # config.active_support.cache_format_version = 7.0 + config.active_support.cache_format_version = 7.0 # Please, add to the `ignore` list any other `lib` subdirectories that do # not contain `.rb` files, or that should not be reloaded or eager loaded. # Common ones are `templates`, `generators`, or `middleware`, for example. - config.autoload_lib(ignore: %w[tasks]) + config.autoload_lib(ignore: %w[generators]) end # Making sure we don't load our dev routes as part of the engine diff --git a/lib/occams/generators/cms/README b/lib/generators/occams/cms/README similarity index 100% rename from lib/occams/generators/cms/README rename to lib/generators/occams/cms/README diff --git a/lib/occams/generators/cms/assets_generator.rb b/lib/generators/occams/cms/assets_generator.rb similarity index 100% rename from lib/occams/generators/cms/assets_generator.rb rename to lib/generators/occams/cms/assets_generator.rb diff --git a/lib/generators/occams/cms/cms_generator.rb b/lib/generators/occams/cms/cms_generator.rb new file mode 100644 index 00000000..90d7eaa3 --- /dev/null +++ b/lib/generators/occams/cms/cms_generator.rb @@ -0,0 +1,67 @@ +# frozen_string_literal: true + +require 'rails/generators/active_record' + +module Occams + module Generators + class CmsGenerator < Rails::Generators::Base + include Rails::Generators::Migration + include Thor::Actions + + source_root File.expand_path('../../../..', __dir__) + + def generate_migration + destination = File.expand_path('db/migrate/01_create_cms.rb', destination_root) + migration_dir = File.dirname(destination) + destination = self.class.migration_exists?(migration_dir, 'create_cms') + + if destination + puts "\e[0m\e[31mFound existing cms_create.rb migration. Remove it if you want to regenerate.\e[0m" + else + migration_template 'db/migrate/01_create_cms.rb', 'db/migrate/create_cms.rb' + end + end + + def generate_initializer + copy_file 'config/initializers/occams.rb', + 'config/initializers/occams.rb' + end + + def generate_railties_order + application <<~RUBY + # Ensuring that ActiveStorage routes are loaded before Occams's globbing + # route. Without this file serving routes are inaccessible. + config.railties_order = [ActiveStorage::Engine, :main_app, :all] + RUBY + end + + def generate_routing + route_string = <<~RUBY + occams_route :cms_admin, path: "/admin" + # Ensure that this route is defined last + occams_route :cms, path: "/" + RUBY + route route_string + end + + def generate_cms_seeds + directory 'db/cms_seeds', 'db/cms_seeds' + end + + def generate_assets + copy_file 'app/assets/javascripts/occams/admin/cms/custom.js', + 'app/assets/javascripts/occams/admin/cms/custom.js' + copy_file 'app/assets/stylesheets/occams/admin/cms/custom.sass', + 'app/assets/stylesheets/occams/admin/cms/custom.sass' + end + + def show_readme + readme 'lib/generators/occams/cms/README' + end + + def self.next_migration_number(dirname) + ActiveRecord::Generators::Base.next_migration_number(dirname) + end + end + end +end diff --git a/lib/occams/generators/cms/controllers_generator.rb b/lib/generators/occams/cms/controllers_generator.rb similarity index 100% rename from lib/occams/generators/cms/controllers_generator.rb rename to lib/generators/occams/cms/controllers_generator.rb diff --git a/lib/occams/generators/cms/models_generator.rb b/lib/generators/occams/cms/models_generator.rb similarity index 100% rename from lib/occams/generators/cms/models_generator.rb rename to lib/generators/occams/cms/models_generator.rb diff --git a/lib/occams/generators/cms/views_generator.rb b/lib/generators/occams/cms/views_generator.rb similarity index 100% rename from lib/occams/generators/cms/views_generator.rb rename to lib/generators/occams/cms/views_generator.rb diff --git a/lib/occams/generators/scaffold_generator.rb b/lib/generators/occams/scaffold/scaffold_generator.rb similarity index 100% rename from lib/occams/generators/scaffold_generator.rb rename to lib/generators/occams/scaffold/scaffold_generator.rb diff --git a/lib/occams/generators/templates/controller.rb.tt b/lib/generators/occams/scaffold/templates/controller.rb.tt similarity index 100% rename from lib/occams/generators/templates/controller.rb.tt rename to lib/generators/occams/scaffold/templates/controller.rb.tt diff --git a/lib/occams/generators/templates/migration.rb.tt b/lib/generators/occams/scaffold/templates/migration.rb.tt similarity index 100% rename from lib/occams/generators/templates/migration.rb.tt rename to lib/generators/occams/scaffold/templates/migration.rb.tt diff --git a/lib/occams/generators/templates/model.rb.tt b/lib/generators/occams/scaffold/templates/model.rb.tt similarity index 100% rename from lib/occams/generators/templates/model.rb.tt rename to lib/generators/occams/scaffold/templates/model.rb.tt diff --git a/lib/occams/generators/templates/tests/controller.rb.tt b/lib/generators/occams/scaffold/templates/tests/controller.rb.tt similarity index 100% rename from lib/occams/generators/templates/tests/controller.rb.tt rename to lib/generators/occams/scaffold/templates/tests/controller.rb.tt diff --git a/lib/occams/generators/templates/tests/fixture.yml.tt b/lib/generators/occams/scaffold/templates/tests/fixture.yml.tt similarity index 100% rename from lib/occams/generators/templates/tests/fixture.yml.tt rename to lib/generators/occams/scaffold/templates/tests/fixture.yml.tt diff --git a/lib/occams/generators/templates/tests/model.rb.tt b/lib/generators/occams/scaffold/templates/tests/model.rb.tt similarity index 100% rename from lib/occams/generators/templates/tests/model.rb.tt rename to lib/generators/occams/scaffold/templates/tests/model.rb.tt diff --git a/lib/occams/generators/templates/views/_form.haml.tt b/lib/generators/occams/scaffold/templates/views/_form.haml.tt similarity index 100% rename from lib/occams/generators/templates/views/_form.haml.tt rename to lib/generators/occams/scaffold/templates/views/_form.haml.tt diff --git a/lib/occams/generators/templates/views/edit.haml.tt b/lib/generators/occams/scaffold/templates/views/edit.haml.tt similarity index 100% rename from lib/occams/generators/templates/views/edit.haml.tt rename to lib/generators/occams/scaffold/templates/views/edit.haml.tt diff --git a/lib/occams/generators/templates/views/index.haml.tt b/lib/generators/occams/scaffold/templates/views/index.haml.tt similarity index 100% rename from lib/occams/generators/templates/views/index.haml.tt rename to lib/generators/occams/scaffold/templates/views/index.haml.tt diff --git a/lib/occams/generators/templates/views/new.haml.tt b/lib/generators/occams/scaffold/templates/views/new.haml.tt similarity index 100% rename from lib/occams/generators/templates/views/new.haml.tt rename to lib/generators/occams/scaffold/templates/views/new.haml.tt diff --git a/lib/occams/generators/templates/views/show.haml.tt b/lib/generators/occams/scaffold/templates/views/show.haml.tt similarity index 100% rename from lib/occams/generators/templates/views/show.haml.tt rename to lib/generators/occams/scaffold/templates/views/show.haml.tt diff --git a/lib/occams/generators/cms/cms_generator.rb b/lib/occams/generators/cms/cms_generator.rb deleted file mode 100644 index 179a469e..00000000 --- a/lib/occams/generators/cms/cms_generator.rb +++ /dev/null @@ -1,69 +0,0 @@ -# frozen_string_literal: true - -require 'rails/generators/active_record' - -module Occams - module Generators - module Cms - class CmsGenerator < Rails::Generators::Base - include Rails::Generators::Migration - include Thor::Actions - - source_root File.expand_path('../../../..', __dir__) - - def generate_migration - destination = File.expand_path('db/migrate/01_create_cms.rb', destination_root) - migration_dir = File.dirname(destination) - destination = self.class.migration_exists?(migration_dir, 'create_cms') - - if destination - puts "\e[0m\e[31mFound existing cms_create.rb migration. Remove it if you want to regenerate.\e[0m" - else - migration_template 'db/migrate/01_create_cms.rb', 'db/migrate/create_cms.rb' - end - end - - def generate_initializer - copy_file 'config/initializers/occams.rb', - 'config/initializers/occams.rb' - end - - def generate_railties_order - application <<~RUBY - # Ensuring that ActiveStorage routes are loaded before Occams's globbing - # route. Without this file serving routes are inaccessible. - config.railties_order = [ActiveStorage::Engine, :main_app, :all] - RUBY - end - - def generate_routing - route_string = <<~RUBY - occams_route :cms_admin, path: "/admin" - # Ensure that this route is defined last - occams_route :cms, path: "/" - RUBY - route route_string - end - - def generate_cms_seeds - directory 'db/cms_seeds', 'db/cms_seeds' - end - - def generate_assets - copy_file 'app/assets/javascripts/occams/admin/cms/custom.js', - 'app/assets/javascripts/occams/admin/cms/custom.js' - copy_file 'app/assets/stylesheets/occams/admin/cms/custom.sass', - 'app/assets/stylesheets/occams/admin/cms/custom.sass' - end - - def show_readme - readme 'lib/occams/generators/cms/README' - end - - def self.next_migration_number(dirname) - ActiveRecord::Generators::Base.next_migration_number(dirname) - end - end - end - end -end diff --git a/test/generators/cms_assets_generator_test.rb b/test/generators/cms_assets_generator_test.rb index e37c281e..80e89e4a 100644 --- a/test/generators/cms_assets_generator_test.rb +++ b/test/generators/cms_assets_generator_test.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require_relative '../test_helper' -require_relative '../../lib/occams/generators/cms/assets_generator' +require_relative '../../lib/generators/occams/cms/assets_generator' class CmsAssetsGeneratorTest < Rails::Generators::TestCase tests Occams::Generators::Cms::AssetsGenerator diff --git a/test/generators/cms_controllers_generator_test.rb b/test/generators/cms_controllers_generator_test.rb index 6e30b3b7..34926826 100644 --- a/test/generators/cms_controllers_generator_test.rb +++ b/test/generators/cms_controllers_generator_test.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require_relative '../test_helper' -require_relative '../../lib/occams/generators/cms/controllers_generator' +require_relative '../../lib/generators/occams/cms/controllers_generator' class CmsControllersGeneratorTest < Rails::Generators::TestCase tests Occams::Generators::Cms::ControllersGenerator diff --git a/test/generators/cms_generator_test.rb b/test/generators/cms_generator_test.rb index 7ca1b1df..eecf8fac 100644 --- a/test/generators/cms_generator_test.rb +++ b/test/generators/cms_generator_test.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true require_relative '../test_helper' -require_relative '../../lib/occams/generators/cms/cms_generator' +require_relative '../../lib/generators/occams/cms/cms_generator' class CmsGeneratorTest < Rails::Generators::TestCase - tests Occams::Generators::Cms::CmsGenerator + tests Occams::Generators::CmsGenerator def test_generator run_generator diff --git a/test/generators/cms_models_generator_test.rb b/test/generators/cms_models_generator_test.rb index 6421f559..07c000e2 100644 --- a/test/generators/cms_models_generator_test.rb +++ b/test/generators/cms_models_generator_test.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require_relative '../test_helper' -require_relative '../../lib/occams/generators/cms/models_generator' +require_relative '../../lib/generators/occams/cms/models_generator' class CmsModelsGeneratorTest < Rails::Generators::TestCase tests Occams::Generators::Cms::ModelsGenerator diff --git a/test/generators/cms_views_generator_test.rb b/test/generators/cms_views_generator_test.rb index 8cd575e2..ded8f857 100644 --- a/test/generators/cms_views_generator_test.rb +++ b/test/generators/cms_views_generator_test.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require_relative '../test_helper' -require_relative '../../lib/occams/generators/cms/views_generator' +require_relative '../../lib/generators/occams/cms/views_generator' class CmsViewsGeneratorTest < Rails::Generators::TestCase tests Occams::Generators::Cms::ViewsGenerator diff --git a/test/generators/scaffold_generator_test.rb b/test/generators/scaffold_generator_test.rb index b5772523..551b50dd 100644 --- a/test/generators/scaffold_generator_test.rb +++ b/test/generators/scaffold_generator_test.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require_relative '../test_helper' -require_relative '../../lib/occams/generators/scaffold_generator' +require_relative '../../lib/generators/occams/scaffold/scaffold_generator' class ScaffoldGeneratorTest < Rails::Generators::TestCase tests Occams::Generators::ScaffoldGenerator diff --git a/test/test_helper.rb b/test/test_helper.rb index 8c823388..c56f98c1 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -13,8 +13,8 @@ SimpleCov.command_name 'Unit Tests' SimpleCov.start 'rails' do add_filter 'lib/tasks' + add_filter 'lib/generators' add_filter 'lib/occams/engine' - add_filter 'lib/occams/generators' add_filter 'lib/occams/version' end