Class: View::FileLink

Inherits:
Formatter show all
Defined in:
lib/view/formatters/file_link.rb

Overview

Handy for paperclip attachment objects, this formatter will find out what the url is and make a link to that.

Controll the link with the :text or :text_method option.

By default, all links have the target _blank, so they won't screw up your site. Turn it off globally by putting:

View::FileLink.default_options = {}

Examples:


<%= view @user.avatar %>
<%= view @user.avatar, :text => "Click for the avatar" %>
<%= view @user.avatar, :text_method => :original_file_name %>

Instance Attribute Summary

Attributes inherited from Formatter

#block, #template, #value

Instance Method Summary (collapse)

Methods inherited from Formatter

#all_options, as, #format!, inherited, #options, skip_blank_formatter, #to_s, type

Instance Method Details

- (Object) format



23
24
25
# File 'lib/view/formatters/file_link.rb', line 23

def format
  template.link_to(text, path, options)
end

- (Object) formatted_text



38
39
40
# File 'lib/view/formatters/file_link.rb', line 38

def formatted_text
  View.format((text_via_method || value), {:as => :guess}, template, &block)
end

- (Object) path



27
28
29
30
31
32
# File 'lib/view/formatters/file_link.rb', line 27

def path
  View.configuration.path_methods.each do |method|
    return value.send(method) if value.respond_to?(method)
  end
  nil
end

- (Object) text



34
35
36
# File 'lib/view/formatters/file_link.rb', line 34

def text
  all_options[:text] || formatted_text
end

- (Object) text_method



46
47
48
# File 'lib/view/formatters/file_link.rb', line 46

def text_method
  all_options[:text_method]
end

- (Object) text_via_method



42
43
44
# File 'lib/view/formatters/file_link.rb', line 42

def text_via_method
  value.send(text_method) if text_method
end