polyblock 0.6.3 → 0.6.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f4a75a7d76cfc5bc2b0419088d4c25ec536998a3
4
- data.tar.gz: 072aa1504a72695350bda2f2f22b61e521c3b51d
3
+ metadata.gz: 868e38e6cfee376a22485c431c90b8aa9b9c037b
4
+ data.tar.gz: 00a556ff876444b8f81d481d21600f52d2962823
5
5
  SHA512:
6
- metadata.gz: 4a82bb323b736d6a825ead87c24dccdd23c978db6645ff59ed422c9fa6c190e64d06e2bd4f5e8a7de8abfb7e72812a48f104389e3f77cb758869d153f14bc8c6
7
- data.tar.gz: 11c937ea4f582e894f1106f71c0541c30fa855d9e69d55efe3121e758d487d1cd599999944b39b21d6214349316dd6f7021c79230e4a7cdf24b0fe0a3689d91f
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('&nbsp;', ' '))
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
@@ -5,7 +5,7 @@ module Polyblock
5
5
  isolate_namespace Polyblock
6
6
  initializer 'polyblock_engine.action_controller' do |app|
7
7
  ActiveSupport.on_load :action_controller do
8
- helper Polyblock::PolyblocksHelper
8
+ # helper Polyblock::PolyblocksHelper
9
9
  end
10
10
  end
11
11
  end
@@ -0,0 +1,8 @@
1
+ require 'polyblock/view_helpers'
2
+ module Polyblock
3
+ class Railtie < Rails::Railtie
4
+ initializer "polyblock.view_helpers" do
5
+ ActionView::Base.send :include, ViewHelpers
6
+ end
7
+ end
8
+ end
@@ -1,3 +1,3 @@
1
1
  module Polyblock
2
- VERSION = "0.6.3"
2
+ VERSION = "0.6.4"
3
3
  end
@@ -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('&nbsp;', ' '))
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
@@ -1,5 +1,6 @@
1
1
  require "polyblock/engine"
2
2
  require "polyblock/has_polyblock"
3
+ require "polyblock/railtie" if defined? Rails
3
4
 
4
5
  module Polyblock
5
6
  end
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.3
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