Skip to content
This repository
file 69 lines (52 sloc) 1.605 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
require 'rails'
require 'action_controller'
require 'rails-footnotes/abstract_note'
require 'rails-footnotes/each_with_rescue'
require 'rails-footnotes/filter'
require 'rails-footnotes/notes/all'
require 'rails-footnotes/extension'
require 'active_support/deprecation'

module Footnotes
  mattr_accessor :before_hooks
  @@before_hooks = []

  mattr_accessor :after_hooks
  @@after_hooks = []

  mattr_accessor :enabled
  @@enabled = false

  class << self
    delegate :notes, :to => Filter
    delegate :notes=, :to => Filter

    delegate :prefix, :to => Filter
    delegate :prefix=, :to => Filter

    delegate :no_style, :to => Filter
    delegate :no_style=, :to => Filter

    delegate :multiple_notes, :to => Filter
    delegate :multiple_notes=, :to => Filter

    delegate :lock_top_right, :to => Filter
    delegate :lock_top_right=, :to => Filter

    delegate :font_size, :to => Filter
    delegate :font_size=, :to => Filter
  end

  def self.run!
    ActiveSupport::Deprecation.warn "run! is deprecated and will be removed from future releases, use Footnotes.setup or Footnotes.enabled instead.", caller
    Footnotes.enabled = true
  end

  def self.before(&block)
    @@before_hooks << block
  end

  def self.after(&block)
    @@after_hooks << block
  end

  def self.enabled?
    if @@enabled.is_a? Proc
      @@enabled.call
    else
      !!@@enabled
    end
  end

  def self.setup
    yield self
  end
end

ActionController::Base.send(:include, Footnotes::RailsFootnotesExtension)

load Rails.root.join('.rails_footnotes') if Rails.root && Rails.root.join('.rails_footnotes').exist?
Something went wrong with that request. Please try again.