Class: LiquidDiagrams::BasicBlock Abstract

Inherits:
Liquid::Block
  • Object
show all
Defined in:
lib/liquid_diagrams/basic_block.rb

Overview

This class is abstract.

Subclass and override #render_content to implement

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.rendererObject

Return the renderer class matching the block



7
8
9
10
11
# File 'lib/liquid_diagrams/basic_block.rb', line 7

def self.renderer
  @renderer ||= Renderers.const_get(
    name.split('::').last.gsub(/Block$/, 'Renderer')
  )
end

Instance Method Details

#handle_error(error) ⇒ Object



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

def handle_error(error)
  error
end

#read_configObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



33
34
35
36
37
38
# File 'lib/liquid_diagrams/basic_block.rb', line 33

def read_config
  options = LiquidDiagrams.configuration(parse_context, key: block_name)
  inline_options = Utils.parse_inline_options(@markup.strip)

  options.merge(inline_options)
end

#render(context) ⇒ Object

Note:

Do not override this method, override #render_content instead



14
15
16
17
18
19
20
# File 'lib/liquid_diagrams/basic_block.rb', line 14

def render(context)
  @context = context
  @content = super.to_s
  @config = read_config

  render_content
end

#render_contentObject



22
23
24
25
26
# File 'lib/liquid_diagrams/basic_block.rb', line 22

def render_content
  self.class.renderer.render(@content, @config)
rescue Errors::BasicError => error
  handle_error(error)
end