require 'sinatra-footnotes/version' require 'sinatra/base' require 'active_support/core_ext' dir = File.dirname(__FILE__) %w[session flash cookies params sinatra_routes env assigns].each do |prefix| require File.join(dir, 'sinatra-footnotes', 'notes', "#{prefix}_note.rb") end module Sinatra module Footnotes module Helpers # Process notes to get javascript code to close them. # def close_helper(note) "Footnotes.hide(document.getElementById('#{note.to_sym}_debug_info'));\n" end # Helper that creates the link and javascript code when note is clicked # def link_helper(note) onclick = note.onclick unless href = note.link href = '#' onclick ||= "Footnotes.hideAllAndToggle('#{note.to_sym}_debug_info');return false;" if note.has_fieldset? end "#{note.title}" end def each_with_rescue(notes) notes.each do |note| begin yield note rescue Exception => e STDERR.puts "FootNotes #{note.to_s.camelize}NoteException" STDERR.puts e end end end def fieldsets(notes) content = '' each_with_rescue(notes) do |note| next unless note.has_fieldset? content << <<-HTML
HTML end content end end 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 '' response.body.push '' response.body.push '