cadmus 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/cadmus/renderers.rb +20 -20
- data/lib/cadmus/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: baa8f826659300b741b1fac079ee71bb74315514
|
4
|
+
data.tar.gz: 1422e3236c83edcc178b76867f568e4cd4122149
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8e8447ace4df8e75b8910fb9d2d6f5e50b39200fd91a264f497122326aa38c66c3c07a827085f5b0431399a45564e35a5723c1822db1f35b718141f44d34a95
|
7
|
+
data.tar.gz: 47f2c14c40f57c03a5b4b22284245c6f3b69c37a067fc2c78cbaaecc35aa1f47fc9ac7b2f81f8dc5ad8de383bcc98af1df33bfc1e7101deca9dc62f469385ac1
|
data/CHANGELOG.md
CHANGED
data/lib/cadmus/renderers.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Cadmus
|
2
|
-
|
2
|
+
|
3
3
|
# A Cadmus renderer is an object that handles the rendering of +Liquid::Template+s to output formats
|
4
4
|
# such as HTML or plain text. A renderer provides several features over and above what plain
|
5
5
|
# Liquid does:
|
@@ -9,22 +9,22 @@ module Cadmus
|
|
9
9
|
# * Ability to specify default assigns, filters, and registers and augment them on a per-call basis
|
10
10
|
# * Ability to render to multiple output formats from a single renderer
|
11
11
|
module Renderers
|
12
|
-
|
12
|
+
|
13
13
|
# The simplest Cadmus renderer. It will render Liquid templates to HTML and plain text (removing the
|
14
14
|
# HTML tags from the plain text output).
|
15
15
|
class Base
|
16
16
|
attr_accessor :default_assigns, :default_filters, :default_registers, :html_sanitizer
|
17
|
-
|
17
|
+
|
18
18
|
DEFAULT_HTML_SANITIZER = defined?(Rails::Html::FullSanitizer) ? Rails::Html::FullSanitizer : HTML::FullSanitizer
|
19
|
-
|
19
|
+
|
20
20
|
def initialize
|
21
21
|
self.default_registers = {}
|
22
22
|
self.default_filters = []
|
23
23
|
self.default_assigns = {}
|
24
|
-
|
24
|
+
|
25
25
|
self.html_sanitizer = Rails.application.config.action_view.full_sanitizer || DEFAULT_HTML_SANITIZER.new
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
# The preprocess method performs the initial rendering of the Liquid template using the a combination
|
29
29
|
# of the default_filters, default_assigns, default_registers, and any :assigns, :filters, and :registers
|
30
30
|
# options passed in as options.
|
@@ -38,18 +38,18 @@ module Cadmus
|
|
38
38
|
# @option options [Hash] :registers additional register variables that will be made available to the template.
|
39
39
|
# @option options [Hash] :filters additional filters to be made available to the template.
|
40
40
|
# @return [String] the raw results of rendering the Liquid template.
|
41
|
-
def preprocess(template, format, options={})
|
41
|
+
def preprocess(template, format, options={})
|
42
42
|
render_args = [
|
43
|
-
default_assigns.merge(options[:assigns] || {}),
|
44
|
-
{
|
43
|
+
default_assigns.merge(options[:assigns] || {}),
|
44
|
+
{
|
45
45
|
:filters => default_filters + (options[:filters] || []),
|
46
46
|
:registers => default_registers.merge(options[:registers] || {})
|
47
47
|
}
|
48
|
-
]
|
49
|
-
|
48
|
+
]
|
49
|
+
|
50
50
|
template.render(*render_args)
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
# Render a given Liquid template to the specified format. This renderer implementation supports +:html+ and
|
54
54
|
# +:text+ formats, but other implementations may support other formats.
|
55
55
|
#
|
@@ -61,7 +61,7 @@ module Cadmus
|
|
61
61
|
# available options.
|
62
62
|
def render(template, format, options={})
|
63
63
|
content = preprocess(template, format, options)
|
64
|
-
|
64
|
+
|
65
65
|
case format.to_sym
|
66
66
|
when :html
|
67
67
|
content.html_safe
|
@@ -73,7 +73,7 @@ module Cadmus
|
|
73
73
|
end
|
74
74
|
end
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
# A helper module that can be included in classes that wish to provide a Cadmus renderer. For
|
78
78
|
# example, an Email class might want to provide a renderer so that it can be easily transformed
|
79
79
|
# into HTML or text formats.
|
@@ -98,27 +98,27 @@ module Cadmus
|
|
98
98
|
# end
|
99
99
|
# end
|
100
100
|
module Renderable
|
101
|
-
|
101
|
+
|
102
102
|
# @return a new Cadmus renderer set up using the +default_assigns+, +default_registers+
|
103
103
|
# and +default_filters+ methods, if they exist.
|
104
104
|
def cadmus_renderer
|
105
105
|
cadmus_renderer_class.new.tap { |renderer| setup_renderer(renderer) }
|
106
106
|
end
|
107
|
-
|
107
|
+
|
108
108
|
# @return the Cadmus renderer class to instanciate in the +cadmus_renderer+ method. By
|
109
109
|
# default, Cadmus::Renderers::Base.
|
110
110
|
def cadmus_renderer_class
|
111
111
|
Cadmus::Renderers::Base
|
112
112
|
end
|
113
|
-
|
113
|
+
|
114
114
|
protected
|
115
115
|
# Sets the values of +default_assigns+, +default_registers+ and +default_filters+ on a given
|
116
116
|
# renderer using the +liquid_assigns+, +liquid_registers+ and +liquid_filters+ methods, if
|
117
117
|
# they're defined.
|
118
118
|
def setup_renderer(renderer)
|
119
|
-
renderer.default_assigns = liquid_assigns if respond_to?(:liquid_assigns)
|
120
|
-
renderer.default_registers = liquid_registers if respond_to?(:liquid_registers)
|
121
|
-
renderer.default_filters = liquid_filters if respond_to?(:liquid_filters)
|
119
|
+
renderer.default_assigns = liquid_assigns if respond_to?(:liquid_assigns, true)
|
120
|
+
renderer.default_registers = liquid_registers if respond_to?(:liquid_registers, true)
|
121
|
+
renderer.default_filters = liquid_filters if respond_to?(:liquid_filters, true)
|
122
122
|
end
|
123
123
|
end
|
124
124
|
end
|
data/lib/cadmus/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cadmus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nat Budin
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2017-02-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|