Class: LiquidDiagrams::BasicRenderer Abstract

Inherits:
Object
  • Object
show all
Includes:
Rendering
Defined in:
lib/liquid_diagrams/basic_renderer.rb

Overview

This class is abstract.

Subclass and override #render to implement.

Constant Summary collapse

FLAGS =

Configuration key for argument with boolean value.

[].freeze
FLAGS_PREFIX =

Prefix for FLAGS

'--'
OPTIONS =

Configuration key for argument with key-value pairs.

[].freeze
OPTIONS_SEPARATOR =

Separator for key and value of OPTIONS.

' '
OPTIONS_PREFIX =

Prefix for OPTIONS

'--'

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Rendering

render_with_command, render_with_stdin_stdout, render_with_tempfile

Constructor Details

#initialize(content, options = {}) ⇒ BasicRenderer

Returns a new instance of BasicRenderer.



27
28
29
30
# File 'lib/liquid_diagrams/basic_renderer.rb', line 27

def initialize(content, options = {})
  @content = content
  @config = options
end

Class Method Details

.render(content, options = {}) ⇒ Object



23
24
25
# File 'lib/liquid_diagrams/basic_renderer.rb', line 23

def self.render(content, options = {})
  new(content, options).render
end

Instance Method Details

#argumentsObject



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/liquid_diagrams/basic_renderer.rb', line 47

def arguments
  flags = Utils.build_flags(
    @config, self.class.const_get(:FLAGS),
    prefix: self.class.const_get(:FLAGS_PREFIX)
  )
  options = Utils.build_options(
    @config, self.class.const_get(:OPTIONS),
    prefix: self.class.const_get(:OPTIONS_PREFIX),
    sep: self.class.const_get(:OPTIONS_SEPARATOR)
  )

  "#{flags} #{options}".strip
end

#build_commandObject



39
40
41
# File 'lib/liquid_diagrams/basic_renderer.rb', line 39

def build_command
  "#{executable} #{arguments}".strip
end

#executableObject



43
44
45
# File 'lib/liquid_diagrams/basic_renderer.rb', line 43

def executable
  self.class.name.split('::').last.sub(/Renderer$/, '').downcase
end

#renderObject

Default render method with Errors::NotImplementedError raised



35
36
37
# File 'lib/liquid_diagrams/basic_renderer.rb', line 35

def render
  raise Errors::NotImplementedError
end