Sha256: 1d72a59c1eac6cbe300568ee4d13b468f680d16cfcdfd1b59354f64f4fa666a0

Contents?: true

Size: 1.99 KB

Versions: 3

Compression:

Stored size: 1.99 KB

Contents

# Routable
A UIViewController->URL router.

```ruby
  @router.map("profile/:id", ProfileController)

  # Later on...

  # Pushes a ProfileController with .initWithParams(:id => 189)
  @router.open("profile/189")
```

Why is this awesome? Because now you can push any view controller from any part of the app with just a string: buttons, push notifications, anything.

## Installation

```ruby
gem install routable
```

And now in your Rakefile, require `routable`:

```ruby
$:.unshift("/Library/RubyMotion/lib")
require 'motion/project'
require 'routable'

Motion::Project::App.setup do |app|
  ...
end
```

## Setup

For every UIViewController you want routable with `:symbolic` params, you need to define `.initWithParams({})`.

```ruby
class ProfileController < UIViewController
  attr_accessor :user_id

  def initWithParams(params = {})
    init()
    self.user_id = params[:user_id]
    self
  end
end
```

Here's an example of how you could setup Routable for the entire application:

```ruby
class AppDelegate
  def application(application, didFinishLaunchingWithOptions:launchOptions)

    @window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
    @window.makeKeyAndVisible

    # Make our URLs
    map_urls

    # .open(url, animated)
    if User.logged_in_user
      @router.open("menu", false)
    else
      @router.open("login", false)
    end

    true
  end

  def map_urls
    @router = Routable::Router.router
    @router.navigation_controller = UINavigationController.alloc.init

    # :modal means we push it modally.
    @router.map("login", LoginController, modal: true)
    # :shared means it will only keep one instance of this VC in the hierarchy;
    # if we push it again later, it will pop any covering VCs.
    @router.map("menu", MenuController, shared: true)
    @router.map("profile/:id", ProfileController)
    @router.map("messages", MessagesController)
    @router.map("message/:id", MessageThreadController)

    @window.rootViewController = @router.navigation_controller
  end
end
```

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
routable-0.0.3 README.md
routable-0.0.2 README.md
routable-0.0.1 README.md