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
|
# File 'app/helpers/polyblock/application_helper.rb', line 4
def pb(name, options={})
options = {
:tag => :div,
:tag_options => {},
:condensed => false,
:length => 250,
:omission => '... (continued)'
}.merge(options)
if name.is_a? Polyblock::Block
pb = name
pb_id = pb.id
name = pb.name
pb_exists = true
else
matches = Polyblock::Block.where :name => name
pb_exists = matches.any?
pb = pb_exists ? matches.first : Polyblock::Block.new({:name => name})
pb_id = if pb_exists
pb.id
else
nextId = Polyblock::Block.count + 1
nextId += 1 while Polyblock::Block.where(:id => nextId).any?
end
end
content = pb_exists ? pb.content : "<p>This block is content managed by Polyblock!<br />Click to edit me!</p>"
tag_options = options[:tag_options].deep_merge({:id => "pb-#{pb_id}", :data => {:pbid => pb_id, :pbname => name}})
tag_options[:contenteditable] = (!respond_to?(:can?) || can?(:manage, pb)) ? "true" : "false"
tag_options[:class] = (tag_options.has_key?(:class) ? "#{tag_options[:class]} ":"") + "polyblock"
tag_options[:data][:pb_exists] = pb_exists
if options[:condensed]
content = CGI.unescapeHTML(content.gsub("<br><br>", "<br>").gsub(' ', ' '))
content = truncate(sanitize(strip_tags(content)), :length => options[:length], :omission => options[:omission]).html_safe
end
content_tag(options[:tag], content, tag_options, false)
end
|