Skip to content

Commit

Permalink
Fix URL helpers for Liquid
Browse files Browse the repository at this point in the history
  • Loading branch information
mayorova committed Jul 22, 2024
1 parent fd9edc2 commit 82c4f99
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions lib/developer_portal/config/initializers/liquid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

Rails.application.config.to_prepare do
# Hacks
# TODO: This should only be included for Developer Portal
ActionView::Helpers.send(:include, Liquid::UrlHelperHacks)

[
Expand Down
2 changes: 2 additions & 0 deletions lib/developer_portal/lib/liquid/drops/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ def request_uri
@request.original_url
end

alias original_url request_uri

desc "Returns the host with port of the request."
def host_with_port
@request.host_with_port
Expand Down
11 changes: 6 additions & 5 deletions lib/developer_portal/lib/liquid/url_helper_hacks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ def current_page?(options)
request = controller.request

request_uri = if url_string.index("?")
request.request_uri
request.original_url
else
request.request_uri.split('?').first
request.original_url.split('?').first
end

url_string == if url_string =~ /^\w+:\/\//
Expand All @@ -22,8 +22,9 @@ def current_page?(options)
private

# Semi-hacky way to access controller from within liquid's filters and tags.
def controller
@context.registers[:controller]
end
# TODO: Ruby 3 TEMPORARY HACK! Figure this out for liquid
# def controller
# @context.registers[:controller]
# end
end
end

0 comments on commit 82c4f99

Please sign in to comment.