Skip to content

Commit

Permalink
Merge pull request #100 from alexeyschepin/feat/compatibility-with-ol…
Browse files Browse the repository at this point in the history
…der-ruby-versions

Avoid using ruby 3.1 methods to keep gem compatible with older ruby versions
  • Loading branch information
dkniffin authored Aug 7, 2024
2 parents e0cc5ec + 91d3ec9 commit c7249f2
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions lib/active_material/font_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,24 @@ module FontLoader
def build_active_admin_head
within super do
uri = URI.parse(ActiveMaterial::Rails::Engine.config.active_material.font_url)
link(rel: "preconnect", href: uri.origin)
link(rel: "preconnect", href: uri.origin, crossorigin: true)
origin = extract_origin(uri)

link(rel: "preconnect", href: origin)
link(rel: "preconnect", href: origin, crossorigin: true)
link(rel: "stylesheet", href: uri.to_s)
end
end

private

def extract_origin(uri)
origin = "#{uri.scheme}://#{uri.host}"
origin += ":#{uri.port}" if uri.port && !default_port?(uri)
origin
end

def default_port?(uri)
(uri.scheme == 'http' && uri.port == 80) || (uri.scheme == 'https' && uri.port == 443)
end
end
end

0 comments on commit c7249f2

Please sign in to comment.