Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #129 from Kyuden/can_use_view_note

Fix  view note on rails 3.2.x ~ 4.x
  • Loading branch information...
commit 74c7b73266b13638dd3a99dbbdae9f14cf3714af 2 parents 768fa4f + 05e9183
@Intrepidd Intrepidd authored
View
22 lib/rails-footnotes/notes/view_note.rb
@@ -1,31 +1,39 @@
module Footnotes
module Notes
class ViewNote < AbstractNote
+ cattr_accessor :template
+
+ def self.start!(controller)
+ @subscriber ||= ActiveSupport::Notifications.subscribe('render_template.action_view') do |*args|
+ event = ActiveSupport::Notifications::Event.new *args
+ self.template = {:file => event.payload[:identifier], :duration => event.duration}
+ end
+ end
+
def initialize(controller)
@controller = controller
- @template = controller.instance_variable_get(:@template)
end
def row
:edit
end
+ def title
+ "View (#{"%.3f" % self.template[:duration]}ms)"
+ end
+
def link
escape(Footnotes::Filter.prefix(filename, 1, 1))
end
def valid?
- prefix? && first_render?
+ prefix? && filename && File.exists?(filename)
end
protected
- def first_render?
- @template.instance_variable_get(:@_first_render)
- end
-
def filename
- @filename ||= @template.instance_variable_get(:@_first_render).filename
+ @filename ||= self.class.template[:file]
end
end
View
12 spec/notes/view_note_spec.rb
@@ -0,0 +1,12 @@
+require "spec_helper"
+require "rails-footnotes/notes/view_note"
+
+describe Footnotes::Notes::ViewNote do
+
+ it "should not be valid if view file not exist" do
+ note = Footnotes::Notes::ViewNote.new(double)
+ note.stub(:filename).and_return(nil)
+
+ note.should_not be_valid
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.