Enhance RouteHelpers

- page_route() accepts nil and return base_url
- clean_url() accepts multiple args and join them
This commit is contained in:
Watal M. Iwasaki
2020-06-14 22:49:26 +09:00
parent 8e7a714991
commit e310f76030
+10 -3
View File
@@ -39,7 +39,7 @@ module Precious
route_path = "#{prefix}/#{path}"
@@route_methods[name.to_s] = route_path
define_method :"#{name.to_s}_path" do
"#{base_url}/#{route_path}".gsub(/\/{2,}/, '/') # remove double slashes
page_route(route_path)
end
end
end
@@ -53,8 +53,15 @@ module Precious
end
end
def page_route(page)
"#{base_url}/#{page}".gsub(/\/{2,}/, '/') # remove double slashes
def page_route(page = nil)
clean_url(@base_url, page)
end
def clean_url(*url)
url.compact!
return url if url.nil?
::File.join(*url).gsub(%r{/{2,}}, '/')
end
end