polyblock 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/helpers/polyblock/application_helper.rb +18 -33
- data/app/models/polyblock/block.rb +32 -10
- data/app/views/polyblock/_simple_fields_for.html.haml +1 -0
- data/lib/polyblock/version.rb +1 -1
- data/test/dummy/app/views/home/index.html.haml +2 -2
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/log/development.log +2125 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/1eacdbb3be88857a9387909bc1ae555c +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/d09e190e75f7ec3bc98994e13a005699 +0 -0
- data/test/dummy/tmp/pids/server.pid +1 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80795451e15edd4c4f2d7eb45fc9f023643d2ecc
|
4
|
+
data.tar.gz: 10c97e9da58822ff329b673c9f944ac43dbdd241
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da8686b6bcc954bdabb98776b1076f48274710124ccf6a8d297e05cbdcc449e3d6715b7bd31dd0e082c523a7935676394ff1756c3124cc0671c952f4058a193e
|
7
|
+
data.tar.gz: 37aeb629009db8eed40f3cab52f2ad0b0c7364f60784cf400502ca15db921d2f363fb895cdd23faaf36e9dc536076c8d4eb68aa07fda7bf2707b265101bab693
|
@@ -12,56 +12,41 @@ module Polyblock
|
|
12
12
|
}.merge(options)
|
13
13
|
|
14
14
|
# Fetch or create Polyblock
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
pb_exists = true
|
20
|
-
else
|
21
|
-
matches = Polyblock::Block.where :name => name
|
22
|
-
pb_exists = matches.any?
|
23
|
-
pb = pb_exists ? matches.first : Polyblock::Block.new({:name => name})
|
24
|
-
pb_id = if pb_exists
|
25
|
-
pb.id
|
26
|
-
else
|
27
|
-
Polyblock::Block.any? ? Polyblock::Block.order(:id).last.id + 1 : 1
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
# Generate a random string for id
|
32
|
-
o = [('a'..'z'), ('A'..'Z')].map { |i| i.to_a }.flatten
|
33
|
-
random_id = (0...50).map { o[rand(o.length)] }.join
|
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
|
34
19
|
|
35
20
|
# Build output tag
|
36
|
-
content =
|
21
|
+
content = pb.content.present? ? pb.content : "[Editable content space for Polyblock <code>#{name}</code>]"
|
37
22
|
tag_options = options[:tag_options].deep_merge({:id => "pb-#{pb_id}-#{random_id}", :data => {:pbid => pb_id, :pbname => name}})
|
38
23
|
tag_options[:contenteditable] = if options[:condensed]
|
39
|
-
|
24
|
+
'false'
|
40
25
|
elsif options.has_key?(:editable)
|
41
|
-
options[:editable] ?
|
26
|
+
options[:editable] ? 'true' : 'false'
|
42
27
|
elsif respond_to?(:can?) && can?(:manage, pb)
|
43
|
-
|
28
|
+
'true'
|
44
29
|
elsif respond_to?(:user_signed_in?) && user_signed_in?
|
45
30
|
if current_user.respond_to?(:admin?) && current_user.admin?
|
46
|
-
|
31
|
+
'true'
|
47
32
|
elsif pb.contentable.present? &&
|
48
33
|
pb.contentable.respond_to?(:user_id) &&
|
49
34
|
pb.contentable.user_id == current_user.id
|
50
|
-
|
35
|
+
'true'
|
51
36
|
else
|
52
|
-
|
37
|
+
'false'
|
53
38
|
end
|
54
39
|
else
|
55
|
-
|
40
|
+
'false'
|
56
41
|
end
|
57
|
-
tag_options.delete(:contenteditable) if tag_options[:contenteditable] ==
|
58
|
-
tag_options[:class] = (tag_options.
|
59
|
-
tag_options[:data][:pb_exists] =
|
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?
|
60
45
|
|
61
46
|
# Truncation
|
62
47
|
if options[:condensed]
|
63
48
|
tag_options[:class] += " polyblock-condensed"
|
64
|
-
content = CGI.unescapeHTML(content.gsub(
|
49
|
+
content = CGI.unescapeHTML(content.gsub('<br><br>', '<br>').gsub(' ', ' '))
|
65
50
|
truncate(sanitize(strip_tags(content)), :length => options[:length], :omission => options[:omission])
|
66
51
|
else
|
67
52
|
content_tag(options[:tag], content, tag_options, false)
|
@@ -73,11 +58,11 @@ module Polyblock
|
|
73
58
|
:label => false,
|
74
59
|
:input_html => {}
|
75
60
|
}.merge(options)
|
76
|
-
render :partial =>
|
61
|
+
render :partial => 'polyblock/simple_fields_for', :locals => {:f => f, :name => name, :options => options}
|
77
62
|
end
|
78
63
|
|
79
64
|
def polyblock_editor_bar
|
80
|
-
render :partial =>
|
65
|
+
render :partial => 'polyblock/editor_bar'
|
81
66
|
end
|
82
67
|
|
83
68
|
end
|
@@ -7,19 +7,15 @@ module Polyblock
|
|
7
7
|
|
8
8
|
def self.import(pbs)
|
9
9
|
outputs = pbs.map do |pb|
|
10
|
-
|
11
|
-
if
|
12
|
-
|
13
|
-
m.update_attributes(pb) if m.content != pb[:content]
|
14
|
-
else
|
15
|
-
Block.create(pb)
|
16
|
-
end
|
10
|
+
block = fetch_or_initialize pb[:name]
|
11
|
+
block.content = pb[:content] if pb.key?(:content) && pb[:content].present? && pb[:content] != block.content
|
12
|
+
block.save
|
17
13
|
end
|
18
14
|
outputs.include?(false)
|
19
15
|
end
|
20
16
|
|
21
17
|
def self.export
|
22
|
-
output =
|
18
|
+
output = all.as_json(:except => [:id, :created_at, :updated_at])
|
23
19
|
puts ""
|
24
20
|
puts "Run the following in Rails Console on the remote server:"
|
25
21
|
puts ""
|
@@ -32,11 +28,37 @@ module Polyblock
|
|
32
28
|
end
|
33
29
|
|
34
30
|
def present?
|
35
|
-
content.present?
|
31
|
+
!nil? && content.present?
|
36
32
|
end
|
37
33
|
|
38
34
|
def blank?
|
39
|
-
content.blank?
|
35
|
+
nil? || content.blank?
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.fetch_or_initialize(name)
|
39
|
+
if name.is_a? Block
|
40
|
+
name
|
41
|
+
else
|
42
|
+
matches = where :name => name
|
43
|
+
if matches.any?
|
44
|
+
matches.first
|
45
|
+
else
|
46
|
+
new({:name => name})
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
def self.fetch_or_create(name)
|
51
|
+
pb = fetch_or_initialize(name)
|
52
|
+
pb.save if pb.new_record?
|
53
|
+
pb
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.next_id
|
57
|
+
any? ? maximum(:id).next : 1
|
58
|
+
end
|
59
|
+
def self.random_id
|
60
|
+
o = [('a'..'z'), ('A'..'Z')].map { |i| i.to_a }.flatten
|
61
|
+
(0...50).map { o[rand(o.length)] }.join
|
40
62
|
end
|
41
63
|
|
42
64
|
end
|
data/lib/polyblock/version.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
%h1 Polyblock Test Dummy
|
2
2
|
|
3
3
|
%h3 Polyblock with Inline Editing
|
4
|
-
= pb
|
4
|
+
= pb 'Test', :editable => true
|
5
5
|
|
6
6
|
%h3 New Polyblock
|
7
|
-
= pb
|
7
|
+
= pb Polyblock::Block.random_id, :editable => true
|
8
8
|
|
9
9
|
%h3 Polyblock SimpleForm
|
10
10
|
= simple_form_for @event do |f|
|
Binary file
|