Module: ActiveAdminAssets::URLPatch

Defined in:
lib/activeadmin_assets/url_patch.rb

Overview

Modify asset URLs for active admins assets:

  • prepend special path (includes VERSIONs to bust caches on gem updates)

  • prevent sprockets or propshaft from adding digests to the asset URLs

Instance Method Summary collapse

Instance Method Details

#active_admin_asset?(path) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/activeadmin_assets/url_patch.rb', line 19

def active_admin_asset?(path)
  %r{\A/?(?:active_admin|flowbite|rails_ujs_esm)(?:[/.]|\z)}.match?(path)
end

#path_to_asset(path) ⇒ Object

this is called by importmap-rails, too



13
14
15
16
17
# File 'lib/activeadmin_assets/url_patch.rb', line 13

def path_to_asset(path, ...)
  return super unless active_admin_asset?(path)

  path.sub(%r{\A/?}, ActiveAdminAssets.path)
end


6
7
8
9
10
# File 'lib/activeadmin_assets/url_patch.rb', line 6

def stylesheet_link_tag(path, ...)
  return super unless active_admin_asset?(path)

  tag.link(rel: :stylesheet, href: path_to_asset("#{path.chomp('.css')}.css"))
end