rails-footnotes 3.7.2 → 3.7.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/.gitignore +2 -0
  2. data/.rspec.example +1 -0
  3. data/.watchr.example +13 -0
  4. data/Gemfile +1 -1
  5. data/README.rdoc +9 -6
  6. data/Rakefile +5 -6
  7. data/lib/rails-footnotes.rb +4 -3
  8. data/lib/rails-footnotes/{notes/abstract_note.rb → abstract_note.rb} +4 -4
  9. data/lib/rails-footnotes/footnotes.rb +0 -6
  10. data/lib/rails-footnotes/notes/all.rb +1 -0
  11. data/lib/rails-footnotes/notes/assigns_note.rb +3 -5
  12. data/lib/rails-footnotes/notes/controller_note.rb +11 -28
  13. data/lib/rails-footnotes/notes/cookies_note.rb +1 -3
  14. data/lib/rails-footnotes/notes/env_note.rb +0 -2
  15. data/lib/rails-footnotes/notes/files_note.rb +1 -3
  16. data/lib/rails-footnotes/notes/filters_note.rb +4 -6
  17. data/lib/rails-footnotes/notes/general_note.rb +1 -3
  18. data/lib/rails-footnotes/notes/javascripts_note.rb +1 -3
  19. data/lib/rails-footnotes/notes/layout_note.rb +0 -2
  20. data/lib/rails-footnotes/notes/log_note.rb +4 -6
  21. data/lib/rails-footnotes/notes/params_note.rb +0 -2
  22. data/lib/rails-footnotes/notes/partials_note.rb +0 -2
  23. data/lib/rails-footnotes/notes/queries_note.rb +0 -2
  24. data/lib/rails-footnotes/notes/routes_note.rb +1 -3
  25. data/lib/rails-footnotes/notes/session_note.rb +0 -2
  26. data/lib/rails-footnotes/notes/stylesheets_note.rb +1 -3
  27. data/lib/rails-footnotes/notes/view_note.rb +0 -2
  28. data/lib/rails-footnotes/version.rb +1 -1
  29. data/rails-footnotes.gemspec +2 -2
  30. data/spec/abstract_note_spec.rb +80 -0
  31. data/spec/footnotes_spec.rb +215 -0
  32. data/{test/test_helper.rb → spec/spec_helper.rb} +7 -3
  33. metadata +17 -17
  34. data/lib/rails-footnotes/backtracer.rb +0 -36
  35. data/lib/rails-footnotes/notes/rpm_note.rb +0 -30
  36. data/test/footnotes_test.rb +0 -222
  37. data/test/notes/abstract_note_test.rb +0 -107
data/.gitignore CHANGED
@@ -1,9 +1,11 @@
1
1
  .*
2
2
  !.gitignore
3
3
  !.gitmodules
4
+ !*.example
4
5
  *.gem
5
6
  .bundle
6
7
  Gemfile.lock
