Class: Footnotes::Notes::AbstractNote
- Inherits:
-
Object
- Object
- Footnotes::Notes::AbstractNote
- Defined in:
- lib/rails-footnotes/abstract_note.rb
Overview
This is the abstract class for notes. You can overwrite all instance public methods to create your notes.
Direct Known Subclasses
AssignsNote, ControllerNote, CookiesNote, EnvNote, FilesNote, FiltersNote, LayoutNote, LogNote, ParamsNote, PartialsNote, QueriesNote, RoutesNote, SessionNote, ViewNote
Class Method Summary collapse
-
.close!(controller = nil) ⇒ Object
Action to be called after the Note was used.
-
.included? ⇒ Boolean
Return true if Note is included in notes array.
-
.start!(controller = nil) ⇒ Object
Action to be called to start the Note.
-
.title ⇒ Object
Returns the title that represents this note.
-
.to_sym ⇒ Object
Returns the symbol that represents this note.
Instance Method Summary collapse
-
#escape(text) ⇒ Object
Escape HTML special characters.
-
#has_fieldset? ⇒ Boolean
Specifies when should create a fieldset for it, considering it’s valid.
- #hash_to_xml_attributes(hash) ⇒ Object
-
#initialize(controller = nil) ⇒ AbstractNote
constructor
Initialize notes.
-
#javascript ⇒ Object
Insert here any additional javascript.
-
#legend ⇒ Object
If has_fieldset? is true, create a fieldset with the value returned as legend.
-
#link ⇒ Object
Set href field for Footnotes links.
-
#mount_table(array, options = {}) ⇒ Object
Gets a bidimensional array and create a table.
-
#mount_table_for_hash(hash, options = {}) ⇒ Object
Mount table for hash, using name and value and adding a name_value class to the generated table.
-
#onclick ⇒ Object
Set onclick field for Footnotes links.
-
#prefix? ⇒ Boolean
Return if Footnotes::Filter.prefix exists or not.
-
#row ⇒ Object
Specifies in which row should appear the title.
-
#stylesheet ⇒ Object
Insert here any additional stylesheet.
-
#title ⇒ Object
Returns the title to be used as link.
-
#to_sym ⇒ Object
Returns the symbol that represents this note.
-
#valid? ⇒ Boolean
Specifies when should create a note for it.
Constructor Details
#initialize(controller = nil) ⇒ AbstractNote
Initialize notes. Always receives a controller.
51 52 |
# File 'lib/rails-footnotes/abstract_note.rb', line 51 def initialize(controller = nil) end |
Class Method Details
.close!(controller = nil) ⇒ Object
Action to be called after the Note was used. This is applied as an after_filter.
44 45 |
# File 'lib/rails-footnotes/abstract_note.rb', line 44 def close!(controller = nil) end |
.included? ⇒ Boolean
Return true if Note is included in notes array.
31 32 33 |
# File 'lib/rails-footnotes/abstract_note.rb', line 31 def included? Footnotes::Filter.notes.include?(self.to_sym) end |
.start!(controller = nil) ⇒ Object
Action to be called to start the Note. This is applied as a before_filter.
38 39 |
# File 'lib/rails-footnotes/abstract_note.rb', line 38 def start!(controller = nil) end |
.title ⇒ Object
Returns the title that represents this note. It’s the name of the class without Note.
For example, for ControllerNote it will return Controller.
25 26 27 |
# File 'lib/rails-footnotes/abstract_note.rb', line 25 def title @note_title ||= self.name.match(/^Footnotes::Notes::(\w+)Note$/)[1] end |
.to_sym ⇒ Object
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.
16 17 18 |
# File 'lib/rails-footnotes/abstract_note.rb', line 16 def to_sym @note_sym ||= self.title.underscore.to_sym end |
Instance Method Details
#escape(text) ⇒ Object
Escape HTML special characters.
136 137 138 |
# File 'lib/rails-footnotes/abstract_note.rb', line 136 def escape(text) text.gsub('&', '&').gsub('<', '<').gsub('>', '>') end |
#has_fieldset? ⇒ Boolean
Specifies when should create a fieldset for it, considering it’s valid.
120 121 122 |
# File 'lib/rails-footnotes/abstract_note.rb', line 120 def has_fieldset? self.respond_to?(:content) end |
#hash_to_xml_attributes(hash) ⇒ Object
169 170 171 172 173 174 175 |
# File 'lib/rails-footnotes/abstract_note.rb', line 169 def hash_to_xml_attributes(hash) newstring = "" hash.each do |key, value| newstring << "#{key.to_s}=\"#{value.gsub('"','\"')}\" " end return newstring end |
#javascript ⇒ Object
Insert here any additional javascript. This is directly inserted into a <script> tag.
108 109 |
# File 'lib/rails-footnotes/abstract_note.rb', line 108 def javascript end |
#legend ⇒ Object
If has_fieldset? is true, create a fieldset with the value returned as legend. By default, returns the title of the class (defined above).
77 78 79 |
# File 'lib/rails-footnotes/abstract_note.rb', line 77 def legend self.class.title end |
#link ⇒ Object
Set href field for Footnotes links. If it’s nil, Footnotes will use ‘#’.
90 91 |
# File 'lib/rails-footnotes/abstract_note.rb', line 90 def link end |
#mount_table(array, options = {}) ⇒ Object
Gets a bidimensional array and create a table. The first array is used as label.
143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/rails-footnotes/abstract_note.rb', line 143 def mount_table(array, = {}) 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 <table #{hash_to_xml_attributes()}> <thead><tr><th>#{header.join('</th><th>')}</th></tr></thead> <tbody>#{rows.join}</tbody> </table> TABLE end |
#mount_table_for_hash(hash, options = {}) ⇒ Object
Mount table for hash, using name and value and adding a name_value class to the generated table.
161 162 163 164 165 166 167 |
# File 'lib/rails-footnotes/abstract_note.rb', line 161 def mount_table_for_hash(hash, ={}) rows = [] hash.each do |key, value| rows << [ key.to_sym.inspect, escape(value.inspect) ] end mount_table(rows.unshift(['Name', 'Value']), {:class => 'name_value'}.merge()) end |
#onclick ⇒ Object
Set onclick field for Footnotes links. If it’s nil, Footnotes will make it open the fieldset.
96 97 |
# File 'lib/rails-footnotes/abstract_note.rb', line 96 def onclick end |
#prefix? ⇒ Boolean
Return if Footnotes::Filter.prefix exists or not. Some notes only work with prefix set.
130 131 132 |
# File 'lib/rails-footnotes/abstract_note.rb', line 130 def prefix? !Footnotes::Filter.prefix.blank? end |
#row ⇒ Object
Specifies in which row should appear the title. The default is :show.
63 64 65 |
# File 'lib/rails-footnotes/abstract_note.rb', line 63 def row :show end |
#stylesheet ⇒ Object
Insert here any additional stylesheet. This is directly inserted into a <style> tag.
102 103 |
# File 'lib/rails-footnotes/abstract_note.rb', line 102 def stylesheet end |
#title ⇒ Object
Returns the title to be used as link. The default is the note title.
70 71 72 |
# File 'lib/rails-footnotes/abstract_note.rb', line 70 def title self.class.title end |
#to_sym ⇒ Object
Returns the symbol that represents this note.
56 57 58 |
# File 'lib/rails-footnotes/abstract_note.rb', line 56 def to_sym self.class.to_sym end |
#valid? ⇒ Boolean
Specifies when should create a note for it. By default, it’s valid.
114 115 116 |
# File 'lib/rails-footnotes/abstract_note.rb', line 114 def valid? true end |