require_relative 'boot'

# require 'rails/all'

require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
# require "active_storage/engine"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "action_cable/engine"
# require "sprockets/railtie"
require "rails/test_unit/railtie"

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)

module AsclepiusBackendWww
  class Application < Rails::Application
    config.load_defaults 6.0
    # 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.

    # Use redis cache store in all env
    config.cache_store = :redis_cache_store, {
      url: 'redis://127.0.0.1:6379/0',
      namespace: 'am',
      expires_in: 1.day
    }

    # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
    # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
    config.time_zone = 'Beijing'
    config.i18n.available_locales = ['zh-CN']
    config.i18n.default_locale = 'zh-CN'
    
    ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
      if html_tag =~ /<(label)/
        html_tag
      else
        html_field = Nokogiri::HTML::DocumentFragment.parse(html_tag)
        html_field.children.add_class 'is-invalid'
        (html_field.to_s + "<span class='error invalid-feedback'>#{ instance.error_message.join(',') }</span>").html_safe
      end
    end
    # Disable unnessary generator
    config.generators do |generate|
      generate.helper false
      generate.assets false
      generate.view_specs false
    end

    # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
    # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
    # config.i18n.default_locale = :de
  end
end
