polyblock 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/helpers/polyblock/application_helper.rb +21 -7
- data/lib/polyblock/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e15bd6a1718d05d6cef2e91692323079359a61a
|
4
|
+
data.tar.gz: a2dac4b8736b97ace57edd442ac633e3d169cd93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9f1d977fc6f9dda1df215a27acc540e80e5669610b0d3ca7533b641a215750c7c7e29838bf8f27baa5806f6f5e243b10848d8b78598f1b043ad722f44887272
|
7
|
+
data.tar.gz: 561a7e70973088d85c3ebbfc1ad24ba3b5507fb154dbeaeb9bc3a856b9893f2589b70ec3a4b0dff654fb44deeca5a09aa05a8599ac33d778cfa7497fcbdcff1c
|
@@ -1,7 +1,15 @@
|
|
1
1
|
module Polyblock
|
2
2
|
module ApplicationHelper
|
3
3
|
|
4
|
-
def pb(name,
|
4
|
+
def pb(name, options={})
|
5
|
+
options = {
|
6
|
+
:tag => :div,
|
7
|
+
:tag_options => {},
|
8
|
+
:condensed => false,
|
9
|
+
:length => 250,
|
10
|
+
:omission => '... (continued)'
|
11
|
+
}.merge(options)
|
12
|
+
|
5
13
|
# Fetch or create Polyblock
|
6
14
|
if name.is_a? Polyblock::Block
|
7
15
|
pb = name
|
@@ -11,18 +19,24 @@ module Polyblock
|
|
11
19
|
else
|
12
20
|
matches = Polyblock::Block.where :name => name
|
13
21
|
pb_exists = matches.any?
|
14
|
-
pb =
|
15
|
-
pb_id =
|
22
|
+
pb = pb_exists ? matches.first : Polyblock::Block.new({:name => name})
|
23
|
+
pb_id = pb_exists ? pb.id : Polyblock::Block.count + 1
|
16
24
|
end
|
17
25
|
|
18
26
|
# Build output tag
|
19
|
-
|
20
|
-
tag_options = tag_options.deep_merge({:id => "pb-#{pb_id}", :data => {:pbid => pb_id}})
|
21
|
-
tag_options[:contenteditable] =
|
27
|
+
content = pb_exists ? pb.content : "<p>This block is content managed by Polyblock!<br />Edit \"#{name}\" to add content here.</p>"
|
28
|
+
tag_options = options[:tag_options].deep_merge({:id => "pb-#{pb_id}", :data => {:pbid => pb_id}})
|
29
|
+
tag_options[:contenteditable] = (!respond_to?(:can?) || can?(:manage, pb)) ? "true" : "false"
|
22
30
|
tag_options[:class] = (tag_options.has_key?(:class) ? "#{tag_options[:class]} ":"") + "polyblock"
|
23
31
|
tag_options[:data][:pb_exists] = pb_exists
|
24
32
|
|
25
|
-
|
33
|
+
# Truncation
|
34
|
+
if options[:condensed]
|
35
|
+
content = CGI.unescapeHTML(content.gsub("<br><br>", "<br>").gsub(' ', ' '))
|
36
|
+
content = truncate(sanitize(strip_tags(content)), :length => options[:length], :omission => options[:omission]).html_safe
|
37
|
+
end
|
38
|
+
|
39
|
+
content_tag(options[:tag], content, tag_options, false)
|
26
40
|
end
|
27
41
|
|
28
42
|
def simple_fields_for_polyblock(name, f)
|
data/lib/polyblock/version.rb
CHANGED