Module: LiquidDiagrams

Defined in:
lib/liquid_diagrams.rb,
lib/liquid_diagrams/utils.rb,
lib/liquid_diagrams/blocks.rb,
lib/liquid_diagrams/errors.rb,
lib/liquid_diagrams/version.rb,
lib/liquid_diagrams/renderers.rb,
lib/liquid_diagrams/rendering.rb,
lib/liquid_diagrams/basic_block.rb,
lib/liquid_diagrams/basic_renderer.rb,
lib/liquid_diagrams/renderers/erd_renderer.rb,
lib/liquid_diagrams/renderers/vega_renderer.rb,
lib/liquid_diagrams/renderers/smcat_renderer.rb,
lib/liquid_diagrams/renderers/svgbob_renderer.rb,
lib/liquid_diagrams/renderers/mermaid_renderer.rb,
lib/liquid_diagrams/renderers/nomnoml_renderer.rb,
lib/liquid_diagrams/renderers/syntrax_renderer.rb,
lib/liquid_diagrams/renderers/bitfield_renderer.rb,
lib/liquid_diagrams/renderers/graphviz_renderer.rb,
lib/liquid_diagrams/renderers/plantuml_renderer.rb,
lib/liquid_diagrams/renderers/vegalite_renderer.rb,
lib/liquid_diagrams/renderers/wavedrom_renderer.rb,
lib/liquid_diagrams/renderers/blockdiag_renderer.rb,
lib/liquid_diagrams/renderers/netlistsvg_renderer.rb

Defined Under Namespace

Modules: Blocks, Errors, Renderers, Rendering, Utils Classes: BasicBlock, BasicRenderer

Constant Summary collapse

OPTIONS_KEY =
:liquid_diagrams
VERSION =
'0.4.0'

Class Method Summary collapse

Class Method Details

.configuration(options, key: nil, default: {}) ⇒ Object

Return configuration of diagram



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

def configuration(options, key: nil, default: {})
  config = options[OPTIONS_KEY.to_sym] || options[OPTIONS_KEY.to_s] || {}

  key ? (config.dig(key.to_sym) || config.dig(key.to_s) || default) : config
end

.diagramsArray<Symbol>

Return all diagrams defined in Renderers

Returns:

  • (Array<Symbol>)


31
32
33
# File 'lib/liquid_diagrams.rb', line 31

def diagrams
  @diagrams ||= renderers.keys
end

.register_diagram(diagram) ⇒ Liquid::Block

Register a diagram block

Parameters:

  • diagram (#to_s)

    diagram name to register

Returns:

  • (Liquid::Block)

    the registered liquid block

Raises:



72
73
74
75
76
77
78
79
80
81
# File 'lib/liquid_diagrams.rb', line 72

def register_diagram(diagram)
  diagram = diagram.to_s.downcase.to_sym

  raise Errors::DiagramNotFoundError unless diagrams.include?(diagram)

  block = Blocks.const_get("#{diagram.capitalize}Block")

  registered_diagrams.merge!(diagram => block)
  Liquid::Template.register_tag(diagram, block)
end

.register_diagrams(*diagrams) ⇒ Array<Liquid::Block>

Register diagrams

Parameters:

  • diagrams (Array<String, Symbol>)

    diagrams to register

Returns:

  • (Array<Liquid::Block>)

    the registered liquid blocks



63
64
65
# File 'lib/liquid_diagrams.rb', line 63

def register_diagrams(*diagrams)
  Array(diagrams).flatten.map { |diagram| register_diagram(diagram) }
end

.registered_diagramsHash{Symbol => BasicBlock}

Return all registered diagrams block

Use register_diagrams and register_diagram to register a diagram

Returns:



54
55
56
# File 'lib/liquid_diagrams.rb', line 54

def registered_diagrams
  @registered_diagrams ||= {}
end

.renderersHash{Symbol => BasicRenderer}

Return all avaliable renderers under Renderers

Returns:



38
39
40
41
42
43
44
45
46
47
# File 'lib/liquid_diagrams.rb', line 38

def renderers
  @renderers ||= Hash[
    Renderers.constants.grep(/Renderer$/).sort.map do |renderer|
      [
        renderer.to_s.chomp('Renderer').downcase.to_sym,
        Renderers.const_get(renderer)
      ]
    end
  ]
end