software_tab_data_block.rb
940 Bytes
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
class SoftwareTabDataBlock < Block
attr_accessible :show_name, :displayed_blog
settings_items :show_name, :type => :boolean, :default => false
settings_items :displayed_blog, :type => :integer, :default => 0
TOTAL_POSTS_DYSPLAYED = 5
def self.description
_('Software Tab Data')
end
def help
_('This block is used by colab to insert data into Noosfero')
end
def content(args={})
block = self
lambda do |object|
render(
:file => 'blocks/software_tab_data',
:locals => {
:block => block
}
)
end
end
def blogs
self.owner.blogs
end
def actual_blog
# As :displayed_blog default value is 0, it falls to the first one
blogs.find_by_id(self.displayed_blog) || blogs.first
end
def posts
blog = actual_blog
if blog and (not blog.posts.empty?)
blog.posts.limit(TOTAL_POSTS_DYSPLAYED)
else
[]
end
end
end