context_content_block.rb
2.22 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
class ContextContentBlock < Block
settings_items :show_name, :type => :boolean, :default => true
settings_items :show_image, :type => :boolean, :default => true
settings_items :show_parent_content, :type => :boolean, :default => true
settings_items :types, :type => Array, :default => ['UploadedFile']
settings_items :limit, :type => :integer, :default => 6
include Noosfero::Plugin::HotSpot
def self.description
_('Display context content')
end
def help
_('This block displays content based on context.')
end
def available_content_types
@available_content_types ||= [TinyMceArticle, TextileArticle, RawHTMLArticle, Event, Folder, Blog, UploadedFile, Forum, Gallery, RssFeed] + plugins.dispatch(:content_types)
end
def types=(new_types)
settings[:types] = new_types.reject(&:blank?)
end
def content_image(content)
block = self
lambda do
if content.image?
image_tag(content.public_filename(:thumb))
else
extra_class = content.kind_of?(UploadedFile) ? "extension-#{content.extension}" : ''
content_tag 'div', '', :class => "context-icon icon-#{content.class.icon_name(content)} #{extra_class}"
end
end
end
def contents(page, p=1)
return @children unless @children.blank?
if page
@children = page.children.with_types(types).paginate(:per_page => limit, :page => p)
(@children.blank? && show_parent_content) ? contents(page.parent) : @children
else
nil
end
end
def footer
block = self
lambda do
if @page
contents = block.contents(@page)
content_tag('div',
render(:partial => 'blocks/more', :locals => {:block => block, :contents => contents, :article_id => @page.id}), :id => "context_content_more_#{block.id}", :class => "more_button")
else
''
end
end
end
def content(args={})
block = self
lambda do
contents = block.contents(@page)
if !contents.blank?
block_title(block.title) + content_tag('div',
render(:file => 'blocks/context_content', :locals => {:block => block, :contents => contents}), :class => 'contents', :id => "context_content_#{block.id}")
else
''
end
end
end
end