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
22
23
24
25
# File 'lib/generators/hyrax/riiif_generator.rb', line 19

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

  Bundler.with_clean_env do
    run "bundle install"
  end
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


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

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

#copy_unauthorized_imageObject


52
53
54
# File 'lib/generators/hyrax/riiif_generator.rb', line 52

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

#mount_routeObject


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

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

#override_image_url_builder_in_hyrax_configObject


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

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


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

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