How do I add a Sinatra extension? (Simple-navigation, to build menus)

I’m trying to adapt simple-navigation to Middleman.

Edit: After digging some more, I’m not sure that Middleman is a subclass of Sinatra::Base. If not, the following is irrelevant, and my questions are simply: Is it possible to use Sinatra Extensions? How?

In order to get it to work, I need to register it. The simple-navigation documentation describes this method:

class MyApp < Sinatra::Base
  register Sinatra::SimpleNavigation

Where would a suitable place be for a Middleman extension to do this registration?

My best guess is this:

module Simple_navigation       
  class << self
    def registered(app)
      app.register Sinatra::SimpleNavigation
      ...

Would that be equivalent to the method in the simple-navigation documentation?

Or is this better:

module Simple_navigation       
  class << self
    def registered(app)
      app.superclass.register Sinatra::SimpleNavigation
      ...

(The class of app is Middleman::Application::MiddlemanApplication1 , while the class of app.superclass is Middleman::Application.)

You would use the map method in your config.rb like so:

map "/sinatra" do
  run MySinatra
end
1 Like