Sha256: fb34ded7c54c8dab269de8b138718bb9def2e9b2ed76196f0b537b658fbe7ff7

Contents?: true

Size: 1.6 KB

Versions: 13

Compression:

Stored size: 1.6 KB

Contents

module Footnotes
  module Notes
    class FilesNote < AbstractNote
      def initialize(controller)
        @files = scan_text(controller.response.body)
        parse_files!
      end

      def row
        :edit
      end

      def content
        if @files.empty?
          ""
        else
          "<ul><li>%s</li></ul>" % @files.join("</li><li>")
        end
      end

      def valid?
        prefix?
      end

      protected
        def scan_text(text)
          []
        end

        def parse_files!
          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
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
rails-footnotes-4.1.5 lib/rails-footnotes/notes/files_note.rb
rails-footnotes-4.1.4 lib/rails-footnotes/notes/files_note.rb
rails-footnotes-4.1.3 lib/rails-footnotes/notes/files_note.rb
rails-footnotes-4.1.2 lib/rails-footnotes/notes/files_note.rb
rails-footnotes-4.1.1 lib/rails-footnotes/notes/files_note.rb
rails-footnotes-4.1.0 lib/rails-footnotes/notes/files_note.rb
rails-footnotes-4.0.2 lib/rails-footnotes/notes/files_note.rb
rails-footnotes-4.0.1 lib/rails-footnotes/notes/files_note.rb
rails-footnotes-4.0.0 lib/rails-footnotes/notes/files_note.rb
rails-footnotes-3.7.9 lib/rails-footnotes/notes/files_note.rb
rails-footnotes-3.7.8 lib/rails-footnotes/notes/files_note.rb
rails-footnotes-3.7.7 lib/rails-footnotes/notes/files_note.rb
rails-footnotes-3.7.6 lib/rails-footnotes/notes/files_note.rb