Module: Admin::UrlHelper
- Included in:
- PagesController
- Defined in:
- app/helpers/admin/url_helper.rb
Instance Method Summary collapse
- #build_url(base_url, page) ⇒ Object
- #extract_base_url(url) ⇒ Object
- #generate_page_url(url, page) ⇒ Object
- #lookup_page_path(page) ⇒ Object
Instance Method Details
#build_url(base_url, page) ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'app/helpers/admin/url_helper.rb', line 4 def build_url(base_url, page) if page.class.name == 'Page' "#{base_url}#{page.path}" else path = lookup_page_path(page) path ? "#{base_url}/#{path}/#{page.slug}" : nil end end |
#extract_base_url(url) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'app/helpers/admin/url_helper.rb', line 13 def extract_base_url(url) uri = URI.parse(url) host = uri.host scheme = uri.scheme return "#{scheme}://#{host}:#{uri.port}" if host&.include?('localhost') "#{scheme}://#{host}" end |
#generate_page_url(url, page) ⇒ Object
22 23 24 25 |
# File 'app/helpers/admin/url_helper.rb', line 22 def generate_page_url(url, page) base_url = extract_base_url(url) build_url(base_url, page) end |
#lookup_page_path(page) ⇒ Object
27 28 29 30 31 32 |
# File 'app/helpers/admin/url_helper.rb', line 27 def lookup_page_path(page) # Use the globally defined PAGE_TYPE_ROUTES from the parent application return nil unless defined?(PAGE_TYPE_ROUTES) && PAGE_TYPE_ROUTES.is_a?(Hash) PAGE_TYPE_ROUTES[page.class.name.to_sym] end |