Module: Admin::UrlHelper
- Included in:
- PagesController, ApplicationHelper
- Defined in:
- app/helpers/admin/url_helper.rb
Instance Method Summary collapse
- #build_url(base_url, page) ⇒ Object
- #default_route?(page) ⇒ Boolean
- #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
9 10 11 12 13 14 15 16 |
# File 'app/helpers/admin/url_helper.rb', line 9 def build_url(base_url, page) return "#{base_url}#{page.path}" if default_route?(page) path = lookup_page_path(page) return nil unless path "#{base_url}/#{path}/#{page.slug}" end |
#default_route?(page) ⇒ Boolean
27 28 29 30 |
# File 'app/helpers/admin/url_helper.rb', line 27 def default_route?(page) page_class_name = page.class.name page_class_name == 'Page' || (defined?(DEFAULT_PAGE_TYPE_ROUTES) && DEFAULT_PAGE_TYPE_ROUTES.include?(page_class_name)) end |
#extract_base_url(url) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'app/helpers/admin/url_helper.rb', line 18 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
4 5 6 7 |
# File 'app/helpers/admin/url_helper.rb', line 4 def generate_page_url(url, page) base_url = extract_base_url(url) build_url(base_url, page) end |
#lookup_page_path(page) ⇒ Object
32 33 34 35 36 |
# File 'app/helpers/admin/url_helper.rb', line 32 def lookup_page_path(page) return nil unless defined?(CUSTOM_PAGE_TYPE_ROUTES) && CUSTOM_PAGE_TYPE_ROUTES.is_a?(Hash) CUSTOM_PAGE_TYPE_ROUTES[page.class.name.to_sym] end |