renderable 1.0.9 → 1.0.10

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: 654b7f8de637ab4bf52cf5e45cea64af71d6fcb7
4
- data.tar.gz: 4dcc2f837ea5cb3e8f46631b0c8fb5aac63228c3
3
+ metadata.gz: 02c36fa911ea8d9e74a768e81351b1b6e85a7e1f
4
+ data.tar.gz: a5f68f6ab655158f138fa5270a469e3911274fe7
5
5
  SHA512:
6
- metadata.gz: 5cec40f615e789895c7eda9e3328555f738f4966fea7e82f65f3ff74244d1a8d321978e3b123071b2d56aeee0b0be9cf253ff94478280344686e51edce9dcee0
7
- data.tar.gz: f18119b9008d9ec6a4e85c9c77f661096b079f86de1124e9892b87ca29c18b8f586cd80ce19a0b4dd9f02c7ef27b968dd5784d7f391e3666fdb830e0ad0bc933
6
+ metadata.gz: 39d78df4fe688710e8873e69aa3940b72f16e4d838c6f70841e114500fec89e7f9e84d83cc5423dbfa034a9ddef18fef6a23a2693299587d715b7670b8b704e1
7
+ data.tar.gz: ead7a271fadc2b6e191aa48aadb3049c0f6a932c89d42bc0837dcbabbe30e954cdd1d7bb8efb65540a0ae70c75262ead68c6715e5bda195f5c0b2682d327e7d6
data/Gemfile CHANGED
@@ -4,4 +4,3 @@ source "http://rubygems.org"
4
4
  # Bundler will treat runtime dependencies like base dependencies, and
5
5
  # development dependencies will be added by default to the :development group.
6
6
  gemspec
7
-
data/README.textile CHANGED
@@ -12,8 +12,6 @@ Is fairly simple.
12
12
 
13
13
  <pre>gem "renderable"</pre>
14
14
 
15
- _(you may also need to add RedCloth to your Gemfile… there’s a weird nuance here I’ve not quite understood)_
16
-
17
15
  *2. add appropriate fields to your database*
18
16
 
19
17
  Each renderable property of your model requires two database fields—one to store the original Textile content, and the other to store the rendered HTML. By default, this second field has the same name as the first, only with a ‘_rendered’ suffix.
@@ -72,6 +70,10 @@ Oh, more than likely. And I’d be _very_ surprised if there wasn’t already so
72
70
 
73
71
  h2. Version history
74
72
 
73
+ h3. 1.0.10 (2017-06-20)
74
+
75
+ * Made renderable include RedCloth by itself
76
+
75
77
  h3. 1.0.9 (2017-05-28)
76
78
 
77
79
  * Fixing broken dependency in gemspec
data/lib/renderable.rb CHANGED
@@ -5,10 +5,12 @@ require 'renderable/version'
5
5
 
6
6
  require 'renderable/railtie' if defined?(Rails)
7
7
 
8
+ require 'RedCloth'
9
+
8
10
  module Renderable
9
-
11
+
10
12
  module ClassMethods
11
-
13
+
12
14
  # Add auto-rendering behaviour to an ActiveRecord object. This will automatically set up accessors on both original
13
15
  # and rendered fields, using attr_accessor
14
16
  #
@@ -23,36 +25,36 @@ module Renderable
23
25
  #
24
26
  def acts_as_renderable( options = {} )
25
27
  include InstanceMethods
26
-
28
+
27
29
  # sanity check
28
30
  if options[:fields].blank?
29
31
  return
30
32
  end
31
-
33
+
32
34
  # default options
33
35
  options[:suffix] ||= '_rendered'
34
36
  options[:restrictions] ||= []
35
-
37
+
36
38
  # store the options
37
39
  self.renderable_options = options
38
-
40
+
39
41
  # set accessible on fields
40
42
  options[:fields].each do |field|
41
43
  if ::Rails::VERSION::STRING < '4.0'
42
44
  attr_accessible field, "#{field}#{options[:suffix]}"
43
45
  end
44
-
46
+
45
47
  define_renderable_callbacks :"#{field}_render"
46
48
  end
47
-
49
+
48
50
  # set up callbacks
49
51
  define_renderable_callbacks :render
50
-
52
+
51
53
  # hook
52
54
  before_save :renderable_render
53
-
55
+
54
56
  end
55
-
57
+
56
58
  end
57
-
58
- end
59
+
60
+ end
@@ -2,12 +2,12 @@ require 'renderable/schema'
2
2
 
3
3
  module Renderable
4
4
  module Glue
5
- def self.included base
5
+ def self.included base
6
6
  base.extend ClassMethods
7
7
  base.send :include, Callbacks
8
8
  base.send :include, Schema if defined? ActiveRecord
9
-
9
+
10
10
  base.class_attribute :renderable_options
11
11
  end
12
12
  end
13
- end
13
+ end
@@ -1,42 +1,42 @@
1
1
  module Renderable
2
2
  module InstanceMethods
3
-
3
+
4
4
  private
5
5
  def renderable_render
6
-
6
+
7
7
  suff = renderable_options[:suffix]
8
8
  renderable_options[:fields].each do |field|
9
-
9
+
10
10
  # skip if the field is unchanged
11
11
  next unless self.changed.include? field.to_s
12
12
 
13
13
  # actually render
14
- run_callbacks(:render) do
15
- run_callbacks(:"#{field}_render") do
16
-
17
- # a. call out
18
- content = self[field.to_sym]
14
+ run_callbacks(:render) do
15
+ run_callbacks(:"#{field}_render") do
16
+
17
+ # a. call out
18
+ content = self[field.to_sym]
19
19
  content = content.nil? ? nil : RedCloth.new(content, renderable_options[:restrictions]).to_html
20
-
20
+
21
21
  # b. if we're using RedCloth's lite_mode, let's make the HTML sane again...
22
22
  if renderable_options[:restrictions].include?(:lite_mode)
23
-
23
+
24
24
  # for reasons best known to RedCloth, lite_mode replaces all newlines with a BR tag. This is butt-ugly and
25
25
  # we can do better.
26
26
  #
27
27
  # So, let's find all instances of multiple BRs and replace them with Ps.
28
28
  content = '<p>'+content.gsub( /(<br\s?\/?>\n){2,}/, "</p>\n\n<p>" )+'</p>';
29
-
29
+
30
30
  end
31
-
31
+
32
32
  # c. copy it back
33
33
  self["#{field}#{suff}".to_sym] = content
34
34
  end
35
- end
36
-
35
+ end
36
+
37
37
  end
38
-
38
+
39
39
  end
40
-
40
+
41
41
  end
42
- end
42
+ end
@@ -1,3 +1,3 @@
1
1
  module Renderable
2
- VERSION = "1.0.9"
2
+ VERSION = "1.0.10"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: renderable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.9
4
+ version: 1.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Pearse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-06 00:00:00.000000000 Z
11
+ date: 2017-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: RedCloth