Class: Hyrax::RiiifGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/hyrax/riiif_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_to_gemfileObject



19
20
21
# File 'lib/generators/hyrax/riiif_generator.rb', line 19

def add_to_gemfile
  gem 'riiif', '~> 2.1'
end


15
16
17
# File 'lib/generators/hyrax/riiif_generator.rb', line 15

def banner
  say_status('info', 'GENERATING RIIIF IMAGE SERVER', :blue)
end

#copy_initializerObject



23
24
25
# File 'lib/generators/hyrax/riiif_generator.rb', line 23

def copy_initializer
  copy_file 'config/initializers/riiif.rb'
end

#copy_unauthorized_imageObject



54
55
56
# File 'lib/generators/hyrax/riiif_generator.rb', line 54

def copy_unauthorized_image
  copy_file 'app/assets/images/us_404.svg'
end

#enable_riiif_in_hyrax_configObject



31
32
33
34
35
# File 'lib/generators/hyrax/riiif_generator.rb', line 31

def enable_riiif_in_hyrax_config
  insert_into_file 'config/initializers/hyrax.rb', before: /^  # config.iiif_image_server = false/ do
    "  config.iiif_image_server = true\n"
  end
end

#mount_routeObject



27
28
29
# File 'lib/generators/hyrax/riiif_generator.rb', line 27

def mount_route
  route "mount Riiif::Engine => 'images', as: :riiif if Hyrax.config.iiif_image_server?"
end

#override_image_url_builder_in_hyrax_configObject



37
38
39
40
41
42
43
# File 'lib/generators/hyrax/riiif_generator.rb', line 37

def override_image_url_builder_in_hyrax_config
  insert_into_file 'config/initializers/hyrax.rb', before: /^  # config.iiif_image_url_builder/ do
    "  config.iiif_image_url_builder = lambda do |file_id, base_url, size, format|\n" \
    "    Riiif::Engine.routes.url_helpers.image_url(file_id, host: base_url, size: size)\n" \
    "  end\n"
  end
end

#override_info_url_builder_in_hyrax_configObject



45
46
47
48
49
50
51
52
# File 'lib/generators/hyrax/riiif_generator.rb', line 45

def override_info_url_builder_in_hyrax_config
  insert_into_file 'config/initializers/hyrax.rb', before: /^  # config.iiif_info_url_builder/ do
    "  config.iiif_info_url_builder = lambda do |file_id, base_url|\n" \
    "    uri = Riiif::Engine.routes.url_helpers.info_url(file_id, host: base_url)\n" \
    "    uri.sub(%r{/info\\.json\\Z}, '')\n" \
    "  end\n"
  end
end