routing_helper.rb 889 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. # frozen_string_literal: true
  2. module RoutingHelper
  3. extend ActiveSupport::Concern
  4. include ActionView::Helpers::AssetTagHelper
  5. include Webpacker::Helper
  6. included do
  7. include Rails.application.routes.url_helpers
  8. def default_url_options
  9. ActionMailer::Base.default_url_options
  10. end
  11. end
  12. def full_asset_url(source, **options)
  13. source = ActionController::Base.helpers.asset_url(source, **options) unless use_storage?
  14. URI.join(asset_host, source).to_s
  15. end
  16. def asset_host
  17. Rails.configuration.action_controller.asset_host || root_url
  18. end
  19. def frontend_asset_path(source, **options)
  20. asset_pack_path("media/#{source}", **options)
  21. end
  22. def frontend_asset_url(source, **options)
  23. full_asset_url(frontend_asset_path(source, **options))
  24. end
  25. def use_storage?
  26. Rails.configuration.x.use_s3 || Rails.configuration.x.use_swift
  27. end
  28. end