Class: Footnotes::Filter
- Inherits:
-
Object
- Object
- Footnotes::Filter
- Extended by:
- EachWithRescue
- Defined in:
- lib/rails-footnotes/filter.rb
Constant Summary collapse
- @@no_style =
false
- @@multiple_notes =
false
- @@klasses =
[]
- @@prefix =
Default link prefix is textmate
'txmt://open?url=file://%s&line=%d&column=%d'
- @@notes =
Edit notes
[ :controller, :view, :layout, :partials, :stylesheets, :javascripts ]
Class Method Summary collapse
-
.prefix(*args) ⇒ Object
If none argument is sent, simply return the prefix.
-
.start!(controller) ⇒ Object
Calls the class method start! in each note Sometimes notes need to set variables or clean the environment to work properly This method allows this kind of setup.
Instance Method Summary collapse
- #add_footnotes! ⇒ Object
-
#close!(controller) ⇒ Object
Calls the class method close! in each note Sometimes notes need to finish their work even after being read This method allows this kind of work.
-
#initialize(controller) ⇒ Filter
constructor
A new instance of Filter.
Methods included from EachWithRescue
Constructor Details
#initialize(controller) ⇒ Filter
Returns a new instance of Filter.
52 53 54 55 56 57 |
# File 'lib/rails-footnotes/filter.rb', line 52 def initialize(controller) @controller = controller @template = controller.instance_variable_get(:@template) @body = controller.response.body @notes = [] end |
Class Method Details
.prefix(*args) ⇒ Object
If none argument is sent, simply return the prefix. Otherwise, replace the args in the prefix.
42 43 44 45 46 47 48 |
# File 'lib/rails-footnotes/filter.rb', line 42 def prefix(*args) if args.empty? @@prefix else format(@@prefix, *args) end end |
.start!(controller) ⇒ Object
Calls the class method start! in each note Sometimes notes need to set variables or clean the environment to work properly This method allows this kind of setup
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rails-footnotes/filter.rb', line 28 def start!(controller) self.each_with_rescue(Footnotes.before_hooks) {|hook| hook.call(controller, self)} @@klasses = [] self.each_with_rescue(@@notes.flatten) do |note| klass = "Footnotes::Notes::#{note.to_s.camelize}Note".constantize klass.start!(controller) if klass.respond_to?(:start!) @@klasses << klass end end |
Instance Method Details
#add_footnotes! ⇒ Object
59 60 61 62 63 64 |
# File 'lib/rails-footnotes/filter.rb', line 59 def add_footnotes! add_footnotes_without_validation! if valid? rescue Exception => e # Discard footnotes if there are any problems self.class.log_error("Footnotes Exception", e) end |
#close!(controller) ⇒ Object
Calls the class method close! in each note Sometimes notes need to finish their work even after being read This method allows this kind of work
70 71 72 73 |
# File 'lib/rails-footnotes/filter.rb', line 70 def close!(controller) self.each_with_rescue(@@klasses) {|klass| klass.close!(controller)} self.each_with_rescue(Footnotes.after_hooks) {|hook| hook.call(controller, self)} end |