Module: Vedeu::Renderers

Extended by:
Enumerable, Renderers, Vedeu::Repositories::Storage
Included in:
Renderers
Defined in:
lib/vedeu/renderers/all.rb,
lib/vedeu/renderers/html.rb,
lib/vedeu/renderers/json.rb,
lib/vedeu/renderers/text.rb,
lib/vedeu/renderers/escape.rb,
lib/vedeu/renderers/terminal.rb,
lib/vedeu/renderers/support/file.rb,
lib/vedeu/renderers/support/options.rb

Overview

Provides a single interface to all registered renderers.

Defined Under Namespace

Modules: Options Classes: Escape, File, HTML, JSON, Terminal, Text

Instance Method Summary collapse

Methods included from Vedeu::Repositories::Storage

reset!, storage

Instance Method Details

#clearArray<void>

Instructs each renderer registered with Vedeu to clear their content.

Examples:

Vedeu.clear
Vedeu.trigger(:_clear_)
Vedeu.renderers.clear

Returns:

  • (Array<void>)


22
23
24
25
26
27
28
29
30
31
# File 'lib/vedeu/renderers/all.rb', line 22

def clear
  storage.map do |renderer|
    Vedeu.log(type:    :render,
              message: "Clearing via #{renderer.class.name}")

    perform(renderer) { renderer.clear }
  end.each(&:join) if Vedeu.ready?

  ''
end

#in_memorySet (private)

Returns:

  • (Set)


65
66
67
68
69
70
71
72
73
# File 'lib/vedeu/renderers/all.rb', line 65

def in_memory
  if Vedeu.config.renderers.any?
    Set.new(Vedeu.config.renderers)

  else
    Set.new([Vedeu::Renderers::Terminal.new])

  end
end

#mutexMutex (private)

Returns:

  • (Mutex)


88
89
90
# File 'lib/vedeu/renderers/all.rb', line 88

def mutex
  @_mutex ||= Mutex.new
end

#perform(renderer, &block) ⇒ Object (private)

Parameters:

  • renderer (void)
  • block (Proc)


77
78
79
80
81
82
83
84
85
# File 'lib/vedeu/renderers/all.rb', line 77

def perform(renderer, &block)
  if Vedeu.config.threaded?
    threaded(renderer) { yield }

  else
    unthreaded { yield }

  end
end

#render(output) ⇒ Array<void>

Instructs each renderer registered with Vedeu to render the output as content.

Examples:

Vedeu.renderers.render(output)

Parameters:

  • output (void)

Returns:

  • (Array<void>)


51
52
53
54
55
56
57
58
59
60
# File 'lib/vedeu/renderers/all.rb', line 51

def render(output)
  storage.map do |renderer|
    Vedeu.log(type:    :render,
              message: "Rendering via #{renderer.class.name}")

    perform(renderer) { renderer.render(output) }
  end.each(&:join) if Vedeu.ready?

  output
end

#renderersModule

Provides access to the list of renderers.

Examples:

Vedeu.renderers

Returns:

  • (Module)


39
40
41
# File 'lib/vedeu/renderers/all.rb', line 39

def renderers
  self
end

#threaded(renderer, &block) ⇒ void (private)

This method returns an undefined value.

Parameters:

  • block (Proc)


94
95
96
97
98
99
100
101
102
# File 'lib/vedeu/renderers/all.rb', line 94

def threaded(renderer, &block)
  Thread.new(renderer) do
    mutex.synchronize do
      toggle_cursor do
        yield
      end
    end
  end
end

#toggle_cursor(&block) ⇒ void (private)

This method returns an undefined value.

Parameters:

  • block (Proc)


106
107
108
109
110
111
112
# File 'lib/vedeu/renderers/all.rb', line 106

def toggle_cursor(&block)
  Vedeu.trigger(:_hide_cursor_)

  yield

  Vedeu.trigger(:_show_cursor_)
end

#unthreaded(&block) ⇒ void (private)

This method returns an undefined value.

Parameters:

  • block (Proc)


116
117
118
119
120
# File 'lib/vedeu/renderers/all.rb', line 116

def unthreaded(&block)
  toggle_cursor do
    yield
  end
end