Class Footnotes::Notes::AbstractNote
In: lib/rails-footnotes/notes/abstract_note.rb
Parent: Object

This is the abstract class for notes. You can overwrite all instance public methods to create your notes.

Methods

close!   escape   has_fieldset?   hash_to_xml_attributes   included?   javascript   legend   link   mount_table   new   onclick   prefix?   row   start!   stylesheet   title   title   to_sym   to_sym   valid?  

Public Class methods

Action to be called after the Note was used. This is applied as an after_filter.

[Source]

# File lib/rails-footnotes/notes/abstract_note.rb, line 44
        def close!(controller = nil)
        end

Return true if Note is included in notes array.

[Source]

# File lib/rails-footnotes/notes/abstract_note.rb, line 31
        def included?
          Footnotes::Filter.notes.include?(self.to_sym)
        end

Initialize notes. Always receives a controller.

[Source]

# File lib/rails-footnotes/notes/abstract_note.rb, line 51
      def initialize(controller = nil)
      end

Action to be called to start the Note. This is applied as a before_filter.

[Source]

# File lib/rails-footnotes/notes/abstract_note.rb, line 38
        def start!(controller = nil)
        end

Returns the title that represents this note. It‘s the name of the class without Note.

For example, for ControllerNote it will return Controller.

[Source]

# File lib/rails-footnotes/notes/abstract_note.rb, line 25
        def title
          @note_title ||= self.name.match(/^Footnotes::Notes::(\w+)Note$/)[1]
        end

Returns the symbol that represents this note. It‘s the name of the class, underscored and without _note.

For example, for ControllerNote it will return :controller.

[Source]

# File lib/rails-footnotes/notes/abstract_note.rb, line 16
        def to_sym
          @note_sym ||= self.title.underscore.to_sym
        end

Public Instance methods

Specifies when should create a fieldset for it, considering it‘s valid.

[Source]

# File lib/rails-footnotes/notes/abstract_note.rb, line 120
      def has_fieldset?
        self.respond_to?(:content)
      end

Insert here any additional javascript. This is directly inserted into a <script> tag.

[Source]

# File lib/rails-footnotes/notes/abstract_note.rb, line 108
      def javascript
      end

If has_fieldset? is true, create a fieldset with the value returned as legend. By default, returns the title of the class (defined above).

[Source]

# File lib/rails-footnotes/notes/abstract_note.rb, line 77
      def legend
        self.class.title
      end

Set href field for Footnotes links. If it‘s nil, Footnotes will use ’#’.

[Source]

# File lib/rails-footnotes/notes/abstract_note.rb, line 90
      def link
      end

Set onclick field for Footnotes links. If it‘s nil, Footnotes will make it open the fieldset.

[Source]

# File lib/rails-footnotes/notes/abstract_note.rb, line 96
      def onclick
      end

Specifies in which row should appear the title. The default is :show.

[Source]

# File lib/rails-footnotes/notes/abstract_note.rb, line 63
      def row
        :show
      end

Insert here any additional stylesheet. This is directly inserted into a <style> tag.

[Source]

# File lib/rails-footnotes/notes/abstract_note.rb, line 102
      def stylesheet
      end

Returns the title to be used as link. The default is the note title.

[Source]

# File lib/rails-footnotes/notes/abstract_note.rb, line 70
      def title
        self.class.title
      end

Returns the symbol that represents this note.

[Source]

# File lib/rails-footnotes/notes/abstract_note.rb, line 56
      def to_sym
        self.class.to_sym
      end

Specifies when should create a note for it. By default, it‘s valid.

[Source]

# File lib/rails-footnotes/notes/abstract_note.rb, line 114
      def valid?
        true
      end

Protected Instance methods

Escape HTML special characters.

[Source]

# File lib/rails-footnotes/notes/abstract_note.rb, line 136
        def escape(text)
          text.gsub('&', '&amp;').gsub('<', '&lt;').gsub('>', '&gt;')
        end

[Source]

# File lib/rails-footnotes/notes/abstract_note.rb, line 159
        def hash_to_xml_attributes(hash)
          return hash.collect{ |key, value| "#{key.to_s}=\"#{value.gsub('"','\"')}\"" }.join(' ')
        end

Gets a bidimensional array and create a table. The first array is used as label.

[Source]

# File lib/rails-footnotes/notes/abstract_note.rb, line 143
        def mount_table(array, options = {})
          header = array.shift
          return '' if array.empty?

          header = header.collect{|i| escape(i.to_s.humanize) }
          rows = array.collect{|i| "<tr><td>#{i.join('</td><td>')}</td></tr>" }

          "<table \#{hash_to_xml_attributes(options)}>\n<thead><tr><th>\#{header.join('</th><th>')}</th></tr></thead>\n<tbody>\#{rows.join}</tbody>\n</table>\n"
        end

Return if Footnotes::Filter.prefix exists or not. Some notes only work with prefix set.

[Source]

# File lib/rails-footnotes/notes/abstract_note.rb, line 130
        def prefix?
          !Footnotes::Filter.prefix.blank?
        end

[Validate]