cirandas.net

ref: master

plugins/profile_images/lib/profile_images_plugin/profile_images_block.rb


 1
 2
 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
class ProfileImagesPlugin::ProfileImagesBlock < Block
  attr_accessible :limit
  settings_items :limit, type: :integer, default: 6

  def view_title
    self.default_title
  end

  def images
    images = owner.articles.images
    self.limit.nil? ? images : images.first(self.get_limit)
  end

  def extra_option
    { }
  end

  def self.description
    _('Display the images inside the context where the block is available.')
  end

  def help
    _('This block lists the images inside this profile.')
  end

  def default_title
    _('Profile images')
  end

  def api_content(params = {})
    content = []
    images.each do |image|
      content << { title: image.title, view_url: image.view_url, path: image.public_filename(:thumb), id: image.id }
    end
    { images: content }
  end

  def display_api_content_by_default?
    false
  end

  def timeout
    4.hours
  end

  def self.expire_on
    { profile: [:article] }
  end
end