Sha256: 062031c76f1b8d620d43c7aa16df8f0dc23ff9bbc02d496058bc5832b6806dd7

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 KB

Contents

require 'rails/generators'

module Openseadragon
  class Install < Rails::Generators::Base
    source_root File.expand_path('templates', __dir__)

    def append_javascript
      run 'yarn init -y'
      gsub_file 'package.json', /\.internal_test_app/, 'internal_test_app' # name beginning with a dot is illegal
      run 'yarn add openseadragon-rails'

      run 'bin/importmap pin openseadragon' if File.exist?('bin/importmap')

      append_to_file 'app/javascript/application.js' do
        <<~CONTENT

          import "openseadragon"
          import "openseadragon-rails"

        CONTENT
      end
    end

    def append_image_paths
      append_to_file 'config/initializers/assets.rb' do
        "\nRails.application.config.assets.paths << Rails.root.join('node_modules/openseadragon/build/openseadragon/images')\n"
      end
    end

    def inject_helper
      inject_into_class 'app/controllers/application_controller.rb', ApplicationController do
        "  helper Openseadragon::OpenseadragonHelper\n"
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
openseadragon-1.0.16 lib/generators/openseadragon/install_generator.rb
openseadragon-1.0.15 lib/generators/openseadragon/install_generator.rb
openseadragon-1.0.14 lib/generators/openseadragon/install_generator.rb