diff --git a/config/application.rb b/config/application.rb index 850a2b515..c221d0090 100644 --- a/config/application.rb +++ b/config/application.rb @@ -9,7 +9,34 @@ Bundler.require(*groups) module Hyku + # Providing a common method to ensure consistent UTF-8 encoding. Also removing the tricksy Byte + # Order Marker character which is an invisible 0 space character. + # + # @note In testing, we encountered errors with the file's character encoding + # (e.g. `Encoding::UndefinedConversionError`). The following will force the encoding to + # UTF-8 and replace any invalid or undefined characters from the original encoding with a + # "?". + # + # Given that we still have the original, and this is a derivative, the forced encoding + # should be acceptable. + # + # @param [String] + # @return [String] + # + # @see https://sentry.io/organizations/scientist-inc/issues/3773392603/?project=6745020&query=is%3Aunresolved&referrer=issue-stream + # @see https://github.com/samvera-labs/bulkrax/pull/689 + # @see https://github.com/samvera-labs/bulkrax/issues/688 + # @see https://github.com/scientist-softserv/adventist-dl/issues/179 + def self.utf_8_encode(string) + string + .encode(Encoding.find('UTF-8'), invalid: :replace, undef: :replace, replace: "?") + .delete("\xEF\xBB\xBF") + end + class Application < Rails::Application + # Add this line to load the lib folder first because we need + config.autoload_paths.unshift("#{Rails.root}/lib") + # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. @@ -33,22 +60,33 @@ class Application < Rails::Application end config.to_prepare do - # Allows us to use decorator files in the app directory + + # Add any extra services before IiifPrint::PluggableDerivativeService to enable processing + Hyrax::DerivativeService.services = [IiifPrint::PluggableDerivativeService] + + # When you are ready to use the derivative rodeo instead of the pluggable uncomment the + # following and comment out the preceding Hyrax::DerivativeService.service + # + # Hyrax::DerivativeService.services = [ + # Adventist::TextFileTextExtractionService, + # IiifPrint::DerivativeRodeoService, + # Hyrax::FileSetDerivativesService] + + DerivativeRodeo::Generators::HocrGenerator.additional_tessearct_options = "-l eng_best" + + # Allows us to use decorator files Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")).sort.each do |c| Rails.configuration.cache_classes ? require(c) : load(c) end - end - config.to_prepare do - # Allows us to use decorator files in the app directory Dir.glob(File.join(File.dirname(__FILE__), "../lib/**/*_decorator*.rb")).sort.each do |c| Rails.configuration.cache_classes ? require(c) : load(c) end - end - # OAI additions - Dir.glob(File.join(File.dirname(__FILE__), "../lib/oai/**/*.rb")).sort.each do |c| - Rails.configuration.cache_classes ? require(c) : load(c) + # OAI additions + Dir.glob(File.join(File.dirname(__FILE__), "../lib/oai/**/*.rb")).sort.each do |c| + Rails.configuration.cache_classes ? require(c) : load(c) + end end # resolve reloading issue in dev mode @@ -67,6 +105,8 @@ class Application < Rails::Application Object.include(AccountSwitch) end + # copies tinymce assets directly into public/assets + config.tinymce.install = :copy ## # Psych Allow YAML Classes #