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


18
19
20
21
22
23
24
# File 'lib/generators/hyrax/riiif_generator.rb', line 18

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

  Bundler.with_clean_env do
    run "bundle install"
  end
end

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

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

#copy_initializerObject


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

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

#copy_unauthorized_imageObject


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

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

#mount_routeObject


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

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

#override_image_url_builder_in_hyrax_configObject


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

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|\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


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

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