Class: Ruflet::Rails::RouteStack
- Inherits:
-
Object
- Object
- Ruflet::Rails::RouteStack
- Defined in:
- lib/ruflet/rails/route_stack.rb
Overview
Flet-style routed navigation stack for complex, multi-screen apps.
It wires up the boilerplate that Flet’s routing examples spell out by hand — on_route_change, on_view_pop and the initial page.go — so an app only has to describe, per route, how to build that screen’s View stack. The stack is rebuilt from the current route on every navigation, and the client back button (AppBar arrow / system back) pops it automatically.
Block form — one builder receives the current route and the stack:
Ruflet::Rails.routed(page) do |route, nav|
nav.push(home_view)
nav.push(store_view) if route == "/store"
end
Map form — declare a builder per route:
Ruflet::Rails::RouteStack.new(page)
.on("/") { |nav| nav.push(home_view) }
.on("/store") { |nav| nav.push(home_view); nav.push(store_view) }
.start
Navigate with page.go(“/store”); pushing onto the stack happens by rebuilding for the new route, exactly like Flet.
Instance Method Summary collapse
-
#initialize(page, &builder) ⇒ RouteStack
constructor
A new instance of RouteStack.
-
#on(route, &block) ⇒ Object
Register a per-route stack builder.
-
#push(view) ⇒ Object
Append a View (or anything responding to #route) onto the current stack.
-
#start ⇒ Object
Render the current route’s stack and begin listening for navigation.
Constructor Details
#initialize(page, &builder) ⇒ RouteStack
Returns a new instance of RouteStack.
30 31 32 33 34 35 36 |
# File 'lib/ruflet/rails/route_stack.rb', line 30 def initialize(page, &builder) @page = page @builder = builder @routes = {} @stack = [] wire_page_handlers! end |
Instance Method Details
#on(route, &block) ⇒ Object
Register a per-route stack builder. The block receives this RouteStack so it can #push one or more views for that route.
40 41 42 43 |
# File 'lib/ruflet/rails/route_stack.rb', line 40 def on(route, &block) @routes[normalize(route)] = block self end |
#push(view) ⇒ Object
Append a View (or anything responding to #route) onto the current stack.
46 47 48 49 |
# File 'lib/ruflet/rails/route_stack.rb', line 46 def push(view) @stack << view view end |
#start ⇒ Object
Render the current route’s stack and begin listening for navigation.
52 53 54 55 |
# File 'lib/ruflet/rails/route_stack.rb', line 52 def start @page.go(@page.route.to_s.empty? ? "/" : @page.route) self end |