class Tourmaline::RoutedMenu

Overview

The RoutedMenu helper class offers a simple to use DSL for creating menus, potentially with multiple levels. Includes support for HTTP like routing, route history, back buttons, and more.

Routes are hashed and shortened before being sent, which means you have no need to worry about the typical 65 character callback query data limit.

Example:

MENU = RoutedMenu.build do
  route "/" do
    content "Some content to go in the home route"
    buttons do
      route_button "Next page", "/page_2"
    end
  end

  route "/page_2" do
    content "..."
    buttons do
      back_button "Back"
    end
  end
end

# in a command
send_menu(chat_id, MENU)

Defined in:

tourmaline/extra/routed_menu.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(routes : Hash(String, Tourmaline::RoutedMenu::Page) = {} of String => Page, start_route = "/", group = Helpers.random_string(8)) #

[View source]

Class Method Detail

def self.build(starting_route = "/", **options, &) #

[View source]
def self.hash_route(route : String) #

[View source]

Instance Method Detail

def add_route(route, page) #

[View source]
def current_page #

[View source]
def current_route : String #

[View source]
def event_handler : EventHandler #

[View source]
def handle_button_click(ctx) #

[View source]
def route_history : Array(String) #

[View source]
def routes : Hash(String, Page) #

[View source]