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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9b896b2db331f79aec0f8f740c19cb8f80bbc2da
4
- data.tar.gz: 6c3a7c607fdb10424957605bd756a13b385f3b04
3
+ metadata.gz: 3e15bd6a1718d05d6cef2e91692323079359a61a
4
+ data.tar.gz: a2dac4b8736b97ace57edd442ac633e3d169cd93
5
5
  SHA512:
6
- metadata.gz: 5ff400fcc4336d56e4254982f52ab08ac79068d0d4fbe0424d6f32656f1e2b802dcd59f72f407e450551faf730f2c2c20d5f79fa5c94918d9b0a561df507581b
7
- data.tar.gz: d535a91e242c24b98f6bceff990a4343f94b84291b99f6c1eb677043404113a20ad2efb363868bb459f1a23ade0e8f46faab790379d7a5498e25d009ce583796
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, tag = :div, tag_options={})
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 = if pb_exists then matches.first() else Polyblock::Block.new({:name => name}) end
15
- pb_id = if pb_exists then pb.id else Polyblock::Block.count + 1 end
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
- pb.content ||= pb.present? ? pb.content : "<p>This block is content managed by Polyblock!<br />Edit \"#{name}\" to add content here.</p>"
20
- tag_options = tag_options.deep_merge({:id => "pb-#{pb_id}", :data => {:pbid => pb_id}})
21
- tag_options[:contenteditable] = if !respond_to?(:can?) or can?(:manage, pb) then "true" else "false" end
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
- content_tag(tag, pb.content, tag_options, false)
33
+ # Truncation
34
+ if options[:condensed]
35
+ content = CGI.unescapeHTML(content.gsub("<br><br>", "<br>").gsub('&nbsp;', ' '))
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)
@@ -1,3 +1,3 @@
1
1
  module Polyblock
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  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.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - MacKinley Smith