Module: EnjuBookJacket::BookJacketHelper

Defined in:
lib/enju_book_jacket/book_jacket_helper.rb

Instance Method Summary collapse

Instance Method Details



57
58
59
60
# File 'lib/enju_book_jacket/book_jacket_helper.rb', line 57

def amazon_link(asin, hostname = configatron.amazon.hostname)
  return nil if asin.blank?
  "http://#{hostname}/dp/#{asin}"
end

#book_jacket(manifestation) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/enju_book_jacket/book_jacket_helper.rb', line 3

def book_jacket(manifestation)
  if manifestation.picture_files.exists?
    link = ''
    manifestation.picture_files.each_with_index do |picture_file, i|
      if i == 0
        link += link_to(show_image(picture_file, :size => :thumb), picture_file_path(picture_file, :format => :download), :rel => "manifestation_#{manifestation.id}")
      else
        link +=  :span, :style => "display: none" do
          link_to(show_image(picture_file, :size => :thumb), picture_file_path(picture_file, :format => :download), :rel => "manifestation_#{manifestation.id}")
        end
      end
    end
    return link.html_safe
  else
    link = book_jacket_tag(manifestation)
    unless link
      link = screenshot_tag(manifestation)
    end
  end

  unless link
    link = link_to image_tag('unknown_resource.png', :width => '100', :height => '100', :alt => '*', :itemprop => 'image'), manifestation
  end
  link
end


62
63
64
65
66
67
68
69
# File 'lib/enju_book_jacket/book_jacket_helper.rb', line 62

def book_jacket_source_link
  case configatron.book_jacket.source
  when :google
    link_to "Google Books", "http://books.google.com/"
  when :amazon
    link_to "Amazon Web Services", "http://aws.amazon.com/"
  end
end

#book_jacket_tag(manifestation, generator = configatron.book_jacket.source) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/enju_book_jacket/book_jacket_helper.rb', line 43

def book_jacket_tag(manifestation, generator = configatron.book_jacket.source)
  return nil unless manifestation
  case generator
  when :amazon
    return nil unless configatron.amazon.hostname
    book_jacket = manifestation.amazon_book_jacket
    if book_jacket
      link_to image_tag(book_jacket[:url], :width => book_jacket[:width], :height => book_jacket[:height], :alt => manifestation.original_title, :class => 'book_jacket', :itemprop => 'image'), "http://#{configatron.amazon.hostname}/dp/#{book_jacket[:asin]}"
    end
  when :google
    render :partial => 'manifestations/google_book_thumbnail', :locals => {:manifestation => manifestation}
  end
end


71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/enju_book_jacket/book_jacket_helper.rb', line 71

def screenshot_generator_link
  case configatron.screenshot.generator
  when :mozshot
    link_to "MozShot", "http://mozshot.nemui.org/"
  when :simpleapi
    link_to "SimpleAPI", "http://img.simpleapi.net/"
  when :heartrails
    link_to "HeartRails Capture", "http://capture.heartrails.com/"
  when :thumbalizr
    link_to "thumbalizr", "http://www.thumbalizr.com/"
  end
end

#screenshot_tag(manifestation, generator = configatron.screenshot.generator) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/enju_book_jacket/book_jacket_helper.rb', line 29

def screenshot_tag(manifestation, generator = configatron.screenshot.generator)
  return nil unless manifestation.try(:access_address)
  case generator
  when :mozshot
    link_to image_tag("http://mozshot.nemui.org/shot?#{manifestation.access_address}", :width => 128, :height => 128, :alt => manifestation.original_title, :border => 0, :itemprop => 'image'), manifestation.access_address
  when :simpleapi
    link_to image_tag("http://img.simpleapi.net/small/#{manifestation.access_address}", :width => 128, :height => 128, :alt => manifestation.original_title, :border => 0, :itemprop => 'image'), manifestation.access_address
  when :heartrails
    link_to image_tag("http://capture.heartrails.com/medium?#{manifestation.access_address}", :width => 120, :height => 90, :alt => manifestation.original_title, :border => 0, :itemprop => 'image'), manifestation.access_address
  when :thumbalizr
    link_to image_tag("http://api.thumbalizr.com/?url=#{manifestation.access_address}&width=128", :width => 128, :height => 144, :alt => manifestation.original_title, :border => 0, :itemprop => 'image'), manifestation.access_address
  end
end