Sha256: 08fd485b4940e40c0750958923cb994a7366c5426a07845576238ea0afcb67a4

Contents?: true

Size: 1.36 KB

Versions: 1

Compression:

Stored size: 1.36 KB

Contents

require 'rails/generators'

module BlacklightOembed
  class Install < Rails::Generators::Base

    source_root File.expand_path('../templates', __FILE__)

    def assets
      copy_file "blacklight_oembed.css.scss", "app/assets/stylesheets/blacklight_oembed.css.scss"
      copy_file "blacklight_oembed.js", "app/assets/javascripts/blacklight_oembed.js"
    end

    def inject_routes
      route "mount Blacklight::Oembed::Engine, at: 'oembed'"
    end

    def inject_oembed_configuration
      copy_file "oembed_providers.rb", "config/initializers/oembed_providers.rb"
    end

    def appease_sprockets4
      append_to_file 'app/assets/config/manifest.js', "\n//= link blacklight-oembed/oembed.js"
    end

    def configuration
      inject_into_file 'app/controllers/catalog_controller.rb', after: 'configure_blacklight do |config|' do
        if ENV['CI_TEST_LEGACY_CONFIGURATION'].present? || Gem::Version.new(Blacklight::VERSION) < Gem::Version.new('8.0')
          <<-EOF

            config.show.oembed_field = :oembed_url_ssm
            config.show.partials.insert(1, :oembed)
          EOF
        else
          <<-EOF

          config.show.oembed_field = :oembed_url_ssm
          config.show.render_oembed_using_async_javascript = true
          config.show.embed_component = Blacklight::Oembed::DocumentOembedComponent
          EOF
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
blacklight-oembed-1.4.1 lib/generators/blacklight_oembed/install_generator.rb