Class: Cadmus::Renderers::Base
- Inherits:
-
Object
- Object
- Cadmus::Renderers::Base
- Defined in:
- lib/cadmus/renderers.rb
Overview
The simplest Cadmus renderer. It will render Liquid templates to HTML and plain text (removing the HTML tags from the plain text output).
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_HTML_SANITIZER =
Rails::Html::FullSanitizer
Instance Attribute Summary collapse
-
#default_assigns ⇒ Object
Returns the value of attribute default_assigns.
-
#default_filters ⇒ Object
Returns the value of attribute default_filters.
-
#default_registers ⇒ Object
Returns the value of attribute default_registers.
-
#html_sanitizer ⇒ Object
Returns the value of attribute html_sanitizer.
Instance Method Summary collapse
-
#initialize ⇒ Base
constructor
A new instance of Base.
-
#preprocess(template, format, options = {}) ⇒ String
The preprocess method performs the initial rendering of the Liquid template using the a combination of the default_filters, default_assigns, default_registers, and any :assigns, :filters, and :registers options passed in as options.
-
#render(template, format, options = {}) ⇒ Object
Render a given Liquid template to the specified format.
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
22 23 24 25 26 27 28 |
# File 'lib/cadmus/renderers.rb', line 22 def initialize self.default_registers = {} self.default_filters = [] self.default_assigns = {} self.html_sanitizer = Rails.application.config.action_view.full_sanitizer || DEFAULT_HTML_SANITIZER.new end |
Instance Attribute Details
#default_assigns ⇒ Object
Returns the value of attribute default_assigns.
18 19 20 |
# File 'lib/cadmus/renderers.rb', line 18 def default_assigns @default_assigns end |
#default_filters ⇒ Object
Returns the value of attribute default_filters.
18 19 20 |
# File 'lib/cadmus/renderers.rb', line 18 def default_filters @default_filters end |
#default_registers ⇒ Object
Returns the value of attribute default_registers.
18 19 20 |
# File 'lib/cadmus/renderers.rb', line 18 def default_registers @default_registers end |
#html_sanitizer ⇒ Object
Returns the value of attribute html_sanitizer.
18 19 20 |
# File 'lib/cadmus/renderers.rb', line 18 def html_sanitizer @html_sanitizer end |
Instance Method Details
#preprocess(template, format, options = {}) ⇒ String
The preprocess method performs the initial rendering of the Liquid template using the a combination of the default_filters, default_assigns, default_registers, and any :assigns, :filters, and :registers options passed in as options.
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/cadmus/renderers.rb', line 43 def preprocess(template, format, ={}) render_args = [ default_assigns.merge([:assigns] || {}), { :filters => default_filters + ([:filters] || []), :registers => default_registers.merge([:registers] || {}) } ] template.render(*render_args) end |
#render(template, format, options = {}) ⇒ Object
Render a given Liquid template to the specified format. This renderer implementation supports +:html+ and +:text+ formats, but other implementations may support other formats.
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/cadmus/renderers.rb', line 64 def render(template, format, ={}) content = preprocess(template, format, ) case format.to_sym when :html content.html_safe when :text html_sanitizer.sanitize content else raise "Format #{format.inspect} unsupported by #{self.class.name}" end end |