polyblock 0.6.3 → 0.6.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/polyblocks_helper.rb +0 -74
- data/lib/polyblock/engine.rb +1 -1
- data/lib/polyblock/railtie.rb +8 -0
- data/lib/polyblock/version.rb +1 -1
- data/lib/polyblock/view_helpers.rb +78 -0
- data/lib/polyblock.rb +1 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 868e38e6cfee376a22485c431c90b8aa9b9c037b
|
4
|
+
data.tar.gz: 00a556ff876444b8f81d481d21600f52d2962823
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c2fe51100db5fae92146a08c153c5522aa8d548e48a4aa6a678b55d6396d57eb3fdaf11fcb6e54e8971487f52cd61e0268fb74ea36cd94b15449e7456072775
|
7
|
+
data.tar.gz: b87ae2228f775e9d3ac96ffae940db06ef6bd765b41cfc43ed7f304378e5ae04f7768495bb16bacfd09eb90c705a7d6ab66dac4f52c95be2f537c65f95760a47
|
@@ -1,78 +1,4 @@
|
|
1
1
|
module Polyblock
|
2
2
|
module PolyblocksHelper
|
3
|
-
|
4
|
-
def pb(name, options={})
|
5
|
-
options = {
|
6
|
-
# :editable => false,
|
7
|
-
:tag => :div,
|
8
|
-
:tag_options => {},
|
9
|
-
:condensed => false,
|
10
|
-
:length => 250,
|
11
|
-
:omission => '... (continued)'
|
12
|
-
}.merge(options)
|
13
|
-
|
14
|
-
# Fetch or create Polyblock
|
15
|
-
pb = Block.fetch_or_create(name)
|
16
|
-
pb_id = pb.new_record? ? Block.next_id : pb.id
|
17
|
-
name = pb.name if name.is_a? Block
|
18
|
-
random_id = Block.random_id
|
19
|
-
|
20
|
-
# Build output tag
|
21
|
-
content = pb.content.present? ? pb.content : "[Editable content space for Polyblock <code>#{name}</code>]"
|
22
|
-
tag_options = options[:tag_options].deep_merge({:id => "pb-#{pb_id}-#{random_id}", :data => {:pbid => pb_id, :pbname => name}})
|
23
|
-
tag_options[:contenteditable] = if options[:condensed]
|
24
|
-
'false'
|
25
|
-
elsif options.has_key?(:editable)
|
26
|
-
options[:editable] ? 'true' : 'false'
|
27
|
-
elsif respond_to?(:can?) && can?(:manage, pb)
|
28
|
-
'true'
|
29
|
-
elsif respond_to?(:user_signed_in?) && user_signed_in?
|
30
|
-
if current_user.respond_to?(:admin?) && current_user.admin?
|
31
|
-
'true'
|
32
|
-
elsif pb.contentable.present? &&
|
33
|
-
pb.contentable.respond_to?(:user_id) &&
|
34
|
-
pb.contentable.user_id == current_user.id
|
35
|
-
'true'
|
36
|
-
else
|
37
|
-
'false'
|
38
|
-
end
|
39
|
-
else
|
40
|
-
'false'
|
41
|
-
end
|
42
|
-
tag_options.delete(:contenteditable) if tag_options[:contenteditable] == 'false'
|
43
|
-
tag_options[:class] = (tag_options.key?(:class) ? "#{tag_options[:class]} ": '') + 'polyblock'
|
44
|
-
tag_options[:data][:pb_exists] = pb.new_record?
|
45
|
-
|
46
|
-
# Truncation
|
47
|
-
if options[:condensed]
|
48
|
-
tag_options[:class] += " polyblock-condensed"
|
49
|
-
content = CGI.unescapeHTML(content.gsub('<br><br>', '<br>').gsub(' ', ' '))
|
50
|
-
truncate(sanitize(strip_tags(content)), :length => options[:length], :omission => options[:omission])
|
51
|
-
else
|
52
|
-
content_tag(options[:tag], content, tag_options, false)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def simple_fields_for_polyblock(name, f, options={})
|
57
|
-
options = {
|
58
|
-
:label => false,
|
59
|
-
:input_html => {}
|
60
|
-
}.merge(options)
|
61
|
-
|
62
|
-
pb = if name.is_a?(String)
|
63
|
-
Block.fetch_or_initialize(name)
|
64
|
-
elsif name.is_a?(Symbol)
|
65
|
-
f.object
|
66
|
-
else
|
67
|
-
nil
|
68
|
-
end
|
69
|
-
|
70
|
-
render :partial => 'polyblock/simple_fields_for', :locals => {:f => f, :pb => pb, :name => name, :options => options}
|
71
|
-
end
|
72
|
-
|
73
|
-
def polyblock_editor_bar
|
74
|
-
render :partial => 'polyblock/editor_bar'
|
75
|
-
end
|
76
|
-
|
77
3
|
end
|
78
4
|
end
|
data/lib/polyblock/engine.rb
CHANGED
data/lib/polyblock/version.rb
CHANGED
@@ -0,0 +1,78 @@
|
|
1
|
+
module Polyblock
|
2
|
+
module ViewHelpers
|
3
|
+
|
4
|
+
def pb(name, options={})
|
5
|
+
options = {
|
6
|
+
# :editable => false,
|
7
|
+
:tag => :div,
|
8
|
+
:tag_options => {},
|
9
|
+
:condensed => false,
|
10
|
+
:length => 250,
|
11
|
+
:omission => '... (continued)'
|
12
|
+
}.merge(options)
|
13
|
+
|
14
|
+
# Fetch or create Polyblock
|
15
|
+
pb = Block.fetch_or_create(name)
|
16
|
+
pb_id = pb.new_record? ? Block.next_id : pb.id
|
17
|
+
name = pb.name if name.is_a? Block
|
18
|
+
random_id = Block.random_id
|
19
|
+
|
20
|
+
# Build output tag
|
21
|
+
content = pb.content.present? ? pb.content : "[Editable content space for Polyblock <code>#{name}</code>]"
|
22
|
+
tag_options = options[:tag_options].deep_merge({:id => "pb-#{pb_id}-#{random_id}", :data => {:pbid => pb_id, :pbname => name}})
|
23
|
+
tag_options[:contenteditable] = if options[:condensed]
|
24
|
+
'false'
|
25
|
+
elsif options.has_key?(:editable)
|
26
|
+
options[:editable] ? 'true' : 'false'
|
27
|
+
elsif respond_to?(:can?) && can?(:manage, pb)
|
28
|
+
'true'
|
29
|
+
elsif respond_to?(:user_signed_in?) && user_signed_in?
|
30
|
+
if current_user.respond_to?(:admin?) && current_user.admin?
|
31
|
+
'true'
|
32
|
+
elsif pb.contentable.present? &&
|
33
|
+
pb.contentable.respond_to?(:user_id) &&
|
34
|
+
pb.contentable.user_id == current_user.id
|
35
|
+
'true'
|
36
|
+
else
|
37
|
+
'false'
|
38
|
+
end
|
39
|
+
else
|
40
|
+
'false'
|
41
|
+
end
|
42
|
+
tag_options.delete(:contenteditable) if tag_options[:contenteditable] == 'false'
|
43
|
+
tag_options[:class] = (tag_options.key?(:class) ? "#{tag_options[:class]} ": '') + 'polyblock'
|
44
|
+
tag_options[:data][:pb_exists] = pb.new_record?
|
45
|
+
|
46
|
+
# Truncation
|
47
|
+
if options[:condensed]
|
48
|
+
tag_options[:class] += " polyblock-condensed"
|
49
|
+
content = CGI.unescapeHTML(content.gsub('<br><br>', '<br>').gsub(' ', ' '))
|
50
|
+
truncate(sanitize(strip_tags(content)), :length => options[:length], :omission => options[:omission])
|
51
|
+
else
|
52
|
+
content_tag(options[:tag], content, tag_options, false)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def simple_fields_for_polyblock(name, f, options={})
|
57
|
+
options = {
|
58
|
+
:label => false,
|
59
|
+
:input_html => {}
|
60
|
+
}.merge(options)
|
61
|
+
|
62
|
+
pb = if name.is_a?(String)
|
63
|
+
Block.fetch_or_initialize(name)
|
64
|
+
elsif name.is_a?(Symbol)
|
65
|
+
f.object
|
66
|
+
else
|
67
|
+
nil
|
68
|
+
end
|
69
|
+
|
70
|
+
render :partial => 'polyblock/simple_fields_for', :locals => {:f => f, :pb => pb, :name => name, :options => options}
|
71
|
+
end
|
72
|
+
|
73
|
+
def polyblock_editor_bar
|
74
|
+
render :partial => 'polyblock/editor_bar'
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
data/lib/polyblock.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: polyblock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- MacKinley Smith
|
@@ -202,7 +202,9 @@ files:
|
|
202
202
|
- lib/polyblock.rb
|
203
203
|
- lib/polyblock/engine.rb
|
204
204
|
- lib/polyblock/has_polyblock.rb
|
205
|
+
- lib/polyblock/railtie.rb
|
205
206
|
- lib/polyblock/version.rb
|
207
|
+
- lib/polyblock/view_helpers.rb
|
206
208
|
- lib/tasks/ckeditor.rake
|
207
209
|
- lib/tasks/polyblock_tasks.rake
|
208
210
|
- test/controllers/polyblock/polyblocks_controller_test.rb
|