Module: JsxRosetta::PagesRouting::Naming
- Defined in:
- lib/jsx_rosetta/pages_routing.rb
Overview
Derives Rails route names and URL helper names from a Route. Used by both the routes.rb emitter (slice 1’s ‘as:` lines) and the Phlex backend’s href rewriter (slice 3) so the names stay paired.
Class Method Summary collapse
Class Method Details
.base_route_name(route) ⇒ Object
102 103 104 105 106 107 108 109 110 |
# File 'lib/jsx_rosetta/pages_routing.rb', line 102 def base_route_name(route) case route.action when "index" then route.controller when "show" then AST::Inflector.singularize(route.controller) when "new" then "new_#{AST::Inflector.singularize(route.controller)}" when "edit" then "edit_#{AST::Inflector.singularize(route.controller)}" else "#{route.controller}_#{route.action}" end end |
.route_name(route) ⇒ Object
88 89 90 91 92 93 94 95 96 |
# File 'lib/jsx_rosetta/pages_routing.rb', line 88 def route_name(route) return "root" if route.rails_path == "/" && route.controller == "pages" && route.action == "index" && route.namespace.empty? base = base_route_name(route) return base if route.namespace.empty? "#{route.namespace.join("_")}_#{base}" end |
.url_helper_name(route) ⇒ Object
98 99 100 |
# File 'lib/jsx_rosetta/pages_routing.rb', line 98 def url_helper_name(route) "#{route_name(route)}_path" end |