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 +4 -4
- data/Gemfile +0 -1
- data/README.textile +4 -2
- data/lib/renderable.rb +15 -13
- data/lib/renderable/glue.rb +3 -3
- data/lib/renderable/instance_methods.rb +17 -17
- data/lib/renderable/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02c36fa911ea8d9e74a768e81351b1b6e85a7e1f
|
4
|
+
data.tar.gz: a5f68f6ab655158f138fa5270a469e3911274fe7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39d78df4fe688710e8873e69aa3940b72f16e4d838c6f70841e114500fec89e7f9e84d83cc5423dbfa034a9ddef18fef6a23a2693299587d715b7670b8b704e1
|
7
|
+
data.tar.gz: ead7a271fadc2b6e191aa48aadb3049c0f6a932c89d42bc0837dcbabbe30e954cdd1d7bb8efb65540a0ae70c75262ead68c6715e5bda195f5c0b2682d327e7d6
|
data/Gemfile
CHANGED
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
|
data/lib/renderable/glue.rb
CHANGED
@@ -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
|
data/lib/renderable/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2017-06-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: RedCloth
|