Skip to content

Commit acaeb28

Browse files
Alex TharpAlex Tharp
Alex Tharp
authored and
Alex Tharp
committed
Merge pull request #19 from cortex-cms/refactor-webpage-url-generation
Refactor Webpage URL Generation
2 parents ec56ee1 + 1a6167d commit acaeb28

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Version History
33
* All Version bumps are required to update this file as well!!
44
----
55

6+
* 0.5.3 - Extract a framework-agnostic sanitized_webpage_url method
67
* 0.5.2 - Addendum to previous version: fix expiry issues
78
* 0.5.1 - Set Webpage feed cache to never expire
89
* 0.5.0 - Auto-inject Client Helper into Views/Controllers. Add 10s race condition resolution to Rails cache fetch. Pass through to Snippet tag entire set of HTML attributes. Implement new namespacing and support Bundler.require.

lib/cortex/snippets/client.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ def cortex_client
1818

1919
def current_webpage(request)
2020
if defined?(Rails)
21-
Rails.cache.fetch("webpages/#{request_url(request)}", race_condition_ttl: 10) do
22-
cortex_client.webpages.get_feed(request_url(request)).contents
21+
sanitized_url = sanitized_webpage_url(request.original_url)
22+
Rails.cache.fetch("webpages/#{sanitized_url}", race_condition_ttl: 10) do
23+
cortex_client.webpages.get_feed(sanitized_url).contents
2324
end
2425
else
2526
raise 'Your Web framework is not supported. Supported frameworks: Rails'
2627
end
2728
end
2829

29-
def request_url(request)
30-
# TODO: Should be grabbing request URL in a framework-agnostic manner, but this is fine for now
31-
uri = Addressable::URI.parse(request.original_url)
30+
def sanitized_webpage_url(url)
31+
uri = Addressable::URI.parse(url)
3232
path = uri.path == '/' ? uri.path : uri.path.chomp('/')
3333
"#{uri.scheme}://#{uri.authority}#{path}"
3434
end

lib/cortex/snippets/client/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Cortex
22
module Snippets
33
module Client
4-
VERSION = '0.5.2'
4+
VERSION = '0.5.3'
55
end
66
end
77
end

0 commit comments

Comments
 (0)