7
8
  pkg/*
9
+ coverage
8
10
  tags
9
11
  doc
data/.rspec.example ADDED
@@ -0,0 +1 @@
1
+ --color
data/.watchr.example ADDED
@@ -0,0 +1,13 @@
1
+ ROOT_PATH = File.dirname(__FILE__)
2
+
3
+ def run_spec(file)
4
+ system "rspec #{file}" if File.exist?(File.join(ROOT_PATH, file))
5
+ end
6
+
7
+ watch('spec/.*_spec\.rb') {|m| run_spec m[0] }
8
+ watch('spec/notes/.*_spec\.rb') {|m| run_spec m[0] }
9
+
10
+ watch('lib/rails-footnotes/(.*)\.rb') {|m| run_spec("spec/#{m[1]}_spec.rb") }
11
+ watch('lib/rails-footnotes/notes/.*_note\.rb') {|m| run_spec("spec/notes/#{m[1]}") }
12
+
13
+ watch('Gemfile') {|m| run_spec("spec") }
data/Gemfile CHANGED
@@ -7,6 +7,6 @@ gemspec
7
7
  #
8
8
  if RUBY_PLATFORM =~ /darwin/
9
9
  group :test do
10
- gem "autotest-growl"
10
+ gem 'simplecov', '>= 0.4.0', :require => false
11
11
  end
12
12
  end
data/README.rdoc CHANGED
@@ -38,6 +38,14 @@ add something like this to config/initializers/footnotes.rb:
38
38
  # ... other init code
39
39
  end
40
40
 
41
+ === Post initialization
42
+
43
+ If you want to add alternate logic to config footnotes without commit it to SCM, add your code to .footnotes:
44
+
45
+ Footnotes::Filter.notes = []
46
+
47
+ this code temporarily disables notes for all controllers
48
+
41
49
  === Hooks
42
50
 
43
51
  Footnotes.setup do |config|
@@ -50,7 +58,7 @@ add something like this to config/initializers/footnotes.rb:
50
58
  If you are not using Textmate as text editor, in your environment.rb or
51
59
  in an initializer do:
52
60
 
53
- Footnotes::Filter.prefix = 'mvim://open?url=file://%s&line=%d&column=%d'
61
+ Footnotes::Filter.prefix = 'mvim://open?url=file://%s&line=%d&column=%d'
54
62
 
55
63
  for MacVim
56
64
 
@@ -68,11 +76,6 @@ Another option is to allow multiple notes to be opened at the same time:
68
76
 
69
77
  Footnotes::Filter.multiple_notes = true
70
78
 
71
- If you have New Relic RPM installed, you may want to turn off query explains
72
- (explains can slows things down)
73
-
74
- Footnotes::Notes::QueriesNote.sql_explain = false
75
-
76
79
  Finally, you can control which notes you want to show. The default are:
77
80
 
78
81
  Footnotes::Filter.notes = [:session, :cookies, :params, :filters, :routes, :env, :queries, :log, :general]
data/Rakefile CHANGED
@@ -1,16 +1,15 @@
1
1
  require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
- require 'rake/testtask'
3
+ require "rspec/core/rake_task"
4
4
  require 'rake/rdoctask'
5
5
 
6
6
  desc 'Default: run tests'
7
- task :default => :test
7
+ task :default => :spec
8
8
 
9
9
  desc 'Run tests for Footnotes.'
10
- Rake::TestTask.new(:test) do |t|
11
- t.libs << 'test'
12
- t.pattern = 'test/**/*_test.rb'
13
- t.verbose = true
10
+ RSpec::Core::RakeTask.new(:spec) do |t|
11
+ t.pattern = 'spec/**/*_spec.rb'
12
+ t.rcov = false
14
13
  end
15
14
 
16
15
  desc 'Generate documentation for Footnotes.'
@@ -26,11 +26,12 @@ module Footnotes
26
26
 
27
27
  def self.run!
28
28
  require 'rails-footnotes/footnotes'
29
- require 'rails-footnotes/backtracer'
30
-
31
- Dir[File.join(File.dirname(__FILE__), 'rails-footnotes', 'notes', '*.rb')].each { |note| require note }
29
+ require 'rails-footnotes/abstract_note'
30
+ require 'rails-footnotes/notes/all'
32
31
 
33
32
  ActionController::Base.send(:include, RailsFootnotesExtension)
33
+
34
+ load Rails.root.join('.footnotes') if Rails.root.join('.footnotes').exist?
34
35
  end
35
36
 
36
37
  def self.setup
@@ -86,13 +86,13 @@ module Footnotes
86
86
 
87
87
  # Set href field for Footnotes links.
88
88
  # If it's nil, Footnotes will use '#'.
89
- #
89
+ #
90
90
  def link
91
91
  end
92
92
 
93
93
  # Set onclick field for Footnotes links.
94
94
  # If it's nil, Footnotes will make it open the fieldset.
95
- #
95
+ #
96
96
  def onclick
97
97
  end
98
98
 
@@ -123,7 +123,7 @@ module Footnotes
123
123
 
124
124
  # Some helpers to generate notes.
125
125
  #
126
- protected
126
+ public
127
127
  # Return if Footnotes::Filter.prefix exists or not.
128
128
  # Some notes only work with prefix set.
129
129
  #
@@ -171,7 +171,7 @@ module Footnotes
171
171
  newstring = ""
172
172
  hash.each do |key, value|
173
173
  newstring << "#{key.to_s}=\"#{value.gsub('"','\"')}\" "
174
- end
174
+ end
175
175
  return newstring
176
176
  end
177
177
  end
@@ -29,12 +29,6 @@ module Footnotes
29
29
  # Show notes
30
30
  @@notes += [ :assigns, :session, :cookies, :params, :filters, :routes, :env, :queries, :log, :general ]
31
31
 
32
- # Change queries for rpm note when available
33
- # if defined?(NewRelic)
34
- # @@notes.delete(:queries)
35
- # @@notes << :rpm
36
- # end
37
-
38
32
  # :no_style => If you don't want the style to be appended to your pages
39
33
  # :notes => Class variable that holds the notes to be processed
40
34
  # :prefix => Prefix appended to FootnotesLinks
@@ -0,0 +1 @@
1
+ Dir[File.join(File.dirname(__FILE__), '*_note.rb')].each {|note| require note}
@@ -1,5 +1,3 @@
1
- require "#{File.dirname(__FILE__)}/abstract_note"
2
-
3
1
  module Footnotes
4
2
  module Notes
