Permalink
Browse files

[^] Assets paths for rails version > 3.1 has been fixed

  • Loading branch information...
1 parent a7239f8 commit 1b61d0ddb25a5d01e651fdc8b0ae2feda48e7ae5 @romanvbabenko romanvbabenko committed Mar 25, 2012
Showing with 37 additions and 11 deletions.
  1. +25 −7 lib/rails-footnotes/notes/files_note.rb
  2. +10 −4 spec/notes/files_note_spec.rb
  3. +2 −0 spec/spec_helper.rb
@@ -14,7 +14,7 @@ def content
if @files.empty?
""
else
- "<ul><li>#{@files.join("</li><li>")}</li></ul>"
+ "<ul><li>%s</li></ul>" % @files.join("</li><li>")
end
end
@@ -28,12 +28,30 @@ def scan_text(text)
end
def parse_files!
- @files.collect! do |filename|
- if filename =~ %r{^/}
- full_filename = File.join(File.expand_path(Rails.root), 'public', filename)
- %[<a href="#{Footnotes::Filter.prefix(full_filename, 1, 1)}">#{filename}</a>]
- else
- %[<a href="#{filename}">#{filename}</a>]
+ if Rails.version >= '3.1' && Rails.application.config.assets[:enabled]
+ asset_paths = Rails.application.config.assets.paths
+ linked_files = []
+
+ @files.collect do |file|
+ base_name = File.basename(file)
+ asset_paths.each do |asset_path|
+ results = Dir[File.expand_path(base_name, asset_path) + '*']
+ results.each do |r|
+ linked_files << %[<a href="#{Footnotes::Filter.prefix(r, 1, 1)}">#{File.basename(r)}</a>]
+ end
+ break if results.present?
+ end
+ end
+ @files = linked_files
+ else
+ #Original Implementation
+ @files.collect! do |filename|
+ if filename =~ %r{^/}
+ full_filename = File.join(File.expand_path(Rails.root), 'public', filename)
+ %[<a href="#{Footnotes::Filter.prefix(full_filename, 1, 1)}">#{filename}</a>]
+ else
+ %[<a href="#{filename}">#{filename}</a>]
+ end
end
end
end
@@ -3,9 +3,15 @@
require "rails-footnotes/notes/files_note"
describe Footnotes::Notes::FilesNote do
- let(:note) {Footnotes::Notes::FilesNote.new(mock('controller', :response => mock('', :body => '')))}
- subject {note}
- it {should be_valid}
- its(:row) {should eql :edit}
+ let(:note) do
+ Rails.stub(:version).and_return('3.0.12');
+ Footnotes::Notes::FilesNote.new(mock('controller', :response => mock('', :body => '')))
+ end
+
+ subject { note }
+
+ it { should be_valid }
+ its(:row) { should eql :edit }
+
end
View
@@ -16,6 +16,8 @@
class Rails
def self.logger; end
+
+ def self.version; '3.0.12'; end
end
RSpec.configure do |config|

0 comments on commit 1b61d0d

Please sign in to comment.