Class: Hyrax::IiifViewerGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Hyrax::IiifViewerGenerator
- Defined in:
- lib/generators/hyrax/iiif_viewer/iiif_viewer_generator.rb
Instance Method Summary collapse
Instance Method Details
#configure_viewer ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/generators/hyrax/iiif_viewer/iiif_viewer_generator.rb', line 27 def configure_viewer config = Pathname.new(dest_root).join("config", "initializers", "hyrax.rb") lastmatch = nil content = "\n # Injected via `rails generate hyrax:iiif_viewer #{viewer}`\n" \ " config.iiif_av_viewer = :#{viewer}\n\n" File.open(config).each_line do |line| regex = /config.iiif_av_viewer = .*/ if behavior == :revoke # When removing/revoking, we return nil if the line includes # our viewer name because we want to delete the line instead # of using it as the "after" anchor. lastmatch = line if line.match?(regex) && line.exclude?(viewer.to_s) elsif line.match?(regex) lastmatch = line end end anchor = lastmatch || "Hyrax.config do |config|\n" insert_into_file(config, content, after: anchor) end |
#copy_partial ⇒ Object
21 22 23 24 25 |
# File 'lib/generators/hyrax/iiif_viewer/iiif_viewer_generator.rb', line 21 def copy_partial filename = "_#{viewer}.html.erb" dest = Pathname.new(dest_root).join("app", "views", "hyrax", "base", "iiif_viewers", filename) copy_file(filename, dest) end |
#copy_viewer_files ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/generators/hyrax/iiif_viewer/iiif_viewer_generator.rb', line 13 def copy_viewer_files viewer_path = Pathname.new(dest_root).join('public', viewer.to_s) directory(viewer.to_s, viewer_path) return unless behavior == :revoke && Dir.exist?(viewer_path) FileUtils.rmdir(viewer_path) say_status :remove, viewer_path, :red end |