Enhance RouteHelpers
- page_route() accepts nil and return base_url - clean_url() accepts multiple args and join them
This commit is contained in:
@@ -39,7 +39,7 @@ module Precious
|
|||||||
route_path = "#{prefix}/#{path}"
|
route_path = "#{prefix}/#{path}"
|
||||||
@@route_methods[name.to_s] = route_path
|
@@route_methods[name.to_s] = route_path
|
||||||
define_method :"#{name.to_s}_path" do
|
define_method :"#{name.to_s}_path" do
|
||||||
"#{base_url}/#{route_path}".gsub(/\/{2,}/, '/') # remove double slashes
|
page_route(route_path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -53,8 +53,15 @@ module Precious
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def page_route(page)
|
def page_route(page = nil)
|
||||||
"#{base_url}/#{page}".gsub(/\/{2,}/, '/') # remove double slashes
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user