5
3
  class AssignsNote < AbstractNote
@@ -44,11 +42,11 @@ module Footnotes
44
42
  def assigns
45
43
  assign = []
46
44
  ignored = @@ignored_assigns
47
-
45
+
48
46
  @controller.instance_variables.each {|x| assign << x.intern }
49
47
  @controller.protected_instance_variables.each {|x| ignored << x.intern } if @controller.respond_to? :protected_instance_variables
50
-
51
- assign -= ignored
48
+
49
+ assign -= ignored
52
50
  return assign
53
51
  end
54
52
 
@@ -1,5 +1,3 @@
1
- require "#{File.dirname(__FILE__)}/abstract_note"
2
-
3
1
  module Footnotes
4
2
  module Notes
5
3
  class ControllerNote < AbstractNote
@@ -12,47 +10,32 @@ module Footnotes
12
10
  end
13
11
 
14
12
  def link
15
- if controller_filename && controller_line_number
16
- escape(Footnotes::Filter.prefix(controller_filename, controller_line_number + 1, 3))
17
- end
13
+ Footnotes::Filter.prefix(controller_filename, controller_line_number + 1, 3)
18
14
  end
19
15
 
20
16
  def valid?
21
- prefix?
17
+ prefix? && File.exists?(self.controller_filename)
22
18
  end
23
19
 
24
20
  protected
25
- # Some controller classes come with the Controller:: module and some don't
26
- # (anyone know why? -- Duane)
21
+ def controller_path
22
+ @controller_path = @controller.class.name.underscore
23
+ end
24
+
27
25
  def controller_filename
28
- return @controller_filename if defined?(@controller_filename)
29
- controller_name=@controller.class.to_s.underscore
30
- controller_name='application' if controller_name=='application_controller'
31
- if ActionController::Routing.respond_to? :controller_paths
32
- @controller_filename=nil
33
- ActionController::Routing.controller_paths.each do |controller_path|
34
- full_controller_path = File.join(File.expand_path(controller_path), "#{controller_name}.rb")
35
- @controller_filename=full_controller_path if File.exists?(full_controller_path)
36
- end
37
- #raise "File not found"
38
- else
39
- @controller_filename=File.join(File.expand_path(Rails.root), 'app', 'controllers', "#{controller_name}.rb").sub('/controllers/controllers/', '/controllers/')
40
- end
41
- @controller_filename
26
+ @controller_filename ||= Gem.find_files(self.controller_path).first # tnx https://github.com/MasterLambaster
42
27
  end
43
28
 
44
29
  def controller_text
45
- if controller_filename
46
- @controller_text ||= IO.read(controller_filename)
47
- end
30
+ @controller_text ||= IO.read(controller_filename)
48
31
  end
49
32
 
50
33
  def action_index
