Skip to content

Commit

Permalink
Update generator
Browse files Browse the repository at this point in the history
  • Loading branch information
kirkkwang committed Jul 3, 2024
1 parent 1962a47 commit 6ce1ecd
Showing 1 changed file with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ def banner
end

def create_controller
return if class_name.ends_with? "Resource"

template('controller.rb.erb', File.join('../app/controllers/hyrax', class_path, "#{plural_file_name}_controller.rb"))
end

Expand Down Expand Up @@ -119,15 +121,17 @@ def insert_hyku_works_controller_behavior
end
end

# rubocop:disable Metrics/MethodLength
def insert_hyku_extra_includes_into_model
model = File.join('../app/models/', class_path, "#{file_name}.rb")
af_model = class_name.to_s.gsub('Resource', '')&.safe_constantize if class_name.end_with?('Resource')
insert_into_file model, before: "end" do
<<-RUBY.gsub(/^ {8}/, ' ')
include Hyrax::Schema(:with_pdf_viewer)
include Hyrax::Schema(:with_video_embed)
include Hyrax::ArResource
include Hyrax::NestedWorks
#{"\n Hyrax::ValkyrieLazyMigration.migrating(self, from: #{af_model})\n" if af_model}
include IiifPrint.model_configuration(
pdf_split_child_model: GenericWorkResource,
pdf_splitter_service: IiifPrint::TenantConfig::PdfSplitter
Expand All @@ -138,6 +142,38 @@ def insert_hyku_extra_includes_into_model
end
end

def insert_hyku_extra_includes_into_form
form = File.join('../app/forms/', class_path, "#{file_name}_form.rb")
insert_into_file form, after: "include Hyrax::FormFields(:#{file_name})\n" do
" include Hyrax::FormFields(:with_pdf_viewer)\n" \
" include Hyrax::FormFields(:with_video_embed)\n" \
" include VideoEmbedBehavior::Validation\n"
end
end

def insert_hyku_extra_inclues_into_indexer
indexer = File.join('../app/indexers/', class_path, "#{file_name}_indexer.rb")
insert_into_file indexer, after: "include Hyrax::Indexer(:#{file_name})\n" do
" include HykuIndexing\n"
end
end

def change_inheritance_of_form
form = File.join('../app/forms/', class_path, "#{file_name}_form.rb")
gsub_file form, 'Hyrax::Forms::PcdmObjectForm', 'Hyrax::Forms::ResourceForm'
end

def change_inheritance_of_indexer
indexer = File.join('../app/indexers/', class_path, "#{file_name}_indexer.rb")
gsub_file indexer, "Hyrax::Indexers::PcdmObjectIndexer(#{class_name})", 'Hyrax::ValkyrieWorkIndexer'
end

def modifiy_indexer_spec
indexer_spec = File.join('../spec/indexers/', class_path, "#{file_name}_indexer_spec.rb")
# remove the let(:resource) { WorkType.new } line
gsub_file indexer_spec, /let\(:resource\) { #{class_name}\.new }\n/, "let!(:resource) { Hyrax.persister.save(resource: #{class_name}.new) }\n"
end

private

def rspec_installed?
Expand Down

0 comments on commit 6ce1ecd

Please sign in to comment.