Implements methods common to all text-based renderers. This class is not meant to be used directly, only as a parent to other type-specific rendering classes.
@attr object [Object] instance to be rendered @attr options [Hash] additional rendering options
@author Boris Parak <parak@cesnet.cz
Shortcuts to interesting object attributes, always prefixed with `object_`
Ruby 2.3 compatibility, with `$SAFE` changes
Constructs a renderer instance for the given object.
@param object [Object] instance to be rendered @param options [Hash] additional options
# File lib/occi/core/renderers/text/base.rb, line 30 def initialize(object, options) @object = object @options = options end
Returns an acceptable value for the $SAFE env variable that should be enforced when evaluating templates.
@return [Integer] SAFE level
# File lib/occi/core/renderers/text/base.rb, line 64 def render_safe RENDER_SAFE end
Renders the given object to `text`.
@return [String] object rendering as plain text @return [Hash] object rendering as hash
# File lib/occi/core/renderers/text/base.rb, line 39 def render case options[:format] when 'text', 'text_plain' render_plain when 'headers', 'text_occi' render_headers else raise Occi::Core::Errors::RenderingError, "Rendering to #{options[:format]} is not supported" end end
Returns an acceptable value for the $SAFE env variable that should be enforced when evaluating templates.
@return [Integer] SAFE level
# File lib/occi/core/renderers/text/base.rb, line 55 def render_safe RENDER_SAFE end
Renders `object` into text for headers and returns the result as `Hash`.
@return [Hash] textual representation of Object for headers
# File lib/occi/core/renderers/text/base.rb, line 81 def render_headers; end
Renders `object` into plain text and returns the result as `String`.
@return [String] textual representation of Object
# File lib/occi/core/renderers/text/base.rb, line 75 def render_plain; end