51
- (controller_text =~ /def\s+#{@controller.action_name}[\s\(]/) if controller_text
34
+ (controller_text =~ /def\s+#{@controller.action_name}[\s\(]/)
52
35
  end
53
36
 
54
37
  def controller_line_number
55
- lines_from_index(controller_text, action_index) || 0 if controller_text
38
+ lines_from_index(controller_text, action_index) || 0
56
39
  end
57
40
 
58
41
  def lines_from_index(string, index)
@@ -69,4 +52,4 @@ module Footnotes
69
52
  end
70
53
  end
71
54
  end
72
- end
55
+ end
@@ -1,10 +1,8 @@
1
- require "#{File.dirname(__FILE__)}/abstract_note"
2
-
3
1
  module Footnotes
4
2
  module Notes
5
3
  class CookiesNote < AbstractNote
6
4
  def initialize(controller)
7
- @cookies = (controller.__send__(:cookies) || {}).symbolize_keys
5
+ @cookies = (controller.__send__(:cookies) || {}).dup.symbolize_keys
8
6
  end
9
7
 
10
8
  def title
@@ -1,5 +1,3 @@
1
- require "#{File.dirname(__FILE__)}/abstract_note"
2
-
3
1
  module Footnotes
4
2
  module Notes
5
3
  class EnvNote < AbstractNote
@@ -1,5 +1,3 @@
1
- require "#{File.dirname(__FILE__)}/abstract_note"
2
-
3
1
  module Footnotes
4
2
  module Notes
5
3
  class FilesNote < AbstractNote
@@ -41,4 +39,4 @@ module Footnotes
41
39
  end
42
40
  end
43
41
  end
44
- end
42
+ end
@@ -1,5 +1,3 @@
1
- require "#{File.dirname(__FILE__)}/abstract_note"
2
-
3
1
  module Footnotes
4
2
  module Notes
5
3
  class FiltersNote < AbstractNote
@@ -35,12 +33,12 @@ module Footnotes
35
33
  mock_controller.action_name = action
36
34
 
37
35
  #remove conditions (this would call a Proc on the mock_controller)
38
- filter.options.merge!(:if => nil, :unless => nil)
36
+ filter.options.merge!(:if => nil, :unless => nil)
39
37
 
40
- filter.__send__(:should_run_callback?, mock_controller)
38
+ filter.__send__(:should_run_callback?, mock_controller)
41
39
  }.map(&:to_sym)
42
40
  end
43
-
41
+
44
42
  def parse_method(method = '')
45
43
  escape(method.inspect.gsub(RAILS_ROOT, ''))
46
44
  end
@@ -50,4 +48,4 @@ module Footnotes
50
48
  module Extensions
51
49
  class MockController < Struct.new(:action_name); end
52
50
  end
53
- end
51
+ end
@@ -1,5 +1,3 @@
1
- require "#{File.dirname(__FILE__)}/abstract_note"
2
-
3
1
  module Footnotes
4
2
  module Notes
5
3
  class GeneralNote < AbstractNote
@@ -16,4 +14,4 @@ module Footnotes
16
14
  end
17
15
  end
18
16
  end
19
- end
17
+ end
@@ -1,5 +1,3 @@
1
- require "#{File.dirname(__FILE__)}/files_note"
2
-
3
1
  module Footnotes
4
2
  module Notes
5
3
  class JavascriptsNote < FilesNote
@@ -13,4 +11,4 @@ module Footnotes
13
11
  end
14
12
  end
15
13
  end
16
- end
14
+ end
@@ -1,5 +1,3 @@
1
- require "#{File.dirname(__FILE__)}/abstract_note"
2
-
3
1
  module Footnotes
4
2
  module Notes
5
3
  class LayoutNote < AbstractNote
@@ -1,14 +1,12 @@
1
- require "#{File.dirname(__FILE__)}/abstract_note"
2
-
3
1
  module Footnotes
4
2
  module Notes
5
3
  class LogNote < AbstractNote
6
4
  @@log = []
7
-
5
+
8
6
  def self.log(message)
9
7
  @@log << message
10
8
  end
11
-
9
+
12
10
  def initialize(controller)
13
11
  @controller = controller
14
12
  end
@@ -20,7 +18,7 @@ module Footnotes
20
18
  def content
21
19
  escape(log.gsub(/\e\[.+?m/, '')).gsub("\n", '<br />')
22
20
  end
23
-
21
+
24
22
  def log
25
23
  unless @log
26
24
  @log = @@log.join('')
@@ -39,7 +37,7 @@ module Footnotes
39
37
  logged_message
40
38
  end
41
39
  end
42
-
40
+
43
41
  Rails.logger.extend LoggingExtensions
44
42
  end
45
43
  end
@@ -1,5 +1,3 @@
1
- require "#{File.dirname(__FILE__)}/abstract_note"
2
-
3
1
  module Footnotes
4
2
  module Notes
5
3
  class ParamsNote < AbstractNote
@@ -1,5 +1,3 @@
1
- require "#{File.dirname(__FILE__)}/log_note"
2
-
3
1
  module Footnotes
4
2
  module Notes
5
3
  class PartialsNote < LogNote
@@ -1,5 +1,3 @@
1
- require "#{File.dirname(__FILE__)}/abstract_note"
2
-
3
1
  module Footnotes
4
2
  module Notes
5
3
  class QueriesNote < AbstractNote
@@ -1,5 +1,3 @@
1
- require "#{File.dirname(__FILE__)}/abstract_note"
2
-
3
1
  module Footnotes
4
2
  module Notes
5
3
  class RoutesNote < AbstractNote
@@ -48,7 +46,7 @@ module Footnotes
48
46
  #
49
47
  def filtered_routes(filter = {})
50
48
  return [] unless filter.is_a?(Hash)
51
- return routes.reject do |r|
49
+ return routes.reject do |r|
52
50
  filter_diff = filter.diff(r.requirements)
53
51
  route_diff = r.requirements.diff(filter)
54
52
  (filter_diff == filter) || (filter_diff != route_diff)
@@ -1,5 +1,3 @@
1
- require "#{File.dirname(__FILE__)}/abstract_note"
2
-
3
1
  module Footnotes
4
2
  module Notes
5
3
  class SessionNote < AbstractNote
@@ -1,5 +1,3 @@
1
- require "#{File.dirname(__FILE__)}/files_note"
2
-
3
1
  module Footnotes
4
2
  module Notes
5
3
  class StylesheetsNote < FilesNote
@@ -13,4 +11,4 @@ module Footnotes
13
11
  end
14
12
  end
15
13
  end
16
- end
14
+ end