Introduce JS variant of path helpers

This commit is contained in:
Dawa Ometto
2018-12-10 19:54:21 +01:00
parent 253ba89f90
commit 04501c205a
4 changed files with 73 additions and 95 deletions
+8 -2
View File
@@ -1,4 +1,4 @@
require 'yaml'
require 'json'
module Precious
module Views
@@ -26,15 +26,21 @@ module Precious
if path.respond_to?(:keys)
self.parse_routes(path, "#{prefix}/#{name}")
else
route_path = "#{prefix}/#{path}"
@@route_methods[name.to_s] = route_path
define_method :"#{name.to_s}_path" do
"#{base_url}/#{prefix}/#{path}".gsub(/\/{2,}/, '/') # remove double slashes
"#{base_url}/#{route_path}".gsub(/\/{2,}/, '/') # remove double slashes
end
end
end
end
def self.included(base)
@@route_methods = {}
self.parse_routes(ROUTES)
define_method :routes_to_json do
@@route_methods.to_json
end
end
end