Files
grecia/config/application.rb
Javi Martín d54971e536 Use Dart Sass to compile SCSS files
SassC/Libsass has been deprecated for years and has been replaced by
Dart Sass. However, the dartsass-rails gem, maintained by the Rails
team, doesn't support sprockets integration and doesn't allow glob
imports (using `@import something/**/*` or similar). In particular,
dartsass-rails needs to start a separate browser that makes it less
straightforward to change a file and reload the browser.

So we're using sassc-embedded, which provides Dart Sass integration with
sprockets. While there's no guarantee this gem will be maintained a few
years from now, we know for sure that SassC/Libsass won't be maintained
at all, so using sassc-embedded is an improvement over our current
situation.

On my machine, this change reduces compilation times by about 35%.

Note we still depend on the `sassc-rails` gem, for two reasons.

First, we're still importing CSS/Sass content from a couple of gems
(mainly, social-share-button and font-awesome) and we don't know how to
import this content without the `sassc-rails` gem.

And, second, it provides support for glob imports. Without it, we'd have
to manually add every single (S)CSS file we import to the
`application.scss` file instead of being able to write things like
`@import admin/**/*";`.

Note we're removing the `sass` gem from `Gemfile.lock`. We should have
done it as part of e210682ac, but when we developed that branch, it
didn't contain the changes where we removed another gem depending on the
`sass` gem (which we removed in commit 2fa713c64), so Bundler didn't
delete it. However, now that we're changing the Gemfile, Bundler is
finally removing the no-longer-needed `sass` gem and its dependencies.
2024-04-04 15:15:28 +02:00

168 lines
5.5 KiB
Ruby

require "sassc-embedded"
require_relative "boot"
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_mailbox/engine"
# require "action_text/engine"
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 Consul
class Application < Rails::Application
config.load_defaults 6.1
# Keep belongs_to fields optional by default, because that's the way
# Rails 4 models worked
config.active_record.belongs_to_required_by_default = false
# Keep using AES-256-CBC for message encryption in case it's used
# in any CONSUL DEMOCRACY installations
config.active_support.use_authenticated_message_encryption = false
# Keep using the classic autoloader until we decide how custom classes
# should work with zeitwerk
config.autoloader = :classic
# Don't enable has_many_inversing because it doesn't seem to currently
# work with the _count database columns we use for caching purposes
config.active_record.has_many_inversing = false
# Disable Sprockets AssetUrlProcessor for CKEditor compatibility
config.assets.resolve_assets_in_css_urls = false
# Keep reading existing data in the legislation_annotations ranges column
config.active_record.yaml_column_permitted_classes = [ActiveSupport::HashWithIndifferentAccess, Symbol]
# Handle custom exceptions
config.action_dispatch.rescue_responses["FeatureFlags::FeatureDisabled"] = :forbidden
config.action_dispatch.rescue_responses["Apartment::TenantNotFound"] = :not_found
# Store uploaded files on the local file system (see config/storage.yml for options).
config.active_storage.service = :local
# 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 = Rails.application.secrets.time_zone.presence || "Madrid"
# 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 = :en
available_locales = [
"ar",
"bg",
"bs",
"ca",
"cs",
"da",
"de",
"el",
"en",
"es",
"es-PE",
"eu",
"fa",
"fr",
"gd",
"gl",
"he",
"hr",
"id",
"it",
"ka",
"ne",
"nl",
"oc",
"pl",
"pt-BR",
"ro",
"ru",
"sl",
"sq",
"so",
"sr",
"sv",
"tr",
"uk-UA",
"val",
"zh-CN",
"zh-TW"
]
config.i18n.available_locales = available_locales
config.i18n.fallbacks = [I18n.default_locale, {
"ca" => "es",
"es-PE" => "es",
"eu" => "es",
"fr" => "es",
"gl" => "es",
"it" => "es",
"oc" => "fr",
"pt-BR" => "es",
"val" => "es"
}]
config.i18n.load_path += Dir[Rails.root.join("config", "locales", "**[^custom]*", "*.{rb,yml}")]
config.i18n.load_path += Dir[Rails.root.join("config", "locales", "custom", "**", "*.{rb,yml}")]
config.after_initialize do
Globalize.set_fallbacks_to_all_available_locales
end
config.assets.paths << Rails.root.join("app", "assets", "fonts")
config.assets.paths << Rails.root.join("vendor", "assets", "fonts")
config.assets.paths << Rails.root.join("node_modules", "jquery-ui", "themes", "base")
config.assets.paths << Rails.root.join("node_modules")
# Add lib to the autoload path
config.autoload_paths << Rails.root.join("lib")
config.active_job.queue_adapter = :delayed_job
# CONSUL DEMOCRACY specific custom overrides
# Read more on documentation:
# * English: https://github.com/consuldemocracy/consuldemocracy/blob/master/CUSTOMIZE_EN.md
# * Spanish: https://github.com/consuldemocracy/consuldemocracy/blob/master/CUSTOMIZE_ES.md
#
config.autoload_paths << "#{Rails.root}/app/components/custom"
config.autoload_paths << "#{Rails.root}/app/controllers/custom"
config.autoload_paths << "#{Rails.root}/app/graphql/custom"
config.autoload_paths << "#{Rails.root}/app/mailers/custom"
config.autoload_paths << "#{Rails.root}/app/models/custom"
config.autoload_paths << "#{Rails.root}/app/models/custom/concerns"
config.paths["app/views"].unshift(Rails.root.join("app", "views", "custom"))
# Set to true to enable user authentication log
config.authentication_logs = Rails.application.secrets.authentication_logs || false
# Set to true to enable devise user lockable feature
config.devise_lockable = Rails.application.secrets.devise_lockable
# Set to true to enable managing different tenants using the same application
config.multitenancy = Rails.application.secrets.multitenancy
end
end
class Rails::Engine
initializer :prepend_custom_assets_path, group: :all do |app|
if self.class.name == "Consul::Application"
%w[images fonts].each do |asset|
app.config.assets.paths.unshift(Rails.root.join("app", "assets", asset, "custom").to_s)
end
end
end
end
require "./config/application_custom"