Module: Vedeu::Renderers

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

Overview

Provides a single interface to all registered renderers.

Defined Under Namespace

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

Class Method Summary collapse

Instance Method Summary collapse

Class 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
# File 'lib/vedeu/renderers/all.rb', line 22

def clear
  storage.map do |renderer|
    log('Clearing', renderer)

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

  ''
end

.in_memorySet (private)

Returns:

  • (Set)


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

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

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

  end
end

.log(message, renderer) ⇒ void (private)

This method returns an undefined value.

Parameters:

  • message (String)
  • renderer (Class)


76
77
78
79
# File 'lib/vedeu/renderers/all.rb', line 76

def log(message, renderer)
  Vedeu.log(type:    :render,
            message: "#{message} via #{renderer.class.name}")
end

.mutexMutex (private)

Returns:

  • (Mutex)


82
83
84
# File 'lib/vedeu/renderers/all.rb', line 82

def mutex
  @mutex ||= Mutex.new
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>)


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

def render(output)
  storage.map do |renderer|
    log('Rendering', renderer)

    threaded(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)


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

def renderers
  self
end

.reset!void Also known as: reset Originally defined in module Vedeu::Repositories::Storage

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.

This method returns an undefined value.

Remove all currently stored data for this repository.

.storagevoid Also known as: all Originally defined in module Vedeu::Repositories::Storage

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.

This method returns an undefined value.

Return whole repository; provides raw access to the storage for this repository.

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

This method returns an undefined value.

Parameters:

  • block (Proc)


88
89
90
91
92
93
94
95
96
# File 'lib/vedeu/renderers/all.rb', line 88

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)


100
101
102
103
104
105
106
# File 'lib/vedeu/renderers/all.rb', line 100

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

  yield

  Vedeu.trigger(:_show_cursor_)
end

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
# File 'lib/vedeu/renderers/all.rb', line 22

def clear
  storage.map do |renderer|
    log('Clearing', renderer)

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

  ''
end

#in_memorySet (private)

Returns:

  • (Set)


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

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

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

  end
end

#log(message, renderer) ⇒ void (private)

This method returns an undefined value.

Parameters:

  • message (String)
  • renderer (Class)


76
77
78
79
# File 'lib/vedeu/renderers/all.rb', line 76

def log(message, renderer)
  Vedeu.log(type:    :render,
            message: "#{message} via #{renderer.class.name}")
end

#mutexMutex (private)

Returns:

  • (Mutex)


82
83
84
# File 'lib/vedeu/renderers/all.rb', line 82

def mutex
  @mutex ||= Mutex.new
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>)


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

def render(output)
  storage.map do |renderer|
    log('Rendering', renderer)

    threaded(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)


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

def renderers
  self
end

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

This method returns an undefined value.

Parameters:

  • block (Proc)


88
89
90
91
92
93
94
95
96
# File 'lib/vedeu/renderers/all.rb', line 88

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)


100
101
102
103
104
105
106
# File 'lib/vedeu/renderers/all.rb', line 100

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

  yield

  Vedeu.trigger(:_show_cursor_)
end