diff --git a/lib/generators/hyrax/work/templates/controller.rb.erb b/lib/generators/hyrax/work/templates/controller.rb.erb index a4a1b8da00..da9730dd82 100644 --- a/lib/generators/hyrax/work/templates/controller.rb.erb +++ b/lib/generators/hyrax/work/templates/controller.rb.erb @@ -7,5 +7,8 @@ module Hyrax include Hyrax::WorksControllerBehavior include Hyrax::BreadcrumbsForWorks self.curation_concern_type = ::<%= class_name %> + + # Use this line if you want to use a custom presenter + self.show_presenter = Hyrax::<%= class_name %>Presenter end end diff --git a/lib/generators/hyrax/work/templates/presenter.rb.erb b/lib/generators/hyrax/work/templates/presenter.rb.erb new file mode 100644 index 0000000000..9cb898e80f --- /dev/null +++ b/lib/generators/hyrax/work/templates/presenter.rb.erb @@ -0,0 +1,6 @@ +# Generated via +# `rails generate hyrax:work <%= class_name %>` +module Hyrax + class <%= class_name %>Presenter < Hyrax::WorkShowPresenter + end +end diff --git a/lib/generators/hyrax/work/templates/presenter_spec.rb.erb b/lib/generators/hyrax/work/templates/presenter_spec.rb.erb new file mode 100644 index 0000000000..6ced08d20b --- /dev/null +++ b/lib/generators/hyrax/work/templates/presenter_spec.rb.erb @@ -0,0 +1,9 @@ +# Generated via +# `rails generate hyrax:work <%= class_name %>` +require 'rails_helper' + +RSpec.describe Hyrax::<%= class_name %>Presenter do + it "has tests" do + skip "Add your tests here" + end +end diff --git a/lib/generators/hyrax/work/work_generator.rb b/lib/generators/hyrax/work/work_generator.rb index c9e5c0c853..fea7597c57 100644 --- a/lib/generators/hyrax/work/work_generator.rb +++ b/lib/generators/hyrax/work/work_generator.rb @@ -38,6 +38,10 @@ def create_form template('form.rb.erb', File.join('app/forms/hyrax', class_path, "#{file_name}_form.rb")) end + def create_presenter + template('presenter.rb.erb', File.join('app/presenters/hyrax', class_path, "#{file_name}_presenter.rb")) + end + def create_model template('model.rb.erb', File.join('app/models/', class_path, "#{file_name}.rb")) end @@ -91,6 +95,11 @@ def create_form_spec template('form_spec.rb.erb', File.join('spec/forms/hyrax/', class_path, "#{file_name}_form_spec.rb")) end + def presenter_spec + return unless rspec_installed? + template('presenter_spec.rb.erb', File.join('spec/presenters/hyrax/', class_path, "#{file_name}_form_spec.rb")) + end + def create_model_spec return unless rspec_installed? template('model_spec.rb.erb', File.join('spec/models/', class_path, "#{file_name}_spec.rb")) diff --git a/spec/features/work_generator_spec.rb b/spec/features/work_generator_spec.rb index b30e974dfa..d0c6addaf3 100644 --- a/spec/features/work_generator_spec.rb +++ b/spec/features/work_generator_spec.rb @@ -7,6 +7,7 @@ Rails::Generators.invoke('hyrax:work', ['Catapult', '--quiet'], destination_root: Rails.root) load "#{EngineCart.destination}/app/indexers/catapult_indexer.rb" load "#{EngineCart.destination}/app/models/catapult.rb" + load "#{EngineCart.destination}/app/presenters/hyrax/catapult_presenter.rb" load "#{EngineCart.destination}/app/controllers/hyrax/catapults_controller.rb" load "#{EngineCart.destination}/app/actors/hyrax/actors/catapult_actor.rb" load "#{EngineCart.destination}/app/forms/hyrax/catapult_form.rb" @@ -22,7 +23,7 @@ it 'catapults should behave like generic works' do expect(Hyrax.config.curation_concerns).to include Catapult expect(defined? Hyrax::Actors::CatapultActor).to eq 'constant' - expect(defined? Hyrax::CatapultsController).to eq 'constant' + expect(Hyrax::CatapultsController.show_presenter).to eq Hyrax::CatapultPresenter expect(defined? Hyrax::CatapultForm).to eq 'constant' expect(Catapult.indexer).to eq CatapultIndexer end