Middleman Extensions: How to get an instance of an activated extension?

I’m building a Middleman extension for making sites that act like digital books.
I’d like some helper methods in this extension to access some data or methods stored in the parent extension’s instance.

I know that a new instance of a MyExtension class is created upon activation, but I can’t seem to figure out a good way to get a handle on it during runtime. Any suggestions on how to call some of its instance methods within a helper method?

Specifically, I’m trying to create a Book extension to organize book-y things like chapters, frontmatter/backmatter, etc. and I’d like to write some next_chapter and prev_chapter helper methods, which would ideally be able to get a full chapter list from the extension itself (keeping this logic out of my templates).

Thanks,

Eric

To make this more concrete, here’s essentially what I’m trying to do:

class Book < Middleman::Extension                                                                                                                              
  def initialize(app, options_hash = {}, &block)                                                                                                               
    super                                                                                                                                                      
  end                                                                                                                                                          
             
  # Ideally a "chapters" method could be used inside helpers
  # and would return a list of all chapters in order when called                                                                                                                                                  
  def chapters                                                                                                                                                 
    contents = @app.sitemap.resources.find_all { |p| p.data.sort_order }                                                                                       
    contents.sort_by { |p| p.data.sort_order }                                                                                                                 
  end                                                                                                                                                          
                                                                                                                                                               
  helpers do                                                                                                                                                                                                                                                                                                               
    def next_chapter_path                                                                                                                                      
      # this is what I'd like to do but it doesn't work                                                                                                               
      max  = chapters.max_by { |p| p.data.sort_order }                                                                                                       
                                                                                                                                                               
      return false unless current_page.data.sort_order                                                                                                         
      return false unless current_page.data.sort_order < max.data.sort_order                                                                                   
      curr = current_page.data.sort_order                                                                                                                      
      next_chap = sitemap.resources.find { |p| p.data.sort_order == curr - 1 }                                                                                 
      next_chap ? next_chap : false                                                                                                                            
    end                                                                                                                                                        
  end                                                                                                                                                          
end                                                                                                                                                            
                                                                                                                                                               
::Middleman::Extensions.register(:book, Book)                                                                                                                  

Actually, some examination of the helper methods of the Middleman Blog extension proves useful. It looks like this data can be found by calling the extensions method of the Middleman::Application instance and using the registered name of the extension as an argument:

app.extensions[:book] # => returns instance of activated extension

I think this is what I was looking for, but I’ll leave this up in case this info is helpful to anyone else.