module Sinatra::Footnotes

Constants

VERSION

Public Class Methods

registered(app) click to toggle source
# File lib/sinatra-footnotes.rb, line 57
def self.registered(app)
  app.helpers Footnotes::Helpers

  app.after do
    style_path = File.join(
      File.dirname(__FILE__), 'sinatra-footnotes', 'style.html')
    if response.body.respond_to? :push
      response.body.push File.read(style_path)

      response.body.push '<!-- Footnotes -->'
      response.body.push '<div style="clear:both"></div>'
      response.body.push '<div id="footnotes_debug">'
      response.body.push 'Show:'

      notes = []
      notes.push ::Footnotes::Notes::SessionNote.new(self)
      notes.push ::Footnotes::Notes::FlashNote.new(self)
      notes.push ::Footnotes::Notes::CookiesNote.new(self.request)
      notes.push ::Footnotes::Notes::ParamsNote.new(self)
      notes.push ::Footnotes::Notes::SinatraRoutesNote.new(app)
      notes.push ::Footnotes::Notes::EnvNote.new(self)
      notes.push(::Footnotes::Notes::AssignsNote.new(self).tap do |note|
        note.ignored_assigns = [:@default_layout, :@app, :@template_cache,
                                :@env, :@request, :@response, :@params,
                                :@preferred_extension, :@_out_buf, :@_routes]
      end)

      response.body.push notes.map { |note| link_helper(note) }.join(' | ')
      response.body.push '<br />'

      response.body.push fieldsets(notes)

      script_path = File.join(
        File.dirname(__FILE__), 'sinatra-footnotes', 'script.html')
      response.body.push(File.read(script_path))

      response.body.push '</div>'
      response.body.push '<!-- End Footnotes -->'
    end
  